Allegro::Keyboard - Allegro keyboard object
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";
}
The Allegro::Keyboard module provides an interface to the Allegro keyboard routines.
$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.
$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.
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.
$kb->simulate('space', ...);
Valid keys are listed below.
$kb->clear;
This will not affect the results of $kb->pressed($key); it will
only affect calls to $kb->read or $kb->pressed().
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.
Colin O'Leary <colin@mx3.org>
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.