azul3d / engine

Azul3D - A 3D game engine written in Go!
https://azul3d.org
Other
606 stars 54 forks source link

Keyboard watcher not receiving keyboard input? #161

Closed matthewr6 closed 8 years ago

matthewr6 commented 8 years ago

On Windows 10, x64

watcher := keyboard.NewWatcher()
myNet.AnimateUntilDone(watcher)

func (net *Network) AnimateUntilDone(watcher *keyboard.Watcher) {
    os.Mkdir("frames", 755)
    exit := false
    for !exit {
        fmt.Println(watcher.States())
        exit = watcher.Down(keyboard.Enter)
    }
}

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.

slimsag commented 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).

matthewr6 commented 8 years ago

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)

slimsag commented 8 years ago

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

matthewr6 commented 8 years ago

Thanks, I'll check that out :)

rikonor commented 8 years ago

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.