robotgo/examples/mouse/main.go

101 lines
2 KiB
Go
Raw Permalink Normal View History

// Copyright (c) 2016-2025 AtomAI, All rights reserved.
//
// See the COPYRIGHT file at the top-level directory of this distribution and at
2017-05-25 14:25:28 +00:00
// 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>
//
// This file may not be copied, modified, or distributed
2017-05-25 14:25:28 +00:00
// 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() {
2021-10-18 16:43:34 +00:00
robotgo.MouseSleep = 100
2018-10-08 16:21:23 +00:00
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
2021-10-18 16:43:34 +00:00
robotgo.Move(100, 200)
2017-07-02 03:52:37 +00:00
2022-04-14 15:57:09 +00:00
// drag mouse with smooth
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)
2021-11-24 19:49:00 +00:00
robotgo.MoveSmooth(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 {
2022-04-14 15:57:09 +00:00
fmt.Println("i: ", i)
2021-10-18 16:43:34 +00:00
// MoveMouse(800, i)
robotgo.Move(800, i)
2018-10-08 16:21:23 +00:00
}
}
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
2021-10-18 16:43:34 +00:00
robotgo.Click("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.Location()
2017-05-25 14:25:28 +00:00
fmt.Println("pos:", x, y)
if x == 456 && y == 586 {
fmt.Println("mouse...", "586")
}
2021-10-18 16:43:34 +00:00
robotgo.Move(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.ScrollDir(10, "up")
robotgo.ScrollDir(10, "right")
2021-11-24 19:49:00 +00:00
robotgo.Scroll(100, 10)
robotgo.Scroll(0, -10)
2018-10-08 16:21:23 +00:00
2022-04-14 15:57:09 +00:00
robotgo.Toggle("left")
robotgo.Toggle("left", "up")
2021-11-24 19:49:00 +00:00
// toggles the right mouse button
robotgo.Toggle("right")
robotgo.Toggle("right", "up")
2018-10-08 16:21:23 +00:00
}
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()
}