NAME

Allegro::Keyboard - Allegro keyboard object


SYNOPSIS

   use Allegro;
   $al = Allegro->new() or die;
   $d  = $al->Display() or die;
   $kb = $al->Keyboard() or die;
   $key = "";
   while($key ne 'escape')
   {
      $key = $kb->read;
      print "$key\n";
   }


DESCRIPTION

The Allegro::Keyboard module provides an interface to the Allegro keyboard routines.


METHODS

new - create a new keyboard object
Initializes the Allegro keyboard subsystem. Only one keyboard object may exist at once with Allegro v4.
   $kb = $al->Keyboard(mode => $mode);

mode may be key, ascii, or both. This will be the default return mode for read. The default is key.

read - read from key buffer
Reads the current key from the key buffer.
   $key   = $kb->read(mode => 'key');
   $ascii = $kb->read(mode => 'ascii');

mode may be either key or ascii to return either the key name of the pressed key or an ASCII equivalent. Not all keys will have a useful ASCII value.

For example, holding shift and hitting the 4 key will set $key to 4 and $ascii to $. Hitting F1 will return $key as f1 and no ASCII value.

   @key = $kb->read(mode => 'both');

If mode is set to both, an array containing the key name and ASCII value will be returned.

mode defaults to whatever was passed into new.

This method will block if there are no keys available in the key buffer.

pressed - check if a key is pressed
Checks if either a specific key is pressed or any key is presssed.
   exit if($kb->pressed('escape'));

If pressed is given a parameter, it should be one of the key names listed below.

   while(!$kb->pressed()) { ... }

If no parameter is supplied, pressed will return a true value if there are any keys in the key buffer.

simulate - simulate a key press
Simulates a key being pressed by inserting the key into the key buffer. Can take any number of key names.
   $kb->simulate('space', ...);

Valid keys are listed below.

clear - clear keyboard buffer
Clears any remaining keys in the keyboard buffer.
   $kb->clear;

This will not affect the results of $kb->pressed($key); it will only affect calls to $kb->read or $kb->pressed().


KEY NAMES

The following key names will be returned by read in key mode, and are valid key values to be passed to pressed or simulate.

Key names listed in parentheses are aliases, and may be used with pressed or simulate. They however, will never be returned by read, so the first listed name must be used when checking on returned key names from read in key mode.

a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
  • 0_pad
  • 1_pad
  • 2_pad
  • 3_pad
  • 4_pad
  • 5_pad
  • 6_pad
  • 7_pad
  • 8_pad
  • 9_pad
  • f1
    f2
    f3
    f4
    f5
    f6
    f7
    f8
    f9
    f10
    f11
    f12
    escape (esc)
    tilde (~)
    minus (-)
    equals (=)
    backspace
    tab
    openbrace ([)
    closebrace (])
    enter (\r) (\n)
    colon (:)
    quote (``)
    backslash (\)
    backslash2
    comma (,)
    period (.)
    slash (/)
    space ( )
    insert (ins)
    delete (del)
    home
    end
    pageup
    pagedown
    left
    right
    up
    down
    slash_pad
    asterisk_pad (asterisk) (*)
    minus_pad
    plus_pad
    delete_pad
    enter_pad
    printscreen
    pause
    abnt_c1
    yen
    kana
    convert
    noconvert
    at
    circumflex
    colon2
    kanji
    leftshift (lshift)
    rightshift (rshift)
    leftcontrol (lcontrol) (lctrl)
    rightcontrol (rcontrol) (rctrl)
    alt
    altgr
    leftwin (lwin)
    rightwin (rwin)
    menu
    scrolllock (scroll)
    numlock (num)
    capslock (caps)


    AUTHOR

    Colin O'Leary <colin@mx3.org>


    COPYRIGHT

    Copyright 2003 by Colin O'Leary. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

    The Allegro library is copyright its authors, and is giftware. See http://alleg.sf.net for more information.


    SEE ALSO

    Allegro - Base Allegro routines