define\_key(3X) Library calls define\_key(3X)

# [NAME](#NAME)

**define\_key** - define a *curses* function key code

# [SYNOPSIS](#SYNOPSIS)

```
#include <curses.h>
```

```
int define_key(const char * definition, int key-code);
```

# [DESCRIPTION](#DESCRIPTION)

The **define\_key** *ncurses* extension permits a *curses* application to *bind* a string *definition* to the function key *key-code* returned by [**wgetch**(3X)](/man/os/ncurses/wgetch.3X) (wide-character API users: [**wget\_wch**(3X)](/man/os/ncurses/wget_wch.3X)) when [**keypad**(3X)](/man/os/ncurses/keypad.3X) is enabled in a window and a function key is pressed. *ncurses* interprets such a binding as it does those in the *terminfo* database entry for the terminal type.

A *definition* of *NULL* removes any existing binding from *key-code*. Similarly, a non-positive *key-code* removes an existing binding for *definition*, if any.

# [RETURN VALUE](#RETURN_VALUE)

**define\_key** returns **ERR** if

- *definition* is *NULL* and *key-code* is nonpositive, or
- insufficient memory is available to bind *definition* to *key-code*.

Otherwise, **define\_key** returns **OK**.

# [EXTENSIONS](#EXTENSIONS)

**define\_key** is an *ncurses* extension.

# [PORTABILITY](#PORTABILITY)

Applications employing *ncurses* extensions should condition their use on the visibility of the **NCURSES\_VERSION** preprocessor macro.

NetBSD *curses* since 2.0 (2004) supports *define\_key*.

# [AUTHORS](#AUTHORS)

Thomas Dickey

# [SEE ALSO](#SEE_ALSO)

[**curses**(3X)](/man/os/ncurses/curses.3X), [**keybound**(3X)](/man/os/ncurses/keybound.3X), [**keyok**(3X)](/man/os/ncurses/keyok.3X), [**key\_defined**(3X)](/man/os/ncurses/key_defined.3X), [**terminfo**(5)](/man/os/ncurses/terminfo.5)

2024-12-28 ncurses 6.6

---

Document: define_key(3x) from ncurses 6.6.20261010-r0 (Chainguard OS)
Source: https://github.com/ThomasDickey/ncurses-snapshots
