• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Programming question

Kntx

Platinum Member
I'm programming something in C and I want the arrow keys on the keyboard to affect a variable.

How do I go about doing that???
 
you have to find the ASCII values for the arrow keys. well, when I made a game, I used W-A-S-D as the controls, and said that if the input was like 87 which is W (its not, I dont remember the number), then do do this.

Hope this helps.
 
Actually, the ASCII value approach will not work since the arrow keys do not have ASCII values. The problem is a bit more complex and entirely dependent upon the environment in which you are programming. If you are writing a Windows/X-Windows program, then you tell the event handler that you want to catch keyboard input, and in your callback function you check the keycode and react accordingly.

If you are in a DOS/UNIX world, there are a couple of approaches. You may be able to tell the signal handler to call a function when a key is pressed and handle things from there. Otherwise you have to query standard input to see if anything is present. This gets even trickier since the arrow keys are typically handled as a sequence of values (ESC-A for the up arrow under UNIX vt100 emulation for instance).
 
Back
Top