Quit

I have a window with multiple control etc and on keydown for any of them I set a Quit to end the app. I do this because I do not know which control has the focus.

This works great on the mac. On windows it works just after starting the app but once its running it does not work.

Any suggestions to overcome this?

Thanks.

It is possible that no control has focus, in which case you may need to trap it in the Window KeyDown event.

I’d think you would only need to trap it in the Window KeyDown event.

Well by clicking on anything window or control still does not seem to set the focus to anything so that the event fires and the app quits.

I agree it should be the window only but I think my earlier testing proved that putting it in all of the controls seemed to fix it. At least I though it would.

How would I trap something in the keydown event?

Not sure what is meant by that?

Thanks.

wouldn’t it be more “graceful” to instead of “QUIT” issue a “self.close” and set APP.AutoQUit=TRue?

Well Dave I did that as you posted something similar in another thread. I set the autoquit to true and do a self.close but it doesnt seem to work on windows.

Then you have something else holding open or reopening a window…

To me “QUIT” is like yanking the power cord out of the wall…

Be sure to set app.autoquit=true in the APP.OPEN event before anything else…

I have used this on Mac and Windows both with no issues… it is the more graceful (and in my opinion) more proper way to exit

You add the KeyDown event to the Window, then put your code in there, the same as you did for your controls. In fact, if all the control behave the same way, you should need the event in the controls at all.

The way that event works, it is sent to the control with focus first. If that control returns True in KeyDown, that’s it. If it returns false, the event moves up the chain to the Window. If that returns True, that’s it, otherwise it’s sent up the chain.

So I did Dave’s suggestion and removed all other keydown events from all controls but the window. I do a self.close on the keydown event there. Again, on windows and windows only, once the app starts(which uses a couple of canvases to show some images at different times from a timer) then the event does not seem to work. On the mac it does not matter where you are in the app while it is running but on windows it only works right after start up, one your running forget it.

[quote=82467:@Tom Russell]I have a window with multiple control etc and on keydown for any of them I set a Quit to end the app. I do this because I do not know which control has the focus.

This works great on the mac. On windows it works just after starting the app but once its running it does not work.[/quote]

If you want to detect if a key was pressed and take action without using the KeyDown event in every control, add a timer to your app with a short period like 100 and place this in the Action event :

for i as integer = 0 to &hff If Keyboard.AsynckeyDown(i) then //do something with this key here beep end if next i

I placed beep ; you can put your quit there.

But am curious : do you really quit if any key is entered ?

Thanks, I will try that. No its not just any key but the minus key only.

On Windows, TextField and TextArea consume the key whether you return true or not. It never goes to the window.

Even if it’s a control key?

[quote=82502:@Michel Bujardet]If you want to detect if a key was pressed and take action without using the KeyDown event in every control, add a timer to your app with a short period like 100 and place this in the Action event :

for i as integer = 0 to &hff If Keyboard.AsynckeyDown(i) then //do something with this key here beep end if next i

I placed beep ; you can put your quit there.

But am curious : do you really quit if any key is entered ?[/quote]

I tried this but for whatever reason xojo freezes up when I set a breakpoint to see what key is pressed. If I unset the breakpoint it runs fine. However the code never seems to get called.

xojo is getting worse the more I use it. Id rather go back to the older realstudio for real work. Or its just bad luck for me.

Yes. Alt-key seqences go through the menu system, of course.

This quits if either the minus key from alphanumeric or numeric keypad is punched.

If Keyboard.AsynckeyDown(&h1B) or Keyboard.AsynckeyDown(&h4E) then //do something with this key here quit end if

Now you have the proper keys on the US keyboard set.

See the documentation for the codes :
http://documentation.xojo.com/index.php/Keyboard

You do not need to place a breakpoint to see what is the code of a particular key. Just modify the code I originally posted :

for i as integer = 0 to &hff If Keyboard.AsynckeyDown(i) then //do something with this key here msgbox(Hex(i)) exit end if next i

But where did you place the code ? Did you use a timer as I told you ? If you place it in a timer, it gets called no matter what… Make sure to set the timer period to 100 or less.

Xojo or RS will react the same in this instance…