keybound(3NCURSES)

πŸ’– keybound β€” get definition of a curses function key code πŸ’–

okay bestie, so you know how keybound(3NCURSES) lives in the Library calls section of the ncurses fam? yeah. that one. let's get into it ✨


🌸 SYNOPSIS 🌸

#include <curses.h>

char * keybound(int key-code, int count);

✨ DESCRIPTION ✨

so keybound is an ncurses extension (yes, an extension, hold that thought for PORTABILITY, bestie) and what it does is let a curses application get the value of the string that's bound to the function key key-code. if you wanna see where those bindings actually get used on input, go peek at wgetch(3NCURSES) β€” and if you're on the wide-character API side of things, that's wget_wch(3NCURSES) for you πŸ’…

by default, those bindings are string capabilities pulled from the terminfo database entry that matches your terminal type. iconic. classic. the standard behavior, no notes.

now here's the fun part: your app can override those definitions using define_key(3NCURSES) β€” and it's non-destructive and repeatable, like literally you can just keep doing it, because it's as if you're pushing new definitions onto a stack. stack energy. very LIFO of it 🫢

and that's where the count parameter comes in, because it lets you reach into that stack and grab the *n*th most recently defined binding. and if you pass 0? that selects the binding that actually gets used on input. the one that matters. the main character 😌


πŸŽ€ RETURN VALUE πŸŽ€

if key-code matches a function key that's been defined by the application or the terminal type currently in use, then keybound will allocate and hand you back a string. and heads up β€” you, the application, have to free it. that's on you, bestie, don't forget 😭

keybound returns NULL if key-code is not positive, or if it doesn't correspond to a key code definition at all. no binding, no string, that's it.


πŸ¦‹ EXTENSIONS πŸ¦‹

keybound is an ncurses extension. periodt. πŸ’…


🌈 PORTABILITY 🌈

if your application is out here using ncurses extensions, you should condition their use on the visibility of the NCURSES_VERSION preprocessor macro. basically: vibe check the macro before you commit, so your code doesn't get humbled on a system that isn't ncurses. iykyk πŸ”₯


πŸ‘‘ AUTHORS πŸ‘‘

Thomas Dickey


🌟 SEE ALSO 🌟

  • ncurses(3NCURSES)
  • define_key(3NCURSES)
  • keyok(3NCURSES)
  • key_defined(3NCURSES)
  • terminfo(5)

and that's the whole page, bestie β€” no crumbs left πŸ“ this was ncurses 6.6, dated 2024-12-28, and honestly? she ate. go bind some keys πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from