in reply to Regex arrow key problem
What you are probably missing is that the "extended keys" generate multiple values for each keypress.
Below shows the output when four arrow keys are pressed in the order: left, right, up, down:
use Term::ReadKey;; { ReadMode(4); print ord($c), " : '$c'" while ($c=ReadKey(0)) ne "\cM"; ReadMode(0) };; 27 : '←' 91 : '[' 68 : 'D' 27 : '←' 91 : '[' 67 : 'C' 27 : '←' 91 : '[' 65 : 'A' 27 : '←' 91 : '[' 66 : 'B'
So, in order to match the left arrow key, you would need to use "\e[D" in your regex. But, ReadKey() returns those 3 characters one at a time, so you would need to accumulate them before you could match that.
But then the problem becomes how do you decide when you see the escape character (←, '←', "\e"; 27), whether the user has pressed the escape key, or some other keys that also generates more characters.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex arrow key problem
by austin43 (Acolyte) on Dec 01, 2010 at 19:32 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2010 at 19:36 UTC | |
by austin43 (Acolyte) on Dec 01, 2010 at 19:41 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2010 at 20:21 UTC | |
by ikegami (Patriarch) on Dec 01, 2010 at 19:45 UTC | |
by Anonymous Monk on Dec 01, 2010 at 19:47 UTC | |
by ikegami (Patriarch) on Dec 01, 2010 at 19:53 UTC | |
by austin43 (Acolyte) on Dec 01, 2010 at 19:57 UTC | |
|