Good news on this one - Windows now have KeyDown and KeyUp events. The change is implemented and will ship in the next Objo Studio release.
A window's key handlers are fallbacks, matching how Xojo's DesktopWindow behaves: the focused control always sees a key first. If a control handles it (e.g. a TextField receiving typed text, or a control whose own KeyDown handler returns True) the window events don't fire. Any key that nothing else handles reaches the window:
Event KeyDown(keyName As String) As Boolean
If keyName = "F5" Then
ReloadData()
Return True
End If
Return False
End Event
Return True from KeyDown to mark the key as handled and stop further processing of it. KeyUp(keyName As String) fires on release for keys nothing else handled.
Two notes for your original scenario:
- ScrollBox keeps no key events of its own - containers deliberately don't have any. But this covers the use case: keys pressed inside a ScrollBox that its content doesn't handle bubble up to the window's
KeyDown/KeyUp. A scrolling window now catches keystrokes directly, with no full-window Canvas trick needed.
- For held-key polling (your
AsyncKeyDown question): the Keyboard module is the equivalent. Keyboard.IsKeyDown("W") reports whether a key is currently held, Keyboard.IsPhysicalKeyDown(...) works by physical key regardless of layout, and ShiftDown/ControlDown/AltDown/CommandDown report the modifiers. Poll those from a Timer when you need held state; use the new window events to react to presses.
The old Canvas workaround still works, of course - it's just no longer necessary simply to receive keystrokes.