How to specify the key you want wwith sdl.
I know how to check if a key is pressed,but I donnt know how to specify which key I want...I try to look in the docs, but half the time they don''t work HELP!!!!!
if(Event.key.keysym.sym == SDLK_a) {
std::cout << "You pressed a!\n";
}
Of course you'll need to distinguish between a key press and a key release.
You should have something like this:
An event function like this:
And then:
[edited by - MetaCipher on May 18, 2004 2:40:49 PM]
std::cout << "You pressed a!\n";
}
Of course you'll need to distinguish between a key press and a key release.
You should have something like this:
An event function like this:
void OnEvent(SDL_Event* Event) { switch(Event->type) { case SDL_KEYDOWN: { OnKeyDown(Event->key.keysym.sym); break; } case SDL_KEYUP: { OnKeyUp(Event->key.keysym.sym); break; } }}
And then:
void OnKeyDown(SDLKey sym) { switch(sym) { case SDLK_ESCAPE: { //Escape break; } }}void OnKeyUp(SDLKey sym) { switch(sym) { }}
[edited by - MetaCipher on May 18, 2004 2:40:49 PM]
Oh, look at SDL_keysym.h to see a list of keyboard keys. (Also note, you can check for unicode keys and mod keys by using .mod or .unicode instead of .sym at the end).
It''s not a function. I don''t know if you have done any OOP or used structures before, but the .sym at the end is a variable (int I believe) and you can just check the key with an equal == .
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement