define_key(3NCURSES)
π define_key β bestie edition π
okay so this is from the ncurses library calls manual, and honestly? she's a little icon. let's get into it π«Ά
β¨ NAME β¨
define_key β define a curses function key code πΈ
π SYNOPSIS π
#include <curses.h>
int define_key(const char * definition, int key-code);
like. look at her. so simple. so powerful. π
π¦ DESCRIPTION π¦
okay so first things first: define_key is an ncurses extension, not like a standard-library-core thing, so keep that in mind bestie. β¨
What she does is let a curses app bind a string definition to a function key β specifically to the key-code that comes back from wgetch(3NCURSES). and if you're on the wide-character API? that's wget_wch(3NCURSES) for you, mwah. π
BUT. and this is the important part, no cap β this only kicks in when keypad(3NCURSES) is enabled in a window and somebody actually presses a function key. both. not one or the other. both. π
and here's the cute part: ncurses treats your binding exactly the way it treats the bindings in the terminfo database entry for the terminal type. like, same energy. same treatment. iconic behaviour fr fr. π
π the removal lore (do not skip this)
- if
definitionisNULL, that removes any existing binding fromkey-code. gone. deleted. not me doing cleanup π - similarly, a non-positive
key-coderemoves an existing binding fordefinition, if there is one. bye bestie π«Ά
β RETURN VALUE β
define_key returns ERR if:
definitionisNULLandkey-codeis nonpositive, or- there's insufficient memory available to bind
definitiontokey-code. π
Otherwise? define_key returns OK. slay. β¨
π EXTENSIONS π
define_key is an ncurses extension. that's the whole section. periodt. π
πΈ PORTABILITY πΈ
okay so if your app is out here using ncurses extensions, the move is to condition their use on the visibility of the NCURSES_VERSION preprocessor macro. like, check before you commit. vibe check your preprocessor. π
also, for the record: NetBSD curses since 2.0 (2004) supports define_key. so she's not only an ncurses girlie. we love range. π
π§ AUTHORS π§
Thomas Dickey π
π₯ SEE ALSO π₯
ncurses(3NCURSES)keybound(3NCURSES)keyok(3NCURSES)key_defined(3NCURSES)terminfo(5)
go read them. iykyk. π¦
and that's the whole page bestie!! this was ncurses 6.6, dated 2024-12-28, and it's the define_key(3NCURSES) manual page. mwah. go bind some keys. π
β¨π
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- 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