key_defined(3X)
π 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
definitionis 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
definitionis a prefix of some other bound definition, you get back-1. π (no exact match, just a teaser)
lowkey important:0and-1mean 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
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 2003-2006,2010 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms