How to tell when pressing escape?

This is a discussion on How to tell when pressing escape? within the C++ Programming forums, part of the General Programming Boards category; I need some kind of routine that can detect when the user has pressed the escape button....

  1. #1
    Shadow12345
    Guest

    How to tell when pressing escape?

    I need some kind of routine that can detect when the user has pressed the escape button.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    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);//
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    Shadow12345
    Guest
    Example of what I mean:
    bool done = false;
    while(done == false)
    {
    //if(userhitsescape) {done = true;}
    xpos += 1;

    DrawScene();
    }


    return 0;
    }

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Are you using Win32 API or what? Please be a little more specific.

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    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.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  6. #6
    Shadow12345
    Guest
    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.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    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.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  8. #8
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    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.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well then I told him at the end of my post the value he seeks is 27.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  10. #10
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Is this possible outside of winproc?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    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.
    Code:
    if( kbhit() )
    {
         keyCode = getch();
    			
         // Escape key pressed
         if( keyCode == 27 )
         {
               // Do something!!!
         }
    }
    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.

    EDIT: Man, Dual-Catfish, that game on the ascii page with clicking as many boxes as you can is TOOOO GOOOOD!!!
    Last edited by MrWizard; 05-24-2002 at 10:25 PM.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  12. #12
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    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.

  13. #13
    Shadow12345
    Guest
    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.

  14. #14
    Shadow12345
    Guest
    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

  15. #15
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    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.
    Demonographic rhinology is not the only possible outcome, but why take the chance

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LoadFromFile() from a txt
    By Snoopy104 in forum C++ Programming
    Replies: 6
    Last Post: 03-14-2006, 09:05 AM
  2. Escape Codes
    By renurv in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2006, 01:01 PM
  3. Interpreting literal escape sequences from a file...
    By Sebastiani in forum C++ Programming
    Replies: 1
    Last Post: 07-08-2003, 02:00 PM
  4. Escape characters
    By The Gweech in forum C++ Programming
    Replies: 3
    Last Post: 07-09-2002, 05:38 PM
  5. Using escape sequences as user inputs
    By musayume in forum C Programming
    Replies: 4
    Last Post: 12-11-2001, 08:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21