Skip to content

Instantly share code, notes, and snippets.

@3rt4nm4n
Created November 17, 2021 18:53
Show Gist options
  • Save 3rt4nm4n/2f25573f4efb8ba6474b7ff88915cac2 to your computer and use it in GitHub Desktop.
Save 3rt4nm4n/2f25573f4efb8ba6474b7ff88915cac2 to your computer and use it in GitHub Desktop.
This is a C++ program that will detect Left, Up, Right and Down arrow keys when they are pressed, it will give outputs. The program may give such outputs like [[A^, these are raw key codes that are sent by computer to the terminal.
#include <iostream>
//#include <conio.h> for windows users who will use getch() in switch condition
using namespace std;
int main()
{
char ch;
switch(scanf(&ch))
{
case 37:
cout<<"Left Button"<<endl;
break;
case 38:
cout<<"Up Button"<<endl;
break;
case 39:
cout<<"Right Button"<<endl;
break;
case 40:
cout<<"Down Button"<<endl;
break;
default:
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment