Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Disable escape key or trap it.

Author
Message
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 1st May 2011 03:06
Hi ,

I would like to ask is it possible when I am pressing escape key in my game , instead of terminate my program to handle the key and open some options menu.

I tried press_esc=keystate(1) variable
or escapekey() and both terminates my program.


I use this code:




Thank you
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 1st May 2011 03:21
Use DISABLE ESCAPEKEY first.

Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 3rd May 2011 07:19
That's right. The engine has hard-code to terminate on ESC, and it's hooked at a lower level than code execution. This means that if the user hits ESC, the engine will interpret it as a terminate before the code is allowed to detect that ESC has been pressed.

Using DISABLE ESCAPEKEY near the top of your program will switch off this lowlevel hook, so that it will no longer terminate. Your program will then be able to catch it to use any way you like.

If you disable escape, you'll need to code another means of exiting your program or the user will be restricted to ALT-F4 or hitting the close button in the caption bar.

Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 2nd Jul 2011 02:39
Yes your trick worked perfect.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Jul 2011 12:34
You can also use "escapekey()" to find out if the escapekey is being pressed... that way you can control what happens when it is pressed, maybe pop up a message saying "Are you sure you want to quit?"

Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 5th Sep 2011 18:25
Yes this worked great.

Login to post a reply

Server time is: 2024-11-27 19:53:42
Your offset time is: 2024-11-27 19:53:42