Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ Detect when user presses arrow key

#include <conio.h>
#include <iostream>
using namespace std;

#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77

int main()
{
    int c = 0;
    while(1)
    {
        c = getch();

        switch(c) {
        case KEY_UP:
            cout << endl << "Up" << endl;
            break;
        case KEY_DOWN:
            cout << endl << "Down" << endl;
            break;
        case KEY_LEFT:
            cout << endl << "Left" << endl;
            break;
        case KEY_RIGHT:
            cout << endl << "Right" << endl;
            break;
        default:
            cout << endl << "null" << endl;
            break;
        }
    }

    return 0;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Detect #user #presses #arrow #key
ADD COMMENT
Topic
Name
8+8 =