robotgo/examples/event/main.go

115 lines
2.4 KiB
Go
Raw Permalink Normal View History

2018-02-01 16:07:44 +00:00
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
2017-05-25 14:25:28 +00:00
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/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"
// "go-vgo/robotgo"
)
2019-02-22 12:50:56 +00:00
func addEvent() {
fmt.Println("--- Please press ctrl + shift + q ---")
2019-02-22 12:50:56 +00:00
ok := robotgo.AddEvents("q", "ctrl", "shift")
if ok {
fmt.Println("add events...")
}
fmt.Println("--- Please press w---")
2019-02-22 12:50:56 +00:00
ok = robotgo.AddEvents("w")
if ok {
fmt.Println("add events")
}
2019-03-04 15:33:52 +00:00
// start hook
2019-02-22 12:50:56 +00:00
s := robotgo.Start()
2019-03-04 15:33:52 +00:00
// end hook
2019-02-22 12:50:56 +00:00
defer robotgo.End()
for ev := range s {
2019-06-23 13:45:52 +00:00
fmt.Println("hook: ", ev)
2019-02-22 12:50:56 +00:00
}
}
2019-03-08 14:09:16 +00:00
func addMouse() {
fmt.Println("--- Please press left mouse button ---")
ok := robotgo.AddMouse("left")
if ok {
fmt.Println("add mouse...")
}
fmt.Println("--- Please press left mouse button and move mosue to 100,100 ---")
ok = robotgo.AddMouse("left", 100, 100)
if ok {
fmt.Println("add mouse and move to 100,100 ...")
2019-03-09 12:58:54 +00:00
}
fmt.Println("--- Please move mosue to 100,100 ---")
ok = robotgo.AddMousePos(100, 100)
if ok {
fmt.Println(" move mouse to 100,100 ...")
2019-03-08 14:09:16 +00:00
}
}
func add() {
2017-05-25 14:25:28 +00:00
fmt.Println("--- Please press v---")
eve := robotgo.AddEvent("v")
if eve {
2017-05-25 14:25:28 +00:00
fmt.Println("--- You press v---", "v")
}
fmt.Println("--- Please press k---")
keve := robotgo.AddEvent("k")
if keve {
2017-05-25 14:25:28 +00:00
fmt.Println("--- You press k---", "k")
}
fmt.Println("--- Please press f1---")
feve := robotgo.AddEvent("f1")
if feve {
2017-05-25 14:25:28 +00:00
fmt.Println("You press...", "f1")
}
}
func event() {
////////////////////////////////////////////////////////////////////////////////
// Global event listener
////////////////////////////////////////////////////////////////////////////////
add()
2017-05-25 14:25:28 +00:00
fmt.Println("--- Please press left mouse button---")
mleft := robotgo.AddEvent("mleft")
if mleft {
2017-05-25 14:25:28 +00:00
fmt.Println("--- You press left mouse button---", "mleft")
}
mright := robotgo.AddEvent("mright")
if mright {
2017-05-25 14:25:28 +00:00
fmt.Println("--- You press right mouse button---", "mright")
}
2017-07-02 03:52:37 +00:00
// stop AddEvent
2017-05-25 14:25:28 +00:00
// robotgo.StopEvent()
}
2018-07-13 11:23:09 +00:00
func main() {
fmt.Println("test begin...")
2019-02-22 12:50:56 +00:00
addEvent()
2019-03-08 14:09:16 +00:00
addMouse()
2018-07-13 11:23:09 +00:00
event()
}