Jump to content
  • Advertisement

Archived

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

exodus7

Keyboard Input??

This topic is 5396 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''m having a problem with a simple windows program I created. Basically all I want is a user to press Esc on the keyboard and the window to close. So: if (VK_ESCAPE) { // close window. } This won''t work Is this if statement correct, or is there more to it than that?

Share this post


Link to post
Share on other sites
Advertisement
Well surely you want a   key == VK_ESCAPE   (or whatever - I haven''t changed my Win32 code in a year). The way the code stands I''m guessing it would always exit, if VK_ESCAPE is a positive integer . . .

Also, more information than ''This won''t work'' would probably be useful ; )

Share this post


Link to post
Share on other sites
Does it even get as far as your message handler? Window created OK?

And the more source code you can give me more we can help.

Share this post


Link to post
Share on other sites
As far as I can remember from my readings you have to do a

case WM_KEYDOWN
{
switch(virtualkey) <---? something like that
case VK_ESCAPE
{
//close
}
}

Sorry if this is way off, but im a newb as well and I dont have my references with me at work.

Share this post


Link to post
Share on other sites
VK_ESCAPE is a defined constant
#define VK_ESCAPE 27 // or something

so your if statement looks something like
if(27) exit;

which allways evaluates to true
if you are handling a windows message you wanna do something like
if(wparam==VK_ESCAPE) exit;
then you got proper syntax happenin

a better way to handle messages is with a switch case statment, cleaner looking.

switch(wparam)
{
case VK_ESCAPE:
exit;
default:
break;
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!