I want to know if it is possible...
Articles and Tips: qna
01 Mar 2002
Q.
I want to know if it is possible to trap the up arrow and the down arrow keys. I am writing an application where I need to change the attributes of a character when the up arrow or down arrow key is pressed.
Basically, the screen will wait for keyboard input. The program will wait in an infinite loop and scan for key strokes. The user will not hit the return key after any key stroke. The data must be available immediately. Hitting return or ESC will cause the screen to close.
A.
Your program can read the up and down arrows with getch(). Up arrow is translated to two codes, 0 and 72, and the down arrow is translated to 0, 80. I'm attaching a small program that reads keys with getch() and displays their codes. Another possibility is to use NWSNUT.
#include <nwconio.h> #include <nwthread.h> #include <stdio.h> #include <stdlib.h> int main( void) { int key; puts( "Press keys to see their codes, <Esc> for exit"); while (( key = getch()) != 27) printf( "%d\n", key); return EXIT_SUCCESS; }
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.