aztlan667 has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, I am trying to create a script that will read in a series of characters and look for a certain sequence of characters. I am having a hard time reading in control characters like <CTRL> and <ALT>. I'm basically am trying to create a keylogger that will look for a sequence like "<CTRL>+<ALT>+B" and execute another script when that happens. I've tried using the following code:
my $key_buf; my $sequence = qr/some_keys/g; system "stty cbreak < /dev/tty > /dev/tty 2>&1"; while (($key=getc) ) { $key_buf .= $key; if ($key_buf =~ $my_sequence) { system "xmessage 'OH YA!'"; last; } last if $key eq "q"; } system "stty -cbreak < /dev/tty > /dev/tty 2>&1";
I've also tried using Term::ReadKey and Term::InKey, but I've had no success in capturing the control characters. Any suggestions or anything I'm missing?
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing control characters
by almut (Canon) on Feb 10, 2009 at 02:59 UTC | |
|
Re: Capturing control characters
by Joost (Canon) on Feb 10, 2009 at 00:00 UTC | |
by aztlan667 (Novice) on Feb 10, 2009 at 00:52 UTC |