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.
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.
key
ascii
both
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.
4
$
f1
@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.
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.
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.
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().
$kb->pressed($key)
$kb->read
$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 <colino@cpan.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.
To install Allegro, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Allegro
CPAN shell
perl -MCPAN -e shell install Allegro
For more information on module installation, please visit the detailed CPAN module installation guide.