I use Window.KeyUp event to detect key events, but as described in http://documentation.xojo.com/index.php/Window.KeyUp this is only fired when the window has the focus. Is there any ‘global’ key event for an app? And only for the app, I don’t want to write a key logger Searched a lot without success.
Sub Timer_Action(sender As Timer)
If Keyboard.AsyncKeyDown(&h7B) Then
// left arrow was pressed
End
End Sub
Have a look at the other properties of the Keyboard module.
TheTimer.Period = 0 has always worked for this specific case in my projects, but I think it is a bit of a hack, since it just magically “steals” the event from the control currently having the focus.
Keyboard navigation for an information screen in a company.
There is a PagePanel with several panels (calendar, tasks, project overview,…) and a ultra small keyboard. So user can switch panels with the keyboard.
If you have a menubar, it would be better to add menu items under the “View” menu for it. At least on OS X all special key combinations should have a corresponding menu item.
That’s what I thought too, and as I couldn’t come up with another usage scenario I was puzzled as to how this can be used. Urs explained it. If you know of other usage scenarios then please let us know.
Problem: pressed key is called multiple times in a blink because of Timer.Period = 0.
When I higher the timer period I don’t get always the pressed button. I guess this is because sometimes the control with the actual focus receives the pressed key and App misses the pressed key.
So I implement a timeout. Did this by comparing ticks of the last time a button was pressed:
Add property pLastPressedKeyTicks to App.
In App.Open()
pLastPressedKeyTicks = Ticks
Sub Timer_Action(sender As Timer)
If Keyboard.AsyncKeyDown(&h7C) then
'right arrow key
HandlePressedKey(&h7C)
end if
End Sub
End Sub
[code]Sub HandlePressedKey(key As Integer)
Dim now As Date = New Date
If Int32(Ticks - pLastPressedKeyTicks) > 10 Then
pLastPressedKeyTicks = Ticks
WinMain.KeyPressed(key)
End If
End Sub[/code]
That was my first thought. A bit like an RS latch to eliminate the bouncing of switches.
But the user can press the button (e.g. down arrow) repeatedly or hold down to scroll through all pages.
I would change the timer period on key detect and then change it back the next time the timer fires (if no key detect). No need to have the timer firing in the interim.