mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 06:33:56 +00:00
move gops code to ps.go
This commit is contained in:
parent
5485466381
commit
c7ce55023a
72
ps.go
Normal file
72
ps.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// 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 robotgo
|
||||||
|
|
||||||
|
import ps "github.com/vcaesar/gops"
|
||||||
|
|
||||||
|
// Nps process struct
|
||||||
|
type Nps struct {
|
||||||
|
Pid int32
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pids get the all process id
|
||||||
|
func Pids() ([]int32, error) {
|
||||||
|
return ps.Pids()
|
||||||
|
}
|
||||||
|
|
||||||
|
// PidExists determine whether the process exists
|
||||||
|
func PidExists(pid int32) (bool, error) {
|
||||||
|
return ps.PidExists(pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process get the all process struct
|
||||||
|
func Process() ([]Nps, error) {
|
||||||
|
var npsArr []Nps
|
||||||
|
nps, err := ps.Process()
|
||||||
|
for i := 0; i < len(nps); i++ {
|
||||||
|
np := Nps{
|
||||||
|
nps[i].Pid,
|
||||||
|
nps[i].Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
npsArr = append(npsArr, np)
|
||||||
|
}
|
||||||
|
|
||||||
|
return npsArr, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindName find the process name by the process id
|
||||||
|
func FindName(pid int32) (string, error) {
|
||||||
|
return ps.FindName(pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindNames find the all process name
|
||||||
|
func FindNames() ([]string, error) {
|
||||||
|
return ps.FindNames()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindIds finds the all processes named with a subset
|
||||||
|
// of "name" (case insensitive),
|
||||||
|
// return matched IDs.
|
||||||
|
func FindIds(name string) ([]int32, error) {
|
||||||
|
return ps.FindIds(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindPath find the process path by the process pid
|
||||||
|
func FindPath(pid int32) (string, error) {
|
||||||
|
return ps.FindPath(pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kill kill the process by PID
|
||||||
|
func Kill(pid int32) error {
|
||||||
|
return ps.Kill(pid)
|
||||||
|
}
|
60
robotgo.go
60
robotgo.go
@ -63,7 +63,6 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/go-vgo/robotgo/clipboard"
|
"github.com/go-vgo/robotgo/clipboard"
|
||||||
ps "github.com/vcaesar/gops"
|
|
||||||
"github.com/vcaesar/imgo"
|
"github.com/vcaesar/imgo"
|
||||||
"github.com/vcaesar/tt"
|
"github.com/vcaesar/tt"
|
||||||
)
|
)
|
||||||
@ -1512,66 +1511,12 @@ func internalGetBounds(pid int32, hwnd int) (int, int, int, int) {
|
|||||||
return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H)
|
return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pids get the all process id
|
|
||||||
func Pids() ([]int32, error) {
|
|
||||||
return ps.Pids()
|
|
||||||
}
|
|
||||||
|
|
||||||
// PidExists determine whether the process exists
|
|
||||||
func PidExists(pid int32) (bool, error) {
|
|
||||||
return ps.PidExists(pid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is64Bit determine whether the sys is 64bit
|
// Is64Bit determine whether the sys is 64bit
|
||||||
func Is64Bit() bool {
|
func Is64Bit() bool {
|
||||||
b := C.Is64Bit()
|
b := C.Is64Bit()
|
||||||
return bool(b)
|
return bool(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nps process struct
|
|
||||||
type Nps struct {
|
|
||||||
Pid int32
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process get the all process struct
|
|
||||||
func Process() ([]Nps, error) {
|
|
||||||
var npsArr []Nps
|
|
||||||
nps, err := ps.Process()
|
|
||||||
for i := 0; i < len(nps); i++ {
|
|
||||||
np := Nps{
|
|
||||||
nps[i].Pid,
|
|
||||||
nps[i].Name,
|
|
||||||
}
|
|
||||||
|
|
||||||
npsArr = append(npsArr, np)
|
|
||||||
}
|
|
||||||
|
|
||||||
return npsArr, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindName find the process name by the process id
|
|
||||||
func FindName(pid int32) (string, error) {
|
|
||||||
return ps.FindName(pid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindNames find the all process name
|
|
||||||
func FindNames() ([]string, error) {
|
|
||||||
return ps.FindNames()
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindIds finds the all processes named with a subset
|
|
||||||
// of "name" (case insensitive),
|
|
||||||
// return matched IDs.
|
|
||||||
func FindIds(name string) ([]int32, error) {
|
|
||||||
return ps.FindIds(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindPath find the process path by the process pid
|
|
||||||
func FindPath(pid int32) (string, error) {
|
|
||||||
return ps.FindPath(pid)
|
|
||||||
}
|
|
||||||
|
|
||||||
func internalActive(pid int32, hwnd int) {
|
func internalActive(pid int32, hwnd int) {
|
||||||
C.active_PID(C.uintptr(pid), C.uintptr(hwnd))
|
C.active_PID(C.uintptr(pid), C.uintptr(hwnd))
|
||||||
}
|
}
|
||||||
@ -1596,8 +1541,3 @@ func ActiveName(name string) error {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill kill the process by PID
|
|
||||||
func Kill(pid int32) error {
|
|
||||||
return ps.Kill(pid)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user