in reply to Regex arrow key problem

Please wrap code in <code> tags - as the author of a node, you can edit it. Please read Writeup Formatting Tips.

I would suggest you check to make sure that the codes you are getting correspond to what you expect, perhaps with some code similar to

use strict; use warnings; use Term::ReadKey; ReadMode(4); my %keys = GetControlChars; my $int = $keys{INTERRUPT}; while ((my $input = ReadKey(0)) ne $int) { print ord($input), "\n"; } print ord($input), "\n"; ReadMode(0);

I would also suggest you likely want to use equality (as I've done above, see perlop) instead of regular expressions (perlre). As well, see Term::ReadKey, which does not contain a Readmode method (Perl is case sensitive).

Replies are listed 'Best First'.
Re^2: Regex arrow key problem
by austin43 (Acolyte) on Dec 01, 2010 at 20:17 UTC
    This spits out 27 91 68 for left, and 27 91 67 for right. Now what?
        My end goal in this situation is just to be able to use arrow keys for browsing through different areas of a script. Whenever an arrow key is pressed I want it to run a new subroutine as specified. Currently I have it matching "q" for previous subroutine and "w" for next subroutine. I figured this is not as intuitive as <- ->. I am very new to perl, and it is essentially my first programming language. I will try to figure out a way to implement multiple input capturing. The entire script, with its 5 or so modules, is about 8000-9000 lines, so it will be interesting to figure out how to do that. Gosh I wish there was an easier way to do this.