-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
hotkey_darwin_test.go
68 lines (60 loc) · 1.41 KB
/
hotkey_darwin_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
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2021 The golang.design Initiative Authors.
// All rights reserved. Use of this source code is governed
// by a MIT license that can be found in the LICENSE file.
//
// Written by Changkun Ou <changkun.de>
//go:build darwin && cgo
package hotkey_test
import (
"context"
"fmt"
"testing"
"time"
"golang.design/x/hotkey"
)
// TestHotkey should always run success.
// This is a test to run and for manually testing the registration of multiple
// hotkeys. Registered hotkeys:
// Ctrl+Shift+S
// Ctrl+Option+S
func TestHotkey(t *testing.T) {
tt := time.Second * 5
done := make(chan struct{}, 2)
ctx, cancel := context.WithTimeout(context.Background(), tt)
go func() {
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS)
if err := hk.Register(); err != nil {
t.Errorf("failed to register hotkey: %v", err)
return
}
for {
select {
case <-ctx.Done():
cancel()
done <- struct{}{}
return
case <-hk.Keydown():
fmt.Println("triggered ctrl+shift+s")
}
}
}()
go func() {
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModOption}, hotkey.KeyS)
if err := hk.Register(); err != nil {
t.Errorf("failed to register hotkey: %v", err)
return
}
for {
select {
case <-ctx.Done():
cancel()
done <- struct{}{}
return
case <-hk.Keydown():
fmt.Println("triggered ctrl+option+s")
}
}
}()
<-done
<-done
}