diff --git a/README.md b/README.md index 826718d..cd6394d 100644 --- a/README.md +++ b/README.md @@ -237,14 +237,18 @@ func main() { if len(fpid) > 0 { robotgo.ActivePID(fpid[0]) + + robotgo.Kill(fpid[0]) } } robotgo.ActiveName("chrome") isExist, err := robotgo.PidExists(100) - if err == nil { + if err == nil && isExist { fmt.Println("pid exists is", isExist) + + robotgo.Kill(100) } abool := robotgo.ShowAlert("test", "robotgo") diff --git a/README_zh.md b/README_zh.md index 5d8210a..b16851e 100644 --- a/README_zh.md +++ b/README_zh.md @@ -235,14 +235,18 @@ func main() { if len(fpid) > 0 { robotgo.ActivePID(fpid[0]) + + robotgo.Kill(fpid[0]) } } robotgo.ActiveName("chrome") isExist, err := robotgo.PidExists(100) - if err == nil { + if err == nil && isExist { fmt.Println("pid exists is", isExist) + + robotgo.Kill(100) } abool := robotgo.ShowAlert("test", "robotgo") diff --git a/examples/main.go b/examples/main.go index f95fad8..5f28948 100644 --- a/examples/main.go +++ b/examples/main.go @@ -308,6 +308,8 @@ func window() { fmt.Println("pids...", fpid) if len(fpid) > 0 { robotgo.ActivePID(fpid[0]) + + robotgo.Kill(fpid[0]) } } @@ -315,8 +317,10 @@ func window() { // determine whether the process exists isExist, err := robotgo.PidExists(100) - if err == nil { + if err == nil && isExist { fmt.Println("pid exists is", isExist) + + robotgo.Kill(100) } // get the all process id diff --git a/examples/window/main.go b/examples/window/main.go index d562228..4bb3181 100644 --- a/examples/window/main.go +++ b/examples/window/main.go @@ -57,6 +57,8 @@ func main() { fmt.Println("pids...", fpid) if len(fpid) > 0 { robotgo.ActivePID(fpid[0]) + + robotgo.Kill(fpid[0]) } } @@ -64,8 +66,10 @@ func main() { // determine whether the process exists isExist, err := robotgo.PidExists(100) - if err == nil { + if err == nil && isExist { fmt.Println("pid exists is", isExist) + + robotgo.Kill(100) } // get the all process id diff --git a/robotgo.go b/robotgo.go index 77b840d..0e7ee3c 100644 --- a/robotgo.go +++ b/robotgo.go @@ -63,7 +63,7 @@ import ( ) const ( - version string = "v0.48.0.506, Ben Nevis!" + version string = "v0.48.0.508, Ben Nevis!" ) type ( @@ -1414,7 +1414,7 @@ func ActiveName(name string) error { } // Kill kill the process by PID -func Kill(pid int) error { - ps := os.Process{Pid: pid} +func Kill(pid int32) error { + ps := os.Process{Pid: int(pid)} return ps.Kill() }