go-vgo / robotgo

RobotGo, Go Native cross-platform RPA and GUI automation @vcaesar
Apache License 2.0
9.47k stars 862 forks source link

cannot use ps.Pids() (value of type []int) as []int32 value in return statement #582

Open historydev opened 1 year ago

historydev commented 1 year ago
package main

import (
    "github.com/go-vgo/robotgo"
)

func main() {
    robotgo.MouseSleep = 100
}

First error i have this:

hook.go:98:17: invalid operation: geve == 0 (mismatched types bool and untyped int)
ps.go:23:9: cannot use ps.Pids() (value of type []int) as []int32 value in return statement

Second error after change robotgo version on 1.0.0-beta1 have only this:

ps.go:23:9: cannot use ps.Pids() (value of type []int) as []int32 value in return statement
iuli-dercaci commented 1 year ago

The same here, and even more. I guess this is related to the Windows compiler (gcc or something)

go: upgraded github.com/go-vgo/robotgo v0.100.10 => v1.0.0-beta1 \golang\mouseClick> go run .\cmd\main.go

..\..\go\src\pkg\mod\github.com\go-vgo\robotgo@v1.0.0-beta1\ps.go:23:9: cannot use ps.Pids() (value of type []int) as []int32 value in return statement
..\..\go\src\pkg\mod\github.com\go-vgo\robotgo@v1.0.0-beta1\ps.go:28:22: cannot use pid (variable of type int32) as int value in argument to ps.PidExists
..\..\go\src\pkg\mod\github.com\go-vgo\robotgo@v1.0.0-beta1\ps.go:37:4: cannot use nps[i].Pid (variable of type int) as int32 value in struct literal
..\..\go\src\pkg\mod\github.com\go-vgo\robotgo@v1.0.0-beta1\ps.go:49:21: cannot use pid (variable of type int32) as int value in argument to ps.FindName
..\..\go\src\pkg\mod\github.com\go-vgo\robotgo@v1.0.0-beta1\ps.go:61:9: cannot use ps.FindIds(name) (value of type []int) as []int32 value in return statement        
..\..\go\src\pkg\mod\github.com\go-vgo\robotgo@v1.0.0-beta1\ps.go:66:21: cannot use pid (variable of type int32) as int value in argument to ps.FindPath
..\..\go\src\pkg\mod\github.com\go-vgo\robotgo@v1.0.0-beta1\ps.go:76:17: cannot use pid (variable of type int32) as int value in argument to ps.Kill
parsibox commented 1 year ago

i have same error

tfmeneses commented 11 months ago

I'm getting the same. Should I rollback to an old version?

drgrib commented 11 months ago

Same. As far as I can tell, robotgo is completely unusable on Windows from a fresh install.

drgrib commented 11 months ago

For anyone looking for a workaround on Windows, I ended up using AutoHotkey. It certainly leaves a lot to be desired in terms of syntax and data structures but I was able to accomplish what I needed with a few Map() data structures.

wilon commented 11 months ago

Because the robotgo version does not match its dependency versions. Run go mod graph check it.

Re download the go mod dependencies will solve it.

Just like this:

  1. Update robotgo go get -u github.com/go-vgo/robotgo.
  2. Clear go.mod file second require.
  3. Then run go mod tidy.
module tests

go 1.18

require (
    github.com/go-vgo/robotgo v1.0.0-rc1.0.20230706172004-af321105215d
)

- require (
-   github.com/vcaesar/gops v0.30.1 // indirect
-   github.com/vcaesar/imgo v0.30.2 // indirect
-   github.com/vcaesar/keycode v0.10.0 // indirect
-   github.com/vcaesar/tt v0.20.0 // indirect
-   ...
- )
drgrib commented 11 months ago

@wilon This isn't for go 1.18. This is for people running go 1.20+ on Windows.

We have to use:

go get -u github.com/go-vgo/robotgo@v1.0.0-beta1

Or otherwise we get this issue documented in the OPs post:

hook.go:98:17: invalid operation: geve == 0 (mismatched types bool and untyped int)

But using the beta causes the second issue in the OPs post:

ps.go:23:9: cannot use ps.Pids() (value of type []int) as []int32 value in return statement

I've tried to manually set my go.mod file to use go 1.15 but this seems to be an issue with the go 1.20 base installation I have.

wilon commented 11 months ago

It doesn't matter which go version, try execute steps 2 and 3.

drgrib commented 11 months ago

I don't have the second require in my go.mod file, so step 2 is not possible.

wilon commented 11 months ago

I don't have the second require in my go.mod file, so step 2 is not possible.

Run go mod graph check the dependencies, then find out the mismatching package, reinstall it. Or remove the go.mod and reinstall all dependencies.

drgrib commented 11 months ago

Thanks @wilon. Just removing whatever was in my second require (even though it didn't match what you wrote) and running go mod tidy worked. It is really strange to me that these issues pop up on a fresh install but it was likely because I didn't start with the beta but instead switched to it after trying the non-beta.