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.
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.
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.
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 ?
[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.
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.