Jump to content
  • Advertisement
Sign in to follow this  
voldemort62442

multiple key input

This topic is 3676 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
Advertisement
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 = 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
Quote:
Original post by voldemort62442
c++

??

C++ is a language, not an API or platform , C++ doesn't do proper input handling (C++ doesn't really do much of anything).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!