define_key(3X)
π define_key β the "make your own function key" era π
okay bestie, so we're in define_key(3X), part of the Library calls section of the ncurses manual, and this one is genuinely so fun. it's the little extension that lets you bind your own string to a function key code. like, you're the main character and you get to decide what that key means. periodt. π
β¨ NAME β¨
define_key β define a curses function key code
π¦ SYNOPSIS π¦
#include <curses.h>
int define_key(const char * definition, int key-code);
π DESCRIPTION π
so define_key is an ncurses extension (iykyk, it's not in every curses out there) and what it does is it lets a curses application bind a string definition to the function key key-code. that key-code is the thing that wgetch(3X) hands back to you β and if you're one of the wide-character API girlies, that's wget_wch(3X) β but only when keypad(3X) is enabled in a window and a function key actually gets pressed. πΈ
and here's the cute part: ncurses treats that binding exactly the same way it treats the bindings in the terminfo database entry for the terminal type. no special-casing, no weird second-class treatment. it just slots right in. obsessed. π
now, the removal tricks, because yes, this function also un-binds things:
- if
definitionisNULL, it removes any existing binding fromkey-code. bye bye binding. π - and similarly, if
key-codeis non-positive, it removes an existing binding fordefinition, if there even is one.
π₯ RETURN VALUE π₯
define_key returns ERR when:
definitionisNULLandkey-codeis nonpositive, or- there's not enough memory available to bind
definitiontokey-code.
and otherwise? define_key returns OK. slay. β¨
π EXTENSIONS π
define_key is an ncurses extension. it's giving exclusive, bestie. π
π§ 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, don't just rawdog it and assume everyone has it, okay?
also, good news for the BSD girlies: NetBSD curses since 2.0 (2004) supports define_key. we love a crossover moment. π«Ά
π AUTHORS π
Thomas Dickey
π SEE ALSO π
curses(3X)keybound(3X)keyok(3X)key_defined(3X)terminfo(5)
and that's the whole vibe check, bestie. this page came from ncurses 6.6, dated 2024-12-28 β go forth and bind some keys, you absolute icon. π πβ¨
π¦ 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-2023,2024 Thomas E. Dickey
- Copyright 1998-2010,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms