Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detecting function or cursor key press

Status
Not open for further replies.

JoshuaH82

Programmer
Jun 5, 2001
3
US
I'm having problems detecting the function keys, or any non ASCII character for that matter. getch() doesn't work when it comes to picking those keys up. Is there a function anywhere that will detect the non-standard key pressed or any tips on doing it? I'm running linux 2.4.2 with gcc. Also, I'm using curses.h
 
Looks like I answered my own question...here's how:

/*
* First off, (n)curses.h's #define macros for the F keys don't work.
* I took each F key I needed and #defined it explicitly. Then, using
* (n)curses.h's keypad() function, I told curses which windows I wanted
* to process these special keys from. Then I compared the int returned
* by wgetch() with my #defines...
*/

#define KEY_F5 0415 /* F5 key to exit */
...
keypad(mywindow);
...
int key;
key = wgetch(mywindow);
switch(key)
{
case KEY_F5:
done = 1; /* exit loop */
break;
}
 
Using getch() will work; u can directly refer to scan codes. for this code will be :

ch=getch();
if(ch==0)
{
if(ch==72)
{
printf("Down Arrow key Pressed.");
}
}

Regards,
SwapSawe.
 
Swap,

This doesn't work with the function keys tho. And I tried getch() on different keys on different systems and the scan codes weren't consistent.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top