I need some kind of routine that can detect when the user has pressed the escape button.
Printable View
I need some kind of routine that can detect when the user has pressed the escape button.
Code:
LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
//which message did we get?
switch(uMsg)
{
case WM_KEYDOWN:
{
//check for escape key
if(wParam==VK_ESCAPE)
{
DestroyWindow(hWndMain);
}
return(0);//
Example of what I mean:
bool done = false;
while(done == false)
{
//if(userhitsescape) {done = true;}
xpos += 1;
DrawScene();
}
return 0;
}
Are you using Win32 API or what? Please be a little more specific.
he says he's using SDL or something like that, I am not really informed on what SDL is, I heard it was like a Direct X wrapper or something, I dont' know.
well all I need is a generic way of detecting whether the escape key is being pressed down...You know how the ASCII characters have numbers assigned to them? You can go char i = 112 and it ends up being a symbol.
I was wondering if the escape button also had a numerical identity.
Um, so you never did answer the question. In your winproc, if you are using Win32, simply check the WM_KEYDOWN message, switch on the wParam, and have a case for value 27 or VK_ESCAPE as stated above. I guess to answer your generic quetsion it would be 27 as I just wrote for the value assigned to it.
Quote:
Originally posted by MrWizard
Um, so you never did answer the question. In your winproc, if you are using Win32, simply check the WM_KEYDOWN message, switch on the wParam, and have a case for value 27 or VK_ESCAPE as stated above. I guess to answer your generic quetsion it would be 27 as I just wrote for the value assigned to it.
I told him that above man......he says he doens't have a winproc.
Well then I told him at the end of my post the value he seeks is 27.
Is this possible outside of winproc?
Yep, I assume he's talking about a text based game here. Or something like that. Also you will need conio.h for the kbhit function.
If this isn't what he meant, I think you'll agree with me he needs to post the whole source or be rather specific, I don't have ESP. :DCode:if( kbhit() )
{
keyCode = getch();
// Escape key pressed
if( keyCode == 27 )
{
// Do something!!!
}
}
EDIT: Man, Dual-Catfish, that game on the ascii page with clicking as many boxes as you can is TOOOO GOOOOD!!!
STFW.
http://www.asciitable.com
And, if you didn't know, you can use the little 'search' button at the top of the page. This question has been asked 10000 times.
yeah yeah yeah, it gets old, stop telling people that. obviously someone with 100+ posts has heard that plenty of times. if I hear that one more time I'm never going to use the search thing again.
and yes I did try using the search function, and no they don't answer my question, and no it hasn't been answered 10000 times
This is the second thread that appeared when I searched for the words press & escape.
http://www.cprogramming.com/cboard/s...t=press+escape
I know it doesn't answer the question directly, but someone with 100+ posts should be able to see where it's headed.