[Tutor] Arrow keys in subwindows

Alan Gauld alan.gauld at yahoo.co.uk
Thu Jan 12 08:34:18 EST 2023


On 12/01/2023 07:02, paulf at quillandmouse.com wrote:
> I can't seem to get the arrow keys (KEY_LEFT, KEY_RIGHT) to work in
> subwindows. I'm running Debian Linux with version 3.10.9 of Python.
> When I run my code using stdscr, arrow keys work just fine. I do a
> a key = stdscr.getch(), it registers the keys. But when I use a
> subwindow (key = mysubwin.getch()), they don't register. No exception
> dumped, but the arrow keys just don't register.

Just to clarify, this means you are using the curses library.

Its always useful if you can post some real code that shows
the problem in action, otherwise we are debugging blind.

> Has anyone else seen this behavior, and can you explain it?

I'm guessing that you initialise the main screen using the
standard initscr() settings? And you used keypad() to
enable the function keys.

But when you create subwindows they have to be initialised
separately and explicitly. So you need to call keypad() for
each window where you want to read a function key (or mouse
button)

That's my best guess based on the minimal information available.

<Shameless plug>
I have a book on programming curses with Python available
on Amazon for a minimal price, both kindle and paper vesions.

https://www.amazon.co.uk/gp/product/B091B85B77/ref=dbs_a_def_rwt_hsch_vapi_tkin_p1_i2

</Shameless plug>


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





More information about the Tutor mailing list