Thread: Arrow keys as keyboard Input

  1. #1
    Registered User
    Join Date
    Jul 2005

    Arrow keys as keyboard Input

    Hey everyone i am trying to write an openGL program that uses the arrow keys to rotate an image. The problem is i can't seem to find out how to use the keys. Is there specific numbers that corresponds to them? ASCII values ?

    I need to say :

    if (key == arrow key) { 

    thanks in advance,

  2. #2
    Registered User
    Join Date
    Aug 2005
    I know there's a chart somplace, but this simple program will tell you the ascii value of any key on the keyboard. This program will make special keys such as arrow keys and function keys negative so that a program can distinguish between special and normal keys. special keys have the same ascii value of normal keys, the difference is that specia keys are returned as two integers instead of one.

    #include <iostream>
    #include <conio.h>
    using namespace std;
    int main() /* program main begins execution */
    	int c= 0;
    	while( c != 27)
    		c = getche();
    		if(c == 0 || c == 224)
    			c = -getche();
    		cout << c << endl;
       return 0;  /* indicates successful program execution */

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    I've posted this before, but this is a program that I wrote a while back that accepts input for all keys on the keyboard (except utility keys like CTRL and Lock Keys...). Thought, I must admit, the versions in the FAQs is signifcantly better.

    Another thing worth mentioning, if that if you're using OpenGL and you're looking to make a pretty advanced program, there are probably better ways for doing this. Windows.h has commands that can read key taps, solid key presses, keys being held down, etc... you may want to look into those.
    Last edited by SlyMaelstrom; 12-01-2005 at 09:45 PM.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interacting with keyboard input.
    By Devils Child in forum C# Programming
    Replies: 4
    Last Post: 06-05-2009, 12:06 AM
  2. Simple keyboard input
    By Da-Nuka in forum C++ Programming
    Replies: 1
    Last Post: 02-12-2005, 11:33 AM
  3. getting input from keyboard, passing to execvp
    By jumpyg in forum C++ Programming
    Replies: 4
    Last Post: 11-02-2003, 08:49 PM
  4. Arrow keys
    By Nutshell in forum C Programming
    Replies: 5
    Last Post: 03-27-2002, 11:49 AM
  5. ascii value for the arrow keys
    By uvacow in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2002, 06:17 PM