-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_event.go
66 lines (52 loc) · 1.31 KB
/
key_event.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
package bus
import (
"unicode"
"golang.org/x/mobile/event/key"
)
func NewKeyEvent(key key.Event) KeyEvent {
return &keyEvent{key}
}
func NewKeyRegistrationEvent(keys []rune) KeysRegistrationEvent {
return &keysRegistrationEvent{keys}
}
type KeysRegistrationEventListener interface {
OnKeyRegistrationEvent(keyRegistrationChannel <-chan KeysRegistrationEvent)
}
type KeyEventListener interface {
OnKeyEvent(keyChannel <-chan KeyEvent)
}
// ////////////////////////////////////////////////////////////////////
type KeysRegistrationEvent interface {
GetRunes() []rune
}
type keysRegistrationEvent struct {
runes []rune
}
func (k *keysRegistrationEvent) GetRunes() []rune {
return k.runes
}
type KeyEvent interface {
ToRune() rune
Equals(keyRune rune) bool
EqualsIgnoreCase(keyRune rune) bool
IsPressed() bool
IsReleased() bool
}
func (k *keyEvent) IsPressed() bool {
return k.key.Direction == key.DirPress
}
func (k *keyEvent) IsReleased() bool {
return k.key.Direction == key.DirRelease
}
type keyEvent struct {
key key.Event
}
func (k *keyEvent) ToRune() rune {
return k.key.Rune
}
func (k *keyEvent) EqualsIgnoreCase(keyRune rune) bool {
return k.key.Rune == unicode.ToLower(keyRune) || k.key.Rune == unicode.ToUpper(keyRune)
}
func (k *keyEvent) Equals(keyRune rune) bool {
return k.key.Rune == keyRune
}