If you are using Windows you might be able to use this...
#include <conio.h>
#include <iostream>
int main()
{
int key = 0;
while(key != 27)
if(kbhit())
{
key = getch();
std::cout << "Key: " << static_cast<char>(key);
std::cout << " Keycode: " << key << std::endl;
}
}