Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

escape characters

This topic is 5230 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

How do i create a character in c++ where if the user presses it at any time during the program it exits. Eg/ a program runs until the user preses q or even ctrl + q. Any help would be appreciated.

Share this post

Link to post
Share on other sites
I might be wrong on this

but at the top in your defines add,

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

Then in your main game loop you can add something such as,

// In your case I think you'd replace VK_ESCAPE with
// 51 which is the hexadecimal value for the Q key

PostMessage(main_window_handle, WM_DESTROY,0,0);

As for CTRL-Q? I have no idea

[edited by - _vizual_ on January 24, 2004 3:48:41 PM]

Share this post

Link to post
Share on other sites
the only way i can think of is each time you ask for input, allow a "quit" input. For example, if you''re asking for a choice of 0-9, you accept all input 0-9 as well as q, where if the input''s q you quit.

If, however, you''re for example calculating a billion numbers and you want to allow the user to quit inbetween you could setup intervals (like every 10 million calculatoins) at which point you ask the user whether or not he wishes to quit. Also, it''d be a good idea to insert a timer so that after x seconds it goes on (if no input was given).

As for an example, here''s my (rather messy) input loop from my console game:
if(i>=0&&i<=6){ /* needs to be changed if menu is expanded! */
}else if(i+48==''x''||i+48==''X''||i+48==''q''||i+48==''Q''){
std::cout<<"Are you sure you wish to quit? (Y/N)"<<std::endl;

in case you''re wondering, getint() is just a getch() + 48.

Share this post

Link to post
Share on other sites

  • 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!