key_defined(3NCURSES)

πŸ’– key_defined β€” the ncurses girlies' guide πŸ’–

okay bestie, so this is a page from Library calls in the ncurses manual, and it's literally about figuring out which function key a string is bound to. it's giving detective energy fr fr πŸ”βœ¨


✨ NAME ✨

key_defined β€” obtain the key code for an ncurses function key definition πŸŽ€


🌸 SYNOPSIS 🌸

#include <curses.h>

int key_defined(const char * definition);

that's it, that's the whole vibe. one include, one function, no cap. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so key_defined is an ncurses extension β€” like, not a standard-curses thing, it's our special little bonus β€” and what it does is let a curses application determine the function key code, if any, to which the string definition is bound.

basically: you hand it a string, it tells you which key (if any) that string is vibing with. iconic behaviour honestly πŸ‘‘


⭐ RETURN VALUE ⭐

here's the tea on what you get back:

  • if definition is bound to something, key_defined returns the first key code to which definition is bound. first come, first served, periodt. πŸ’–
  • if nothing is bound to it? it returns 0. like, nobody's home. πŸ™ˆ
  • but WAIT β€” if definition is a prefix of another bound definition, key_defined returns -1. not me getting a weird negative number because my string was only part of a bigger bound definition 😭 careful with that one bestie.
🫢 fr fr, remember: 0 means "not bound at all" and -1 means "you gave me a prefix of something that IS bound." two very different moods.

🌈 EXTENSIONS 🌈

key_defined is an ncurses extension. it's not out here in regular curses, it's an ncurses-only situation, iykyk. ✨


🧚 PORTABILITY 🧚

if you're using ncurses extensions in your app, you should condition their use on the visibility of the NCURSES_VERSION preprocessor macro. like, vibe check your environment first before you commit to using the fancy stuff, because other curses implementations might not have it and that would be so embarrassing for everyone involved πŸ’€


πŸ‘‘ AUTHORS πŸ‘‘

Thomas Dickey β€” the author, the legend, the main character. 🫑


πŸ“ SEE ALSO πŸ“

  • ncurses(3NCURSES)
  • define_key(3NCURSES)
  • keybound(3NCURSES)
  • keyok(3NCURSES)

go read those too, they're all part of the same little key-binding friend group πŸ’œ


and that's the whole page bestie!! this was ncurses 6.6, dated 2025-10-04, and honestly? slay. go bind some keys, you've got this πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from