The general problem here is that modifier keys like <CTRL> and <ALT> are being interpreted by the tty itself. You could try something like this, however:
#!/usr/bin/perl use Term::ReadKey; my $my_sequence = qr/\x1b\x02\z/; # <CTRL>+<ALT>+B my $key; my $key_buf; ReadMode 4; while ($key ne 'q') { $key = ReadKey(); printf "key=\\x%02x\n", ord($key); # debug $key_buf .= $key; if ($key_buf =~ $my_sequence) { system "xmessage 'OH YA!'"; last; } }; ReadMode 0;
This has its limits, too (for example I wouldn't know how to tell apart <CTRL>+<ALT>+B from <CTRL>+<ALT>+<SHIFT>+B), but maybe it's sufficient for your purpose.
<CTRL>+A .. <CTRL>+Z typically maps to 1..26 (ord($key), that is); and <ALT>+... typically generates a two-byte sequence with a leading ESC (27 or \x1b). Other keys (cursor keys, etc.) generate three-byte sequences...
Printing out the sequence you get when you hit a certain key/modifier combination will tell you which substring to match (you don't necessarily need a regex for this, btw; index() would do). But in case portability is an issue, be aware that terminals sometimes differ with respect to the sequences they generate — in particular the multi-byte ones...
Update: the loop exit condition ($key eq 'q') is probably too simple for production use (it would also exit on hitting <ALT>+q, for example, due to the second byte of the escape sequence being 'q')... Fixing this is left as an exercise for the reader :)
In reply to Re: Capturing control characters
by almut
in thread Capturing control characters
by aztlan667
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |