generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
keyboard_test.go
55 lines (47 loc) · 1.15 KB
/
keyboard_test.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
49
50
51
52
53
54
55
package keyboard_test
import (
"testing"
"atomicgo.dev/keyboard"
"atomicgo.dev/keyboard/keys"
"github.com/MarvinJWendt/testza"
)
func TestMocking(t *testing.T) {
go func() {
keyboard.SimulateKeyPress('a')
keyboard.SimulateKeyPress("b")
keyboard.SimulateKeyPress("c")
keyboard.SimulateKeyPress(keys.Enter)
}()
var aPressed, bPressed, cPressed, enterPressed bool
var keyList []keys.Key
err := keyboard.Listen(func(key keys.Key) (stop bool, err error) {
keyList = append(keyList, key)
switch key.Code {
case keys.RuneKey:
switch key.String() {
case "a":
println("a pressed")
aPressed = true
return false, nil
case "b":
println("b pressed")
bPressed = true
return false, nil
case "c":
println("c pressed")
cPressed = true
return false, nil
}
case keys.Enter:
println("enter pressed")
enterPressed = true
return true, nil
}
return false, nil
})
testza.AssertNoError(t, err)
testza.AssertTrue(t, aPressed, "A | %s", keyList)
testza.AssertTrue(t, bPressed, "B | %s", keyList)
testza.AssertTrue(t, cPressed, "C | %s", keyList)
testza.AssertTrue(t, enterPressed, "Enter | %s", keyList)
}