Skip to content

Instantly share code, notes, and snippets.

@upsilun
Created April 10, 2023 23:54
Show Gist options
  • Save upsilun/3b51541a9a7fc96144331bba25f79348 to your computer and use it in GitHub Desktop.
Save upsilun/3b51541a9a7fc96144331bba25f79348 to your computer and use it in GitHub Desktop.
Getting pressed keyboard key in ASCII code
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
char ch;
while(true) {
if(_kbhit()) { // check if key has been pressed
ch = _getch();
cout << "Key pressed: " << (int)ch << endl; // print ASCII code of key
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment