1curs_getch(3X) curs_getch(3X)
2
3
4
6 getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or push back)
7 characters from curses terminal keyboard
8
10 #include <curses.h>
11
12 int getch(void);
13 int wgetch(WINDOW *win);
14
15 int mvgetch(int y, int x);
16 int mvwgetch(WINDOW *win, int y, int x);
17
18 int ungetch(int ch);
19
20 /* extension */
21 int has_key(int ch);
22
24 Reading characters
25 The getch, wgetch, mvgetch and mvwgetch, routines read a character from
26 the window. In no-delay mode, if no input is waiting, the value ERR is
27 returned. In delay mode, the program waits until the system passes
28 text through to the program. Depending on the setting of cbreak, this
29 is after one character (cbreak mode), or after the first newline
30 (nocbreak mode). In half-delay mode, the program waits until a charac‐
31 ter is typed or the specified timeout has been reached.
32
33 If echo is enabled, and the window is not a pad, then the character
34 will also be echoed into the designated window according to the follow‐
35 ing rules:
36
37 • If the character is the current erase character, left arrow, or
38 backspace, the cursor is moved one space to the left and that
39 screen position is erased as if delch had been called.
40
41 • If the character value is any other KEY_ define, the user is alert‐
42 ed with a beep call.
43
44 • If the character is a carriage-return, and if nl is enabled, it is
45 translated to a line-feed after echoing.
46
47 • Otherwise the character is simply output to the screen.
48
49 If the window is not a pad, and it has been moved or modified since the
50 last call to wrefresh, wrefresh will be called before another character
51 is read.
52
53 Keypad mode
54 If keypad is TRUE, and a function key is pressed, the token for that
55 function key is returned instead of the raw characters:
56
57 • The predefined function keys are listed in <curses.h> as macros
58 with values outside the range of 8-bit characters. Their names be‐
59 gin with KEY_.
60
61 • Other (user-defined) function keys which may be defined using de‐
62 fine_key(3X) have no names, but also are expected to have values
63 outside the range of 8-bit characters.
64
65 Thus, a variable intended to hold the return value of a function key
66 must be of short size or larger.
67
68 When a character that could be the beginning of a function key is re‐
69 ceived (which, on modern terminals, means an escape character), curses
70 sets a timer. If the remainder of the sequence does not come in within
71 the designated time, the character is passed through; otherwise, the
72 function key value is returned. For this reason, many