KEY_ESCAPE not exiting?
BlitzMax Forums/BlitzMax Programming/KEY_ESCAPE not exiting?
| ||
I am using BlitzMAX and seem unable to exit test applications using the normal:Strict Framework brl.blitz Import brl.max2d Repeat DebugLog "HELP!" Until KeyHit(KEY_ESCAPE) Am I overlooking something here? |
| ||
Polling isn't enabled until you create a graphics object. |
| ||
EnablePolledInput() |
| ||
Can someone please try this, or supply an example that works? I have exhausted ideas and still have the same problem. I am unable to quit a simple test program. @AngelDaniel I have tried enablepolledinput() but the same is still true. I cannot exit this simple test loop? Here is an example that works but has a window (Arghhh....) Strict Framework brl.d3d7max2d Import brl.max2d Graphics 0,0,0 Repeat DebugLog "HELP!" Until KeyHit(KEY_ESCAPE) |
| ||
[EDIT] Oops, it would help if I read the post correctly! |
| ||
yeah he's write the version with no graphics window bu using EnablePolledInput() doesn't work, it just loops forever. I found the same thing out a while back, not sure how to fix. Maybe it needs a Delay(1) in there? |
| ||
Your code works fine for me. Escape exits. Tested on windows XP. Perhaps your example is too simple for some reason? try Changing the Graphics line to Graphics 800,600,1,16 That should force 800x600 full screen 16bit, which should make all the input polling and other background whatnot run right. Also could try changing DebugLog to just a simple Print for testing. |
| ||
Strict Local can:Tgadget = CreateCanvas(0,0,1,1,CreateWindow("Game Window",0,0,1,1,Null,WINDOW_CLIENTCOORDS)) SetGraphics CanvasGraphics(can) ActivateGadget (can) Repeat DebugLog "HELP!" Until (PollEvent()<>0 And (EventID() = EVENT_KEYDOWN And EventData() = KEY_SPACE))Sorry its a maxgui solution, (But I have maxgui, so its the one I know) You still have a window, but now its really tiny, and once it loses focus youre in trouble. Basicly unless you have some way to keep focus, you cannot poll events. It comes down to there needs to be somehthing in the gui envioment (win/lynx etc), that is in focus. Your code works fine for me Read again, the second code is supposed to work. And the esc works on the debug output window in the ide |
| ||
If you don't want a window but want to detect keypresses, on Windows you could use the GetKeyState() and GetAsyncKeyState() API calls. Here's a quick example I knocked up that doesn't require you to keep focus and more importantly, doesn't require any graphics interfaces or windows: Windows only: SuperStrict Framework BRL.StandardIO Import BRL.PolledInput Import Pub.Win32 'Let's create a reference to the function (the user32.dll is imported using Pub.Win32 module) Extern "win32" Function GetAsyncKeyState%(vKey%) 'Get's the no of times the key has been pressed since last call EndExtern Repeat 'Loop until we hit escape PollSystem() Until GetAsyncKeyState(KEY_ESCAPE) Print "Ending" End |
| ||
What if I wanted to use a key modifier (like CTRL or ALT (MODIFIER_CONTROL = ctrl)), if you change the end of the loop to:Until GetAsyncKeyState(KEY_ESCAPE) And GetAsyncKeyState(MODIFIER_CONTROL) it wont leave the loop and you have to end it through the debugger. {EDIT} Since we're all talking about keys, in BRL.KeyCodes why are the following keys: Rem Const KEY_PAUSE=19 Const KEY_CAPSLOCK=20 Const KEY_HELP=47 Const KEY_NUMSLASH=108 Const KEY_START=93 Const KEY_NUMLOCK=144 Const KEY_SCROLL=145 Const KEY_BROWSER_BACK=166 Const KEY_BROWSER_FORWARD=167 Const KEY_BROWSER_REFRESH=168 Const KEY_BROWSER_STOP=169 Const KEY_BROWSER_SEARCH=170 Const KEY_BROWSER_FAVORITES=171 Const KEY_BROWSER_HOME=172 Const KEY_VOLUME_MUTE=173 Const KEY_VOLUME_DOWN=174 Const KEY_VOLUME_UP=175 Const KEY_MEDIA_NEXT_TRACK=176 Const KEY_MEDIA_PREV_TRACK=177 Const KEY_MEDIA_STOP=178 Const KEY_MEDIA_PLAY_PAUSE=179 Const KEY_LAUNCH_MAIL=180 Const KEY_LAUNCH_MEDIA_SELECT=181 Const KEY_LAUNCH_APP1=182 Const KEY_LAUNCH_APP2=183 End Rem commented out? NOTE: Their all sitting at the bottom of the source code. |
| ||
You'd use something like:SuperStrict Framework BRL.StandardIO Import BRL.PolledInput Import Pub.Win32 'Let's create a reference to the function (the user32.dll is imported using Pub.Win32 module) Extern "win32" Function GetAsyncKeyState%(vKey%) 'Get's the no of times the key has been pressed since last call EndExtern Repeat 'Loop until we hit shift and escape PollSystem() Until GetAsyncKeyState(KEY_ESCAPE|VK_SHIFT) 'VK_CONTROL, VK_MENU, VK_LWIN Print "Ending" EndBecause GetAsyncKeyState() is a Windows specific API function, you can't use the modifiers Blitz uses internally (though the normal keys are the same). The modifier constants the function interprets are VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN, VK_SHIFT which are already defined in Pub.Win32 module so you can use them straight away. Regarding the commenting of those additional constants, I assume it's because they haven't got them working the same cross-platform so are not supporting them for now. |
| ||
Regarding the commenting of those additional constants, I assume it's because they haven't got them working the same cross-platform so are not supporting them for now. Ohh, right, thanks. |
| ||
:-) That works, Thanks! |