---
name: "define_key"
section: "3ncurses"
platform: "linux"
package: "ncurses-doc"
version: "6.5+20250216-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/define_key/3ncurses"
---

# define\_key(3ncurses)

define a curses function key code

## NAME

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

## SYNOPSIS

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

**int define\_key(const char \*** *definition***, int** *key-code***);**

## DESCRIPTION

**The** **define\_key** *ncurses* **extension permits a** *curses* **application to** *bind* **a string** *definition* **to the function key** *key-code* **returned by wgetch(3NCURSES)** **(wide-character API users:** **wget\_wch(3NCURSES))** **when keypad(3NCURSES) 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

**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

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

## 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

**Thomas Dickey**

## SEE ALSO

**ncurses(3NCURSES),** **keybound(3NCURSES),** **keyok(3NCURSES),** **key\_defined(3NCURSES),** **[terminfo(5)](/terminfo/5.md)**
