From: Uno on
How do I get these keystrokes:

Name Key name
KEY_BREAK Break key
KEY_DOWN The four arrow keys ...
KEY_UP
KEY_LEFT
KEY_RIGHT
KEY_HOME Home key (upward+left arrow)
KEY_BACKSPACE Backspace
KEY_F0 Function keys; space for 64 keys
is reserved.
KEY_F(n) For 0 ≤ n ≤ 63
KEY_DL Delete line
KEY_IL Insert line
KEY_DC Delete character
KEY_IC Insert char or enter insert mode
KEY_EIC Exit insert char mode
KEY_CLEAR Clear screen
KEY_EOS Clear to end of screen
KEY_EOL Clear to end of line
KEY_SF Scroll 1 line forward

to show up in a program that looks somewhat like this:

#define _XOPEN_SOURCE 500
//#define _XOPEN_SOURCE_EXTENDED 1
#include <stdio.h>
#include <curses.h>

int
tty_getchar ()
{
return getchar ();
}

int
tty_break ()
{
initscr ();
cbreak ();
return 0;
}

int
main (void)
{
int m, n;

while ((n = tty_break ()) != 0)
{
m = tty_getchar ();
printf ("%c = %d\n", m, m);
}
return 0;
}

// gcc -Wall -Wextra -lcurses p4.c -o out

??
--
Uno
From: Gordon Burditt on
>How do I get these keystrokes:
> Name Key name
....
>
>to show up in a program that looks somewhat like this:
>
>#define _XOPEN_SOURCE 500
>//#define _XOPEN_SOURCE_EXTENDED 1
>#include <stdio.h>
>#include <curses.h>
>
>int
>tty_getchar ()
>{
> return getchar ();
>}

First, use a curses input routine, *not* getchar().
Hint: getch()
Also look at the keypad() function.

Note that curses generally does a poor job of interpreting multi-key
sequences generated by special keys if the sequence for one key is
a prefix of the sequence for another key. (On typical VT100-style
terminals, don't try to use the ESC key along with arrow keys, for
example). The timing required can be disrupted by network traffic
for a remote terminal. It's not always so great over a serial port,
either.