-
Notifications
You must be signed in to change notification settings - Fork 0
/
example4.go
48 lines (43 loc) · 864 Bytes
/
example4.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"time"
"github.com/zetamatta/go-console/getch"
)
func main() {
time.Sleep(time.Second / 10)
getch.Flush()
// wait keyboard-event (timeout: 10-seconds)
ok, err := getch.Wait(10000)
if err != nil {
fmt.Println(err.Error())
return
}
if !ok {
fmt.Println("Time-out")
return
}
// get console event
e := getch.All()
if k := e.Key; k != nil {
fmt.Printf("key down: code=%04X scan=%04X shift=%04X\n",
k.Rune, k.Scan, k.Shift)
}
if k := e.KeyUp; k != nil {
fmt.Printf("key up: code=%04X scan=%04X shift=%04X\n",
k.Rune, k.Scan, k.Shift)
}
if r := e.Resize; r != nil {
fmt.Printf("window resize: width=%d height=%d\n",
r.Width, r.Height)
}
if e.Mouse != nil {
fmt.Println("mouse event")
}
if e.Menu != nil {
fmt.Println("menu event")
}
if e.Focus != nil {
fmt.Println("focus event")
}
}