The :mod:curses module does not expose the ncurses key-management extensions define_key(), key_defined() and keyok().
These let an application manage how curses recognizes control strings as keycodes, beyond the predefined terminfo keys and the all-or-nothing :meth:curses.window.keypad.
define_key(definition, keycode) binds the control string definition to keycode. If definition is None the binding for keycode is removed; if keycode is zero or negative the binding for definition is removed.
key_defined(definition) returns the keycode bound to definition, 0 if none is, or -1 if definition is ambiguous.
keyok(keycode, enable) enables or disables recognition of a single keycode, a finer-grained alternative to :meth:curses.window.keypad.
Proposed API:
curses.define_key(definition, keycode)
curses.key_defined(definition) -> int
curses.keyok(keycode, enable)
These are ncurses extensions, available when built against an ncurses with NCURSES_EXT_FUNCS.
Activity
gh-152334: Add curses key-management functions (GH-152338)