[Tutor] Arrow keys in subwindows
Cameron Simpson
cs at cskk.id.au
Fri Jan 13 16:51:40 EST 2023
On 12Jan2023 21:37, paulf at quillandmouse.com <paulf at quillandmouse.com> wrote:
>Actually, I think I found it. In one case, I was using getkey(), and in
>another, getch(). In some cases, like fetching single letters, getkey()
>worked fine. But for arrow keys and others, not. OTOH, getch() worked
>fine in all cases, as long as you put the result through ord(), or
>checked for KEY_LEFT, etc.. I had no idea I had used different methods
>in different places.
getch() and getkey() are supposed to do the same thing, except that
getch() returns an int designating the key, and getkey() returns a
string, which is a single character string for basic characters and a
multicharacter string containing the key name for things like function
keys and arrow keys.
So you get some number>255 for the left arrow from getch() and the
_string_ "KEY_LEFT" from getkey(). On my system here, curses.KEY_LEFT is
260.
However, note that if you're comparing things, comparing an int to a
string is permitted, it will just always be false. So I suspect you were
comparing a string from getkey() with an int (because curses.KEY_LEFT is
an int). And not matching.
Using ord() is a mistake for multicharacter strings, but at least it
will raise an exception so that mistake should show up for an arrow key.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Tutor
mailing list