milosd,<br>
<br>
I think this is what you are looking for. You have to remember that "special" keys like the arrow keys require special handling since they generate two bytes instead of one. The first byte is NULL. For the second byte, the down arrow key produces "80", the up arrow produces "72", the left arrow produces "75", and the right arrow produces "77." <br>
<br>
If you are interested, I have a snippet of code that will show you the ascii code for those special keys. It is a piece of code I picked up off a borland newsgroup. I haven't tested it so I can't say if really works or not.<br>
<br>
<br>
<p>James P. Cottingham<br><a href=mailto:main@ivcusa.com>main@ivcusa.com</a><br><a href=
As 2ffat says, you have to read the key twice for an extended code. Here's how in the DOS environment (Windows is different) :<br>
<br>
a = getch(); /* Get key press */<br>
if (a == 0 ¦¦ a == 0xE0) { a = getch() + 0x100; } /* Add 256 if extended: This makes the rest of the code easier to write */<br>
switch ( a )<br>
{<br>
case 27: /* If escape key */<br>
printf( "Exiting..." );<br>
goto end; /* Sorry */<br>
case 328: /* If Up Arrow key */<br>
/* Do stuff for Up Arrow Key */<br>
break;<br>
case 336: /* If Down Arrow key */ <br>
/* Do stuff for Down Arrow Key */<br>
break;<br>
<br>
The rest of the keycodes can be figured out by putting this into the above code before the switch(a) statement:<br>
<br>
printf("Keycode is %d\n", a );<br>
<br>
I hope this helps. <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href=
Here is the snippet of code that I found that shows what the ascii codes are for keys presses. It's DOS based and I can't say how well it works since I've never compiled it.<br>
<br>
#include <conio.h><br>
#include <stdio.h><br>
<br>
int main()<br>
{<br>
int a, b;<br>
while (1)<br>
{<br>
a = getch();<br>
if (!a)<br>
{<br>
b = getch();<br>
printf("%3i, %3i \n", a, b);<br>
}<br>
else printf("%3i \n", a);<br>
if (a == 'q') break;<br>
}<br>
return 0;<br>
}<br>
<br>
No telling where the original code came from or how many changes have been made in the mean time. I suppose that I should test the code before I post it but . . .<br>
<br>
zBuilder's code is more practical but this code should show you the ascii code of keys.<br>
<br>
Good Luck!<br>
<p>James P. Cottingham<br><a href=mailto:main@ivcusa.com>main@ivcusa.com</a><br><a href=
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.