robotgo/examples/mouse/main.go

95 lines
1.9 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"
)
2018-10-08 16:21:23 +00:00
func move() {
robotgo.Move(100, 200)
robotgo.MoveRelative(10, -200)
2017-05-25 14:25:28 +00:00
2017-07-02 03:52:37 +00:00
// move the mouse to 100, 200
robotgo.MoveMouse(100, 200)
2018-12-27 23:09:14 +00:00
robotgo.Drag(10, 10)
robotgo.Drag(20, 20, "right")
2019-06-09 18:06:23 +00:00
//
robotgo.DragSmooth(10, 10)
robotgo.DragSmooth(100, 200, 1.0, 100.0)
2018-12-27 23:09:14 +00:00
2018-10-08 16:21:23 +00:00
// smooth move the mouse to 100, 200
robotgo.MoveSmooth(100, 200)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
robotgo.MoveSmoothRelative(10, -100, 1.0, 30.0)
2018-10-08 16:21:23 +00:00
for i := 0; i < 1080; i += 1000 {
fmt.Println(i)
robotgo.MoveMouse(800, i)
}
}
func click() {
2017-07-02 03:52:37 +00:00
// click the left mouse button
2018-10-08 16:21:23 +00:00
robotgo.Click()
2018-12-27 23:09:14 +00:00
2017-07-02 03:52:37 +00:00
// click the right mouse button
2018-10-08 16:21:23 +00:00
robotgo.Click("right", false)
2018-12-27 23:09:14 +00:00
2017-07-02 03:52:37 +00:00
// double click the left mouse button
robotgo.MouseClick("left", true)
2018-10-08 16:21:23 +00:00
}
2017-05-25 14:25:28 +00:00
2018-10-08 16:21:23 +00:00
func get() {
2017-07-02 03:52:37 +00:00
// gets the mouse coordinates
x, y := robotgo.GetMousePos()
2017-05-25 14:25:28 +00:00
fmt.Println("pos:", x, y)
if x == 456 && y == 586 {
fmt.Println("mouse...", "586")
}
robotgo.MoveMouse(x, y)
2018-10-08 16:21:23 +00:00
}
2017-05-25 14:25:28 +00:00
2018-10-08 16:21:23 +00:00
func toggleAndScroll() {
// scrolls the mouse either up
robotgo.ScrollMouse(10, "up")
robotgo.Scroll(100, 200)
// toggles right mouse button
robotgo.MouseToggle("down", "right")
robotgo.MouseToggle("up")
}
func mouse() {
////////////////////////////////////////////////////////////////////////////////
// Control the mouse
////////////////////////////////////////////////////////////////////////////////
move()
click()
get()
2017-07-02 03:52:37 +00:00
2018-10-08 16:21:23 +00:00
toggleAndScroll()
2017-05-25 14:25:28 +00:00
}
2018-07-13 11:23:09 +00:00
func main() {
mouse()
}