diff options
| author | Lenni <[email protected]> | 2021-03-03 19:04:54 +0100 |
|---|---|---|
| committer | Lenni <[email protected]> | 2021-03-03 19:04:54 +0100 |
| commit | 4c1bf8cd8d4f0f96428a90f3117896c7f1564cdf (patch) | |
| tree | 9b727b72834e46efcf5ac4aa2ec9b9250b77bdb6 /examples/create-window/main.go | |
| parent | 2a6cba9c3c2e3d2ea720099b61b39669ff6b7474 (diff) | |
added listening to key presses
Diffstat (limited to 'examples/create-window/main.go')
| -rw-r--r-- | examples/create-window/main.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/examples/create-window/main.go b/examples/create-window/main.go index 284daef..76df734 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -110,6 +110,16 @@ func main() { // xproto.ChangeWindowAttributes (see l.50)). // and reacts to it accordingly. All events are defined in the xproto subpackage. switch ev.(type) { + case xproto.KeyPressEvent: + // See https://pkg.go.dev/github.com/jezek/[email protected]/xproto#KeyPressEvent + // for documentation about a key press event. + kpe := ev.(xproto.KeyPressEvent) + fmt.Printf("Key pressed: %d", kpe.Detail) + // The Detail value depends on the keyboard layout, + // for QWERTY, q is #24. + if kpe.Detail == 24 { + return // exit on q + } case xproto.DestroyNotifyEvent: return // Exit if we get a DestroyNotifyEvent. } |
