Skip to content

Add curses key-management functions define_key(), key_defined() and keyok() #152334

Closed

Description

@serhiy-storchaka

Feature or enhancement

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.

Linked PRs

Activity

  1. added a commit that references this issue on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions