robotgo/examples/window/main.go
2018-07-13 19:23:09 +08:00

106 lines
2.3 KiB
Go

// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// 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"
)
func window() {
////////////////////////////////////////////////////////////////////////////////
// Window Handle
////////////////////////////////////////////////////////////////////////////////
// show Alert Window
abool := robotgo.ShowAlert("hello", "robotgo")
if abool == 0 {
fmt.Println("ok@@@", "ok")
}
robotgo.ShowAlert("hello", "robotgo", "Ok", "Cancel")
// get the current process id
pid := robotgo.GetPID()
fmt.Println("pid----", pid)
// get current Window Active
mdata := robotgo.GetActive()
// get current Window Handle
hwnd := robotgo.GetHandle()
fmt.Println("hwnd---", hwnd)
// get current Window Handle
bhwnd := robotgo.GetBHandle()
fmt.Println("bhwnd---", bhwnd)
// get current Window title
title := robotgo.GetTitle()
fmt.Println("title-----", title)
// set Window Active
robotgo.SetActive(mdata)
// find the process id by the process name
fpid, err := robotgo.FindIds("Google")
if err == nil {
fmt.Println("pids...", fpid)
if len(fpid) > 0 {
robotgo.ActivePID(fpid[0])
robotgo.Kill(fpid[0])
}
}
robotgo.ActiveName("chrome")
// determine whether the process exists
isExist, err := robotgo.PidExists(100)
if err == nil && isExist {
fmt.Println("pid exists is", isExist)
robotgo.Kill(100)
}
// get the all process id
pids, err := robotgo.Pids()
if err == nil {
fmt.Println("pids: ", pids)
}
// 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)
}
// get the all process struct
ps, err := robotgo.Process()
if err == nil {
fmt.Println("process: ", ps)
}
// close current Window
robotgo.CloseWindow()
}
func main() {
window()
}