keyname, key_name Subroutine

Purpose

Gets the name of keys.

Library

Curses Library (libcurses.a)

Syntax

#include <curses.h>

char *keyname(int c);

char *key_name(wchar_t c);

Description

The keyname and key_name subroutines generate a character string whose value describes the key c. The c argument of keyname can be an 8-bit character or a key code. The c argument of key_name must be a wide character.

The string has a format according to the first applicable row in the following table:

Item Description
Input Format of Returned String
Visible character The same character
Control character ^X
Meta-character (keyname only) M-X
Key value defined in <curses.h> (keyname only) KEY_name
None of the above UNKNOWN KEY

The meta-character notation shown above is used only, if meta-characters are enabled.

Parameter

c

Return Values

Upon successful completion, the keyname subroutine returns a pointer to a string as described above, Otherwise, it returns a null pointer.

Examples

int key;
char *name;
keypad(stdscr, TRUE);
addstr("Hit a key");
key=getch();
name=keyname(key);
Note: If the Page Up key is pressed, keyname will return KEY_PPAGE.