-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpredicates.go
More file actions
36 lines (30 loc) · 924 Bytes
/
Copy pathpredicates.go
File metadata and controls
36 lines (30 loc) · 924 Bytes
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
package gowinkey
// Predicate represents a filter for key events.
type Predicate func(event KeyEvent) bool
// Selective returns a Predicate allowing only
// events for the given virtual keys to pass.
func Selective(keys ...VirtualKey) Predicate {
set := NewKeySet(keys...)
return func(event KeyEvent) bool {
return set.Contains(event.VirtualKey)
}
}
// KeyboardOnly is a Predicate allowing only
// events for keys on the keyboard to pass.
func KeyboardOnly(event KeyEvent) bool {
switch event.VirtualKey {
case VK_LBUTTON, VK_RBUTTON, VK_MBUTTON, VK_XBUTTON1, VK_XBUTTON2:
return false
}
return true
}
// PressedOnly is a Predicate allowing
// only events for key presses to pass.
func PressedOnly(event KeyEvent) bool {
return event.State == KeyDown
}
// ReleasedOnly is a Predicate allowing
// only events for key releases to pass.
func ReleasedOnly(event KeyEvent) bool {
return event.State == KeyUp
}