-
Notifications
You must be signed in to change notification settings - Fork 887
/
main.go
72 lines (60 loc) · 1.87 KB
/
main.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
69
70
71
72
// Copyright 2016 The cauefcr Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/cauefcr/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
hook "github.com/robotn/gohook"
)
func addEvent() {
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
robotgo.EventHook(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
fmt.Println("ctrl-shift-q")
robotgo.EventEnd()
})
fmt.Println("--- Please press w---")
robotgo.EventHook(hook.KeyDown, []string{"w"}, func(e hook.Event) {
fmt.Println("w")
})
s := robotgo.EventStart()
<-robotgo.EventProcess(s)
}
func addMouse() {
fmt.Println("--- Please press left mouse button to see it's position and the right mouse button to exit ---")
robotgo.EventHook(hook.MouseDown, []string{}, func(e hook.Event) {
if e.Button == hook.MouseMap["left"] {
fmt.Printf("mouse left @ %v - %v\n", e.X, e.Y)
} else if e.Button == hook.MouseMap["right"] {
robotgo.EventEnd()
}
})
s := robotgo.EventStart()
<-robotgo.EventProcess(s)
}
func lowLevel() {
////////////////////////////////////////////////////////////////////////////////
// Global event listener
////////////////////////////////////////////////////////////////////////////////
fmt.Println("Press q to stop event gathering")
evChan := robotgo.EventStart()
for e := range evChan {
fmt.Println(e)
if e.Keychar == 'q' {
robotgo.EventEnd()
// break
}
}
}
func main() {
fmt.Println("test begin...")
addEvent()
addMouse()
lowLevel()
}