TERMKEY\_STRFKEY(3) Library Functions Manual TERMKEY\_STRFKEY(3)

# [NAME](#NAME)

termkey\_strfkey - format a string representing a key event

# [SYNOPSIS](#SYNOPSIS)

```
#include <termkey.h>

size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len,
            TermKeyKey *key, TermKeyFormat format);
```

Link with *-ltermkey*.

# [DESCRIPTION](#DESCRIPTION)

**termkey\_strfkey**() formats a string buffer to contain a human-readable representation of a key event. It fills the *buffer* in a way analogous to the [**snprintf**(3)](/man/os/libtermkey/snprintf.3) or [**strftime**(3)](/man/os/libtermkey/strftime.3) standard library functions. This function used to be called **termkey\_snprint\_key**() but was renamed after version 0.6.

The *format* argument specifies the format of the output, as a bitmask of the following constants:

[**TERMKEY\_FORMAT\_LONGMOD**](#TERMKEY_FORMAT_LONGMOD)

Print full modifier names e.g. "Shift-" instead of abbreviating to "S-".

[**TERMKEY\_FORMAT\_CARETCTRL**](#TERMKEY_FORMAT_CARETCTRL)

If the only modifier is **TERMKEY\_MOD\_CTRL** on a plain letter, render it as "^X" rather than "Ctrl-X".

[**TERMKEY\_FORMAT\_ALTISMETA**](#TERMKEY_FORMAT_ALTISMETA)

Use the name "Meta" or the letter "M" instead of "Alt" or "A".

[**TERMKEY\_FORMAT\_WRAPBRACKET**](#TERMKEY_FORMAT_WRAPBRACKET)

If the key event is a special key instead of unmodified Unicode, wrap it in "&lt;brackets&gt;".

[**TERMKEY\_FORMAT\_SPACEMOD**](#TERMKEY_FORMAT_SPACEMOD)

Use spaces instead of hyphens to separate the modifier name(s) from the base key name.

[**TERMKEY\_FORMAT\_LOWERMOD**](#TERMKEY_FORMAT_LOWERMOD)

Use lowercase for the modifier name.

[**TERMKEY\_FORMAT\_LOWERSPACE**](#TERMKEY_FORMAT_LOWERSPACE)

Use lowercase with spaces in for the key name instead of camelCase (for example "page down" instead of "PageDown").

[**TERMKEY\_FORMAT\_MOUSE\_POS**](#TERMKEY_FORMAT_MOUSE_POS)

If the event is a mouse event, include the position rendered as "@ (col,line)".

The following shortcuts are provided for common combinations of format bits:

[**TERMKEY\_FORMAT\_VIM**](#TERMKEY_FORMAT_VIM)

Shortcut to set **ALTISMETA** and **WRAPBRACKET**, to give an output close to the format the *vim* editor uses.

[**TERMKEY\_FORMAT\_URWID**](#TERMKEY_FORMAT_URWID)

Shortcut to set **ALTISMETA**, **LONGMOD**, **LOWERMOD**, **SPACEMOD** and **LOWERSPACE**, to give an output close to the format the *urwid* python library uses.

When formatting a **TERMKEY\_TYPE\_UNICODE** key structure, this function uses the *utf8* member. If this member contains an empty string (i.e. its first character is 0) then this member will be prefilled by the function from the *code.number* member. This can be convenient when the key structure is being constructed programmatically by user code.

# [RETURN VALUE](#RETURN_VALUE)

**termkey\_strfkey**() returns the number of characters written to *buffer*.

# [SEE ALSO](#SEE_ALSO)

[**termkey\_new**(3)](/man/os/libtermkey/termkey_new.3), [**termkey\_getkey**(3)](/man/os/libtermkey/termkey_getkey.3), [**termkey\_waitkey**(3)](/man/os/libtermkey/termkey_waitkey.3), [**termkey\_get\_keyname**(3)](/man/os/libtermkey/termkey_get_keyname.3), [**termkey\_strpkey**(3)](/man/os/libtermkey/termkey_strpkey.3), [**termkey**(7)](/man/os/libtermkey/termkey.7)

---

Document: termkey_strfkey(3) from libtermkey 0.22-r8 (Chainguard OS)
