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-07 16:15:03 +00:00
|
|
|
func alert() {
|
2017-07-02 03:52:37 +00:00
|
|
|
// show Alert Window
|
|
|
|
|
abool := robotgo.ShowAlert("hello", "robotgo")
|
2017-05-25 14:25:28 +00:00
|
|
|
if abool == 0 {
|
|
|
|
|
fmt.Println("ok@@@", "ok")
|
|
|
|
|
}
|
|
|
|
|
robotgo.ShowAlert("hello", "robotgo", "Ok", "Cancel")
|
|
|
|
|
|
2018-10-07 16:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func get() {
|
2017-07-02 03:52:37 +00:00
|
|
|
// get the current process id
|
|
|
|
|
pid := robotgo.GetPID()
|
2017-05-25 14:25:28 +00:00
|
|
|
fmt.Println("pid----", pid)
|
|
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// get current Window Active
|
|
|
|
|
mdata := robotgo.GetActive()
|
2017-05-25 14:25:28 +00:00
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// get current Window Handle
|
|
|
|
|
hwnd := robotgo.GetHandle()
|
2017-05-25 14:25:28 +00:00
|
|
|
fmt.Println("hwnd---", hwnd)
|
|
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// get current Window Handle
|
|
|
|
|
bhwnd := robotgo.GetBHandle()
|
2017-05-25 14:25:28 +00:00
|
|
|
fmt.Println("bhwnd---", bhwnd)
|
|
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// get current Window title
|
|
|
|
|
title := robotgo.GetTitle()
|
2017-05-25 14:25:28 +00:00
|
|
|
fmt.Println("title-----", title)
|
|
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// set Window Active
|
|
|
|
|
robotgo.SetActive(mdata)
|
2018-10-07 16:15:03 +00:00
|
|
|
}
|
2017-07-01 15:07:30 +00:00
|
|
|
|
2018-10-07 16:15:03 +00:00
|
|
|
func findIds() {
|
2017-07-02 03:52:37 +00:00
|
|
|
// find the process id by the process name
|
2017-07-01 15:07:30 +00:00
|
|
|
fpid, err := robotgo.FindIds("Google")
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Println("pids...", fpid)
|
2018-01-18 13:39:27 +00:00
|
|
|
if len(fpid) > 0 {
|
|
|
|
|
robotgo.ActivePID(fpid[0])
|
2018-02-03 09:42:38 +00:00
|
|
|
|
2018-08-23 14:49:39 +00:00
|
|
|
tl := robotgo.GetTitle(fpid[0])
|
|
|
|
|
fmt.Println("pid[0] title is: ", tl)
|
|
|
|
|
|
2018-08-16 12:46:29 +00:00
|
|
|
x, y, w, h := robotgo.GetBounds(fpid[0])
|
|
|
|
|
fmt.Println("GetBounds is: ", x, y, w, h)
|
|
|
|
|
|
2018-07-29 17:23:58 +00:00
|
|
|
// Windows
|
|
|
|
|
// hwnd := robotgo.FindWindow("google")
|
|
|
|
|
// hwnd := robotgo.GetHWND()
|
|
|
|
|
robotgo.MinWindow(fpid[0])
|
|
|
|
|
robotgo.MaxWindow(fpid[0])
|
2018-08-25 13:51:38 +00:00
|
|
|
robotgo.CloseWindow(fpid[0])
|
2018-07-29 17:23:58 +00:00
|
|
|
|
2018-02-03 09:42:38 +00:00
|
|
|
robotgo.Kill(fpid[0])
|
2018-01-18 13:39:27 +00:00
|
|
|
}
|
2017-07-01 15:07:30 +00:00
|
|
|
}
|
2018-10-07 16:15:03 +00:00
|
|
|
}
|
2017-07-01 15:07:30 +00:00
|
|
|
|
2020-04-07 15:30:29 +00:00
|
|
|
func active() {
|
|
|
|
|
robotgo.ActivePID(100)
|
|
|
|
|
// robotgo.Sleep(2)
|
|
|
|
|
robotgo.ActiveName("code")
|
|
|
|
|
robotgo.Sleep(1)
|
|
|
|
|
robotgo.ActiveName("chrome")
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 16:15:03 +00:00
|
|
|
func findName() {
|
|
|
|
|
// find the process name by the process id
|
|
|
|
|
name, err := robotgo.FindName(100)
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Println("name: ", name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// find the all process name
|
|
|
|
|
names, err := robotgo.FindNames()
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Println("name: ", names)
|
|
|
|
|
}
|
2019-05-13 13:59:13 +00:00
|
|
|
|
|
|
|
|
p, err := robotgo.FindPath(100)
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Println("path: ", p)
|
|
|
|
|
}
|
2018-10-07 16:15:03 +00:00
|
|
|
}
|
2018-01-18 13:39:27 +00:00
|
|
|
|
2018-10-07 16:15:03 +00:00
|
|
|
func ps() {
|
2017-07-02 03:52:37 +00:00
|
|
|
// determine whether the process exists
|
2017-07-01 15:07:30 +00:00
|
|
|
isExist, err := robotgo.PidExists(100)
|
2018-02-03 09:42:38 +00:00
|
|
|
if err == nil && isExist {
|
2017-07-01 15:07:30 +00:00
|
|
|
fmt.Println("pid exists is", isExist)
|
2018-02-03 09:42:38 +00:00
|
|
|
|
|
|
|
|
robotgo.Kill(100)
|
2017-07-01 15:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// get the all process id
|
2017-07-01 15:07:30 +00:00
|
|
|
pids, err := robotgo.Pids()
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Println("pids: ", pids)
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-02 03:52:37 +00:00
|
|
|
// get the all process struct
|
2017-07-01 15:07:30 +00:00
|
|
|
ps, err := robotgo.Process()
|
|
|
|
|
if err == nil {
|
|
|
|
|
fmt.Println("process: ", ps)
|
|
|
|
|
}
|
2018-10-07 16:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func window() {
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Window Handle
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
alert()
|
2020-04-07 15:30:29 +00:00
|
|
|
//
|
2018-10-07 16:15:03 +00:00
|
|
|
get()
|
|
|
|
|
|
|
|
|
|
findIds()
|
2020-04-07 15:30:29 +00:00
|
|
|
active()
|
2018-10-07 16:15:03 +00:00
|
|
|
|
|
|
|
|
findName()
|
2020-04-07 15:30:29 +00:00
|
|
|
//
|
2018-10-07 16:15:03 +00:00
|
|
|
ps()
|
2017-07-02 04:31:58 +00:00
|
|
|
|
|
|
|
|
// close current Window
|
|
|
|
|
robotgo.CloseWindow()
|
2017-05-25 14:25:28 +00:00
|
|
|
}
|
2018-07-13 11:23:09 +00:00
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
window()
|
|
|
|
|
}
|