key_defined(3X)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’– key_defined β€” the "wait, what key is that string even?" decoder ring πŸ’–

okay bestie, so this is a page from the ncurses manual, section 3X β€” the library calls section. It's called key_defined(3X) and honestly? It's giving detective energy. Let's get into it. πŸ•΅οΈβ™€οΈβœ¨


✨ NAME ✨

key_defined β€” obtain key code for an ncurses function key definition

Like. You hand it a string, and it tells you which function key that string is bound to. That's the whole job. Iconic, tbh. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <curses.h>

int key_defined(const char * definition);

yes you gotta include <curses.h> first, that's non-negotiable bestie. πŸ™ˆ


πŸ¦‹ DESCRIPTION πŸ¦‹

So key_defined is an ncurses extension β€” meaning it's a little extra that ncurses added on top, not vanilla curses, iykyk. What it does: it lets a curses application figure out the function key code β€” if any β€” that the string definition is bound to.

That's it. That's the vibe check. You give it a string, it tells you the key code. 🎯


🌸 RETURN VALUE 🌸

Here's the tea, and there are three possible outcomes:

  • If definition is bound to something, you get back the first key code it's bound to. πŸ₯‡
  • If it's bound to nothing at all, you get back 0. πŸ«₯
  • If definition is a prefix of some other bound definition, you get back -1. 😭 (no exact match, just a teaser)
lowkey important: 0 and -1 mean very different things here. Don't treat them like the same "nope". πŸ’€

⭐ EXTENSIONS ⭐

key_defined is an ncurses extension. (yes, we said it in DESCRIPTION too β€” it's that serious, it gets its own section. periodt. πŸ‘‘)


🌈 PORTABILITY 🌈

if you're writing code that uses ncurses extensions, bestie, you should condition their use on the visibility of the NCURSES_VERSION preprocessor macro. Basically: check that macro exists before you go using the fancy extension, so your code doesn't get humbled on a system that isn't ncurses. 🧚


πŸ’œ AUTHORS πŸ’œ

Thomas Dickey

(shoutout to the legend himself 🫢)


πŸ’… SEE ALSO πŸ’…

  • curses(3X)
  • define_key(3X)
  • keybound(3X)
  • keyok(3X)

go read those next, they're all part of the same little key-binding friend group πŸ“


k that's the whole page!! this was ncurses 6.6, dated 2025-10-04, and it's the key_defined(3X) page β€” mwah, go forth and decode your keys βœ¨πŸŽ€πŸ’–

πŸ“¦ where this page comes from