in reply to Is it possible in perl to detect keyboard events like as "when keydown"
The nice thing about the Glib eventloop, is you can add timers, and filehandle watches to it, to accomplish most anything. If you seek more examples, google for "Glib keypress".
#!/usr/bin/perl use warnings; use strict; use Glib; use Glib qw/TRUE FALSE/; # thanks to muppet for this use Term::ReadKey; $|++; ReadMode('cbreak'); my $main_loop = Glib::MainLoop->new; Glib::Idle->add( sub{ my $char; if (defined ($char = ReadKey(0)) ) { print "$char->", ord($char),"\n"; #process key presses here } return TRUE; #keep this going }); $main_loop->run; ReadMode('normal'); # restore normal tty settings __END__
|
|---|