Aug 7, 2012 at 5:11am UTC
I've been wondering for a while if there is a way to run some code when you press a certain key. for instance:
When the key 'M' is pressed, then:
cout << "'M' key pressed!" << endl;
How do I do this?
Aug 7, 2012 at 5:13am UTC
There is no standard for this. Your best bet is to look into your OS's API for something. Duoas has an article about doing something similar with the Windows API.
Aug 7, 2012 at 10:23am UTC
or SFML, which doesn't use ugly capitals and is written in C++ instead of C.
just sayin'
Aug 7, 2012 at 2:55pm UTC
Is there any reason this can't be done? Like something I dont know about?
if(GetAsyncKeyState(VK_UP))
{
std::cout << "You pressed up";
}
Or is it because that is just for Windows?
Aug 8, 2012 at 1:26am UTC
Only for windows, but I don't believe it "just works" like that. I could be wrong, however.
Aug 8, 2012 at 1:12pm UTC
I believe that is the wrong syntax for getasynckeystate() but it is rather easy to use.
Aug 8, 2012 at 8:24pm UTC
It probably is the wrong syntax or something. I havent used it in a long time.