Closed matthewr6 closed 8 years ago
Creating a keyboard.NewWatcher()
doesn't do what you want. It initializes a watcher, but it's not actually going to have its state ever changed (it's a virtual keyboard).
You want to get the watcher from the window, i.e. window.Keyboard().Down(keyboard.Enter)
because that keyboard watcher will have its state updated (based on window events).
Oh, ok... Is there any way to have a watcher without having a new window? (I've been searching for a way to have Go get the keyboard's state and/or listen for keyboard events and this has seemed like the best solution so far)
No; in fact many OSs do not even support getting keyboard events without talking to a window.
That said, you don't need to have a visible window 😉 This example (just take out all the fmt
calls) shows basically what you want: https://github.com/azul3d/examples/blob/master/azul3d_info/azul3d_info.go
Thanks, I'll check that out :)
Hey @slimsag,
I've been trying unsuccessfully to use the example you linked above. I think that the only way to capture keyboard events is for the window to be in focus, which I don't suppose is possible for an non-visible window.
On Windows 10, x64
The loop never exits even if I do hit enter. This is the same for
keyboard.A
and other keys that I've tested. Assume AnimateUntilDone is being called correctly.