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=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
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.