Keycodes (von Sondertasten) auslesen / ncurses

Post Reply
Message
Author
mrasp
Posts: 1
Joined: 06. Jan 2005 8:29
Contact:

Keycodes (von Sondertasten) auslesen / ncurses

#1 Post by mrasp »

Frohes Neues!

Ich möchte ein Testprogramm für Tastaturen schreiben. Dazu muss im Prinzip sofort nach Tastendruck der Keycode der gedrückten Taste abgefragt werden.

Mit ncurses kann ich die meisten normalen Tasten abfragen, aber es gibt da zwei Probleme:

1. Tasten wie ESC, ^, ' kommen nur verspätet nachdem man die Leertaste gedrückt hat.

2. Tasten wie CAPS, Shift links/rechts, Strg, Windows-Tasten, Alt, Alt-Gr, Druck, Rollen, Pause können damit gar nicht abgefragt werden.

Hat von euch jemand eine Idee?

Martin

User avatar
heinrich
Posts: 219
Joined: 22. Sep 1999 11:22
Location: N49.137 E8.544

#2 Post by heinrich »

Beispielquellcode wie man die Cursor- und F-Tasten abfrägt:
http://www.paulgriffiths.net/program/c/curin1src.html

ncurses programming guide
http://www.apmaths.uwo.ca/~xli/ncurses.html#input
Abschnitt: Input - Read user input from keyboard

Und im "The Linux Programmer's Guide" steht in Kapitel 8.7 "Input" auch ein Absatz über dein ESC Problem:
http://www.tldp.org/LDP/lpg/lpg.html
8.7 Input
int getch()
int wgetch(win)
int mvgetch(y, x)
int mvwgetch(win, y, x)
getch() will read input from the terminal in a manner depending on whether delay mode is set or not. If delay is on, getch() will wait until a key is pressed, otherwise it will return the key in the input buffer or ERR if this buffer is empty. mvgetch(...) and mvwgetch(...) will move the cursor to position y,x first. The w functions read input from the terminal related to the window win, getch() and mvgetch(...) from the terminal related to .

With keypad(...) enabled, getch() will return a code defined in .h as KEY_* macros when a function key is pressed. When ESCAPE is pressed (which can be the beginning of a function key) ncurses will start a one second timer. If the remainder of the keystroke is not finished in this second, the key is returned. Otherwise, the function key value is returned. (If necessary, use notimeout() to disable the second timer).
...und auch im Kapitel 8.8.1 "Input Options"
8.8.1 Input Options

int keypad(win, bf)
If TRUE, it enables the keypad on the keyboard of the user's terminal when waiting for input. Ncurses will then return a key code defined in .h as KEY_* for the function and arrow keys on the keypad. This is very useful for a PC keyboard because you can enable the numerical block and the cursor keys.
[...]
int notimeout(win, bf)
If bf is TRUE, getch() will use a special timer (of one second length) to interpret and input sequence beginning with keys as ESCAPE etc.
[...]
It just works.

Post Reply