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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASCII code for arrows

Status
Not open for further replies.

milosd

Programmer
Mar 2, 2000
9
0
0
SI
I would like to know ASCII codes for keyboard arrows.Any information welcomed.
 
milosd,<br>
<br>
I think this is what you are looking for. You have to remember that &quot;special&quot; 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 &quot;80&quot;, the up arrow produces &quot;72&quot;, the left arrow produces &quot;75&quot;, and the right arrow produces &quot;77.&quot; <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= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
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( &quot;Exiting...&quot; );<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(&quot;Keycode is %d\n&quot;, a );<br>
<br>
I hope this helps. <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
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 &lt;conio.h&gt;<br>
#include &lt;stdio.h&gt;<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(&quot;%3i, %3i \n&quot;, a, b);<br>
}<br>
else printf(&quot;%3i \n&quot;, 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= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top