Archived

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

exodus7

Keyboard Input??

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