Sign in to follow this  

multiple key input

This topic is 3487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I looked on here earlier, but i was still kind of confused about pressing two keyboard buttons at once. Can anyone tell me how to write a quick function so that lets say that i wanted to terminate the program case ?: exit (0); break; how would i do this if i wanted them to press 'a' and 'b' at the same time to terminate the program? (not that this part would have any use, but it could obviously be expanded to other things) thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by voldemort62442
I looked on here earlier, but i was still kind of confused about pressing two keyboard buttons at once. Can anyone tell me how to write a quick function so that lets say that i wanted to terminate the program



case ?:
exit (0);
break;


how would i do this if i wanted them to press 'a' and 'b' at the same time to terminate the program?


(not that this part would have any use, but it could obviously be expanded to other things)

thanks


this really depends on what platform you're on.

For SDL you can do:


bool keys[SDLK_LAST];
for (int i=0;i<SDLK_LAST;i++) keys[i] = false;

SDL_Event event;
while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;
case SDL_KEYUP:
keys[event.key.keysym.sym] = false;
break;
//more events ....
}
}

if (keys[SDLK_a] && keys[SDLK_b]) exit(0);
}




the same method works with Win32, Java, and most other platforms aswell. (The event handling is done differently though)

Share this post


Link to post
Share on other sites

This topic is 3487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this