diff --git a/.circleci/config.yml b/.circleci/config.yml index dc9f59a..55be1d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ jobs: docker: # using custom image, see .circleci/images/primary/Dockerfile # - image: govgo/robotgoci:1.10.3 - - image: golang:1.19.1 + - image: golang:1.19.3 working_directory: /gopath/src/github.com/go-vgo/robotgo steps: - checkout diff --git a/.circleci/images/primary/Dockerfile b/.circleci/images/primary/Dockerfile index d4649aa..7b15f84 100644 --- a/.circleci/images/primary/Dockerfile +++ b/.circleci/images/primary/Dockerfile @@ -1,5 +1,5 @@ # FROM golang:1.10.1 -FROM golang:1.19.1-stretch AS build +FROM golang:1.19.3-stretch AS build # FROM govgo/go:1.11.1 RUN apt update && apt install -y --no-install-recommends \ diff --git a/appveyor.yml b/appveyor.yml index c5e38ea..1e8bb1c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,7 +34,7 @@ environment: PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH% # - COMPILER: MINGW_W64 # ARCHITECTURE: x64 - GOVERSION: 1.19.1 + GOVERSION: 1.19.3 # GOPATH: c:\gopath # scripts that run after cloning repository diff --git a/examples/window/main.go b/examples/window/main.go index 7e39b5b..5d63145 100644 --- a/examples/window/main.go +++ b/examples/window/main.go @@ -56,7 +56,7 @@ func findIds() { if len(fpid) > 0 { robotgo.KeyTap("a", fpid[0]) - robotgo.TypeStr("Hi galaxy!", int(fpid[0])) + robotgo.TypeStr("Hi galaxy!", fpid[0]) robotgo.KeyToggle("a", fpid[0], "cmd") robotgo.KeyToggle("a", fpid[0], "cmd", "up") diff --git a/go.mod b/go.mod index 3a26779..6cd39ba 100644 --- a/go.mod +++ b/go.mod @@ -8,25 +8,23 @@ require ( // github.com/robotn/gohook v0.31.3 github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934 github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770 - github.com/vcaesar/gops v0.23.0 + github.com/vcaesar/gops v0.30.0 github.com/vcaesar/imgo v0.30.1 github.com/vcaesar/keycode v0.10.0 github.com/vcaesar/tt v0.20.0 - golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect - golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect + golang.org/x/image v0.1.0 // indirect ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-ole/go-ole v1.2.6 // indirect - github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect github.com/otiai10/mint v1.3.0 // indirect - github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect - github.com/shirou/gopsutil/v3 v3.22.4 // indirect - github.com/tklauser/go-sysconf v0.3.10 // indirect - github.com/tklauser/numcpus v0.4.0 // indirect + github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect + github.com/shirou/gopsutil/v3 v3.22.10 // indirect + github.com/tklauser/go-sysconf v0.3.11 // indirect + github.com/tklauser/numcpus v0.6.0 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect - golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect + golang.org/x/sys v0.2.0 // indirect ) // replace golang.org/x/sys => github.com/golang/sys v0.0.0-20190109145017-48ac38b7c8cb diff --git a/go.sum b/go.sum index c661775..c8c887a 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,11 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c h1:VtwQ41oftZwlMnOEbMWQtSEUgU64U4s+GHk7hZK+jtY= +github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc= github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= @@ -19,51 +20,73 @@ github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c h1:NRoLoZvkBTKvR5gQLgA3e0hqjkY9u1wm+iOL45VN/qI= +github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934 h1:2lhSR8N3T6I30q096DT7/5AKEIcf1vvnnWAmS0wfnNY= github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934/go.mod h1:SxQhJskUJ4rleVU44YvnrdvxQr0tKy5SRSigBrCgyyQ= github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770 h1:2uX8QRLkkxn2EpAQ6I3KhA79BkdRZfvugJUzJadiJwk= github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770/go.mod h1:svkDXUDQjUiWzLrA0OZgHc4lbOts3C+uRfP6/yjwYnU= -github.com/shirou/gopsutil/v3 v3.22.4 h1:srAQaiX6jX/cYL6q29aE0m8lOskT9CurZ9N61YR3yoI= -github.com/shirou/gopsutil/v3 v3.22.4/go.mod h1:D01hZJ4pVHPpCTZ3m3T2+wDF2YAGfd+H4ifUguaQzHM= +github.com/shirou/gopsutil/v3 v3.22.10 h1:4KMHdfBRYXGF9skjDWiL4RA2N+E8dRdodU/bOZpPoVg= +github.com/shirou/gopsutil/v3 v3.22.10/go.mod h1:QNza6r4YQoydyCfo6rH0blGfKahgibh4dQmV5xdFkQk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= -github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o= +github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= +github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= -github.com/vcaesar/gops v0.23.0 h1:gY/E5UJfLpImJjE7tiTJIVRcKOWxi7YX1J/CUHK8gXk= -github.com/vcaesar/gops v0.23.0/go.mod h1:3IepRPE6qK9Wy8MGLJx2N3o77fuO1Ec7FvPHyEuou8I= +github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= +github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/vcaesar/gops v0.30.0 h1:970FznFxZP8ku0zckJRO+pI2fFhg3uJ0z+sQS0NHP4o= +github.com/vcaesar/gops v0.30.0/go.mod h1:xV1wieUA4D9RaNQ8lf8AwPZ8bl+x/MM5w3SsMCr5KVs= github.com/vcaesar/imgo v0.30.1 h1:B7QMm2mZY+SGoEvvJwNi+eAv21ptvk2YT1IbP2OzyLE= github.com/vcaesar/imgo v0.30.1/go.mod h1:n4EluJIN/0UYYGPHBCY/BWlIjdRUdY5U6obtP2lrgdM= github.com/vcaesar/keycode v0.10.0 h1:Qx5QE8ZXHyRyjoA2QOxBp25OKMKB+zxMVqm0FWGV0d4= github.com/vcaesar/keycode v0.10.0/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ= github.com/vcaesar/tt v0.20.0 h1:9t2Ycb9RNHcP0WgQgIaRKJBB+FrRdejuaL6uWIHuoBA= github.com/vcaesar/tt v0.20.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk= +golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/ps.go b/ps.go index 9a45386..cba6f1b 100644 --- a/ps.go +++ b/ps.go @@ -14,17 +14,17 @@ import ps "github.com/vcaesar/gops" // Nps process struct type Nps struct { - Pid int32 + Pid int Name string } // Pids get the all process id -func Pids() ([]int32, error) { +func Pids() ([]int, error) { return ps.Pids() } // PidExists determine whether the process exists -func PidExists(pid int32) (bool, error) { +func PidExists(pid int) (bool, error) { return ps.PidExists(pid) } @@ -45,7 +45,7 @@ func Process() ([]Nps, error) { } // FindName find the process name by the process id -func FindName(pid int32) (string, error) { +func FindName(pid int) (string, error) { return ps.FindName(pid) } @@ -57,12 +57,12 @@ func FindNames() ([]string, error) { // FindIds finds the all processes named with a subset // of "name" (case insensitive), // return matched IDs. -func FindIds(name string) ([]int32, error) { +func FindIds(name string) ([]int, error) { return ps.FindIds(name) } // FindPath find the process path by the process pid -func FindPath(pid int32) (string, error) { +func FindPath(pid int) (string, error) { return ps.FindPath(pid) } @@ -72,6 +72,6 @@ func Run(path string) ([]byte, error) { } // Kill kill the process by PID -func Kill(pid int32) error { +func Kill(pid int) error { return ps.Kill(pid) } diff --git a/robotgo.go b/robotgo.go index 91faeb9..dd902a3 100644 --- a/robotgo.go +++ b/robotgo.go @@ -920,55 +920,55 @@ func GetActive() C.MData { } // MinWindow set the window min -func MinWindow(pid int32, args ...interface{}) { +func MinWindow(pid int, args ...interface{}) { var ( state = true - hwnd int + isPid int ) if len(args) > 0 { state = args[0].(bool) } if len(args) > 1 { - hwnd = args[1].(int) + isPid = args[1].(int) } - C.min_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd)) + C.min_window(C.uintptr(pid), C.bool(state), C.int8_t(isPid)) } // MaxWindow set the window max -func MaxWindow(pid int32, args ...interface{}) { +func MaxWindow(pid int, args ...interface{}) { var ( state = true - hwnd int + isPid int ) if len(args) > 0 { state = args[0].(bool) } if len(args) > 1 { - hwnd = args[1].(int) + isPid = args[1].(int) } - C.max_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd)) + C.max_window(C.uintptr(pid), C.bool(state), C.int8_t(isPid)) } // CloseWindow close the window -func CloseWindow(args ...int32) { +func CloseWindow(args ...int) { if len(args) <= 0 { C.close_main_window() return } - var hwnd, isHwnd int32 + var pid, isPid int if len(args) > 0 { - hwnd = args[0] + pid = args[0] } if len(args) > 1 { - isHwnd = args[1] + isPid = args[1] } - C.close_window_by_PId(C.uintptr(hwnd), C.uintptr(isHwnd)) + C.close_window_by_PId(C.uintptr(pid), C.int8_t(isPid)) } // SetHandle set the window handle @@ -978,23 +978,23 @@ func SetHandle(hwnd int) { } // SetHandlePid set the window handle by pid -func SetHandlePid(pid int32, args ...int32) { - var isHwnd int32 +func SetHandlePid(pid int, args ...int) { + var isPid int if len(args) > 0 { - isHwnd = args[0] + isPid = args[0] } - C.set_handle_pid_mData(C.uintptr(pid), C.uintptr(isHwnd)) + C.set_handle_pid_mData(C.uintptr(pid), C.int8_t(isPid)) } // GetHandPid get handle mdata by pid -func GetHandPid(pid int32, args ...int32) C.MData { - var isHwnd int32 +func GetHandPid(pid int, args ...int) C.MData { + var isPid int if len(args) > 0 { - isHwnd = args[0] + isPid = args[0] } - return C.set_handle_pid(C.uintptr(pid), C.uintptr(isHwnd)) + return C.set_handle_pid(C.uintptr(pid), C.int8_t(isPid)) } // GetHandle get the window handle @@ -1018,8 +1018,8 @@ func GetBHandle() int { return ghwnd } -func cgetTitle(hwnd, isHwnd int32) string { - title := C.get_title_by_pid(C.uintptr(hwnd), C.uintptr(isHwnd)) +func cgetTitle(pid, isPid int) string { + title := C.get_title_by_pid(C.uintptr(pid), C.int8_t(isPid)) gtitle := C.GoString(title) return gtitle @@ -1033,7 +1033,7 @@ func cgetTitle(hwnd, isHwnd int32) string { // // ids, _ := robotgo.FindIds() // robotgo.GetTitle(ids[0]) -func GetTitle(args ...int32) string { +func GetTitle(args ...int) string { if len(args) <= 0 { title := C.get_main_title() gtitle := C.GoString(title) @@ -1048,20 +1048,20 @@ func GetTitle(args ...int32) string { } // GetPid get the process id return int32 -func GetPid() int32 { +func GetPid() int { pid := C.get_PID() - return int32(pid) + return int(pid) } // internalGetBounds get the window bounds -func internalGetBounds(pid int32, hwnd int) (int, int, int, int) { - bounds := C.get_bounds(C.uintptr(pid), C.uintptr(hwnd)) +func internalGetBounds(pid, isPid int) (int, int, int, int) { + bounds := C.get_bounds(C.uintptr(pid), C.int8_t(isPid)) return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H) } // internalGetClient get the window client bounds -func internalGetClient(pid int32, hwnd int) (int, int, int, int) { - bounds := C.get_client(C.uintptr(pid), C.uintptr(hwnd)) +func internalGetClient(pid, isPid int) (int, int, int, int) { + bounds := C.get_client(C.uintptr(pid), C.int8_t(isPid)) return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H) } @@ -1071,19 +1071,19 @@ func Is64Bit() bool { return bool(b) } -func internalActive(pid int32, hwnd int) { - C.active_PID(C.uintptr(pid), C.uintptr(hwnd)) +func internalActive(pid, isPid int) { + C.active_PID(C.uintptr(pid), C.int8_t(isPid)) } // ActivePid active the window by Pid, // If args[0] > 0 on the Windows platform via a window handle to active // func ActivePid(pid int32, args ...int) { -// var hwnd int +// var isPid int // if len(args) > 0 { -// hwnd = args[0] +// isPid = args[0] // } -// C.active_PID(C.uintptr(pid), C.uintptr(hwnd)) +// C.active_PID(C.uintptr(pid), C.uintptr(isPid)) // } // ActiveName active the window by name diff --git a/robotgo_mac_win.go b/robotgo_mac_win.go index 798ea06..e1fe167 100644 --- a/robotgo_mac_win.go +++ b/robotgo_mac_win.go @@ -14,32 +14,32 @@ package robotgo // GetBounds get the window bounds -func GetBounds(pid int32, args ...int) (int, int, int, int) { - var hwnd int +func GetBounds(pid int, args ...int) (int, int, int, int) { + var isPid int if len(args) > 0 { - hwnd = args[0] + isPid = args[0] } - return internalGetBounds(pid, hwnd) + return internalGetBounds(pid, isPid) } // GetClient get the window client bounds -func GetClient(pid int32, args ...int) (int, int, int, int) { - var hwnd int +func GetClient(pid int, args ...int) (int, int, int, int) { + var isPid int if len(args) > 0 { - hwnd = args[0] + isPid = args[0] } - return internalGetClient(pid, hwnd) + return internalGetClient(pid, isPid) } // internalGetTitle get the window title -func internalGetTitle(pid int32, args ...int32) string { - var isHwnd int32 +func internalGetTitle(pid int, args ...int) string { + var isPid int if len(args) > 0 { - isHwnd = args[0] + isPid = args[0] } - gtitle := cgetTitle(pid, isHwnd) + gtitle := cgetTitle(pid, isPid) return gtitle } @@ -52,13 +52,13 @@ func internalGetTitle(pid int32, args ...int32) string { // // ids, _ := robotgo.FindIds() // robotgo.ActivePid(ids[0]) -func ActivePid(pid int32, args ...int) error { - var hwnd int +func ActivePid(pid int, args ...int) error { + var isPid int if len(args) > 0 { - hwnd = args[0] + isPid = args[0] } - internalActive(pid, hwnd) + internalActive(pid, isPid) return nil } diff --git a/robotgo_test.go b/robotgo_test.go index c3aed91..31d14b1 100644 --- a/robotgo_test.go +++ b/robotgo_test.go @@ -220,6 +220,11 @@ func TestPs(t *testing.T) { tt.IsType(t, "[]int32", id) tt.Nil(t, err) + if len(id) > 0 { + e := KeyTap("v", id[0], "cmd") + tt.Nil(t, e) + } + // n, e = FindPath(id[0]) // tt.NotEmpty(t, n) // tt.Nil(t, e) diff --git a/robotgo_win.go b/robotgo_win.go index 2d05078..1f9c6e6 100644 --- a/robotgo_win.go +++ b/robotgo_win.go @@ -52,6 +52,11 @@ func SetFocus(hwnd win.HWND) win.HWND { return win.SetFocus(hwnd) } +// SetForeg set the window into the foreground by hwnd +func SetForeg(hwnd win.HWND) bool { + return win.SetForegroundWindow(hwnd) +} + // GetMian get the main display hwnd func GetMain() win.HWND { return win.GetActiveWindow() diff --git a/robotgo_x11.go b/robotgo_x11.go index c6445f8..f8fdc00 100644 --- a/robotgo_x11.go +++ b/robotgo_x11.go @@ -27,11 +27,11 @@ import ( var xu *xgbutil.XUtil // GetBounds get the window bounds -func GetBounds(pid int32, args ...int) (int, int, int, int) { - var hwnd int +func GetBounds(pid int, args ...int) (int, int, int, int) { + var isPid int if len(args) > 0 { - hwnd = args[0] - return internalGetBounds(pid, hwnd) + isPid = args[0] + return internalGetBounds(pid, isPid) } xid, err := GetXid(xu, pid) @@ -40,15 +40,15 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) { return 0, 0, 0, 0 } - return internalGetBounds(int32(xid), hwnd) + return internalGetBounds(xid, isPid) } // GetClient get the window client bounds -func GetClient(pid int32, args ...int) (int, int, int, int) { - var hwnd int +func GetClient(pid int, args ...int) (int, int, int, int) { + var isPid int if len(args) > 0 { - hwnd = args[0] - return internalGetClient(pid, hwnd) + isPid = args[0] + return internalGetClient(pid, isPid) } xid, err := GetXid(xu, pid) @@ -57,15 +57,15 @@ func GetClient(pid int32, args ...int) (int, int, int, int) { return 0, 0, 0, 0 } - return internalGetClient(int32(xid), hwnd) + return internalGetClient(xid, isPid) } // internalGetTitle get the window title -func internalGetTitle(pid int32, args ...int32) string { - var hwnd int32 +func internalGetTitle(pid int, args ...int) string { + var isPid int if len(args) > 0 { - hwnd = args[0] - return cgetTitle(pid, hwnd) + isPid = args[0] + return cgetTitle(pid, isPid) } xid, err := GetXid(xu, pid) @@ -74,16 +74,16 @@ func internalGetTitle(pid int32, args ...int32) string { return "" } - return cgetTitle(int32(xid), hwnd) + return cgetTitle(xid, isPid) } // ActivePidC active the window by Pid, // If args[0] > 0 on the unix platform via a xid to active -func ActivePidC(pid int32, args ...int) error { - var hwnd int +func ActivePidC(pid int, args ...int) error { + var isPid int if len(args) > 0 { - hwnd = args[0] - internalActive(pid, hwnd) + isPid = args[0] + internalActive(pid, isPid) return nil } @@ -93,7 +93,7 @@ func ActivePidC(pid int32, args ...int) error { return err } - internalActive(int32(xid), hwnd) + internalActive(xid, isPid) return nil } @@ -101,7 +101,7 @@ func ActivePidC(pid int32, args ...int) error { // // If args[0] > 0 on the Windows platform via a window handle to active, // If args[0] > 0 on the unix platform via a xid to active -func ActivePid(pid int32, args ...int) error { +func ActivePid(pid int, args ...int) error { if xu == nil { var err error xu, err = xgbutil.NewConn() @@ -134,7 +134,7 @@ func ActivePid(pid int32, args ...int) error { } // GetXid get the xid return window and error -func GetXid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) { +func GetXid(xu *xgbutil.XUtil, pid int) (xproto.Window, error) { if xu == nil { var err error xu, err = xgbutil.NewConn() @@ -149,7 +149,7 @@ func GetXid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) { } // GetXidFromPid get the xid from pid -func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) { +func GetXidFromPid(xu *xgbutil.XUtil, pid int) (xproto.Window, error) { windows, err := ewmh.ClientListGet(xu) if err != nil { return 0, err diff --git a/screen/goScreen.h b/screen/goScreen.h index e990d3e..c093d06 100644 --- a/screen/goScreen.h +++ b/screen/goScreen.h @@ -9,8 +9,8 @@ // except according to those terms. #include "../base/types.h" -#include "../base/rgb.h" #include "../base/pubs.h" +#include "../base/rgb.h" #include "screengrab_c.h" #include "screen_c.h" #include diff --git a/window/goWindow.h b/window/goWindow.h index e73300b..6b69130 100644 --- a/window/goWindow.h +++ b/window/goWindow.h @@ -12,7 +12,7 @@ #include "window.h" #include "win_sys.h" -void min_window(uintptr pid, bool state, uintptr isHwnd){ +void min_window(uintptr pid, bool state, int8_t isPid){ #if defined(IS_MACOSX) // return 0; AXUIElementRef axID = AXUIElementCreateApplication(pid); @@ -23,7 +23,7 @@ void min_window(uintptr pid, bool state, uintptr isHwnd){ XDismissErrors(); // SetState((Window)pid, STATE_MINIMIZE, state); #elif defined(IS_WINDOWS) - if (isHwnd == 0) { + if (isPid == 0) { HWND hwnd = GetHwndByPid(pid); win_min(hwnd, state); } else { @@ -32,7 +32,7 @@ void min_window(uintptr pid, bool state, uintptr isHwnd){ #endif } -void max_window(uintptr pid, bool state, uintptr isHwnd){ +void max_window(uintptr pid, bool state, int8_t isPid){ #if defined(IS_MACOSX) // return 0; #elif defined(USE_X11) @@ -40,7 +40,7 @@ void max_window(uintptr pid, bool state, uintptr isHwnd){ // SetState((Window)pid, STATE_MINIMIZE, false); // SetState((Window)pid, STATE_MAXIMIZE, state); #elif defined(IS_WINDOWS) - if (isHwnd == 0) { + if (isPid == 0) { HWND hwnd = GetHwndByPid(pid); win_max(hwnd, state); } else { @@ -71,7 +71,7 @@ uintptr b_get_handle() { #endif } -void active_PID(uintptr pid, uintptr isHwnd){ - MData win = set_handle_pid(pid, isHwnd); +void active_PID(uintptr pid, int8_t isPid){ + MData win = set_handle_pid(pid, isPid); set_active(win); } diff --git a/window/win_sys.h b/window/win_sys.h index 89e643d..01edf01 100644 --- a/window/win_sys.h +++ b/window/win_sys.h @@ -12,7 +12,7 @@ #include #endif -Bounds get_client(uintptr pid, uintptr isHwnd); +Bounds get_client(uintptr pid, int8_t isPid); intptr scaleX(); double sys_scale(int32_t display_id) { @@ -73,7 +73,7 @@ intptr scaleX(){ #endif } -Bounds get_bounds(uintptr pid, uintptr isHwnd){ +Bounds get_bounds(uintptr pid, int8_t isPid){ // Check if the window is valid Bounds bounds; if (!is_valid()) { return bounds; } @@ -118,7 +118,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){ MData win; win.XWin = (Window)pid; - Bounds client = get_client(pid, isHwnd); + Bounds client = get_client(pid, isPid); Bounds frame = GetFrame(win); bounds.X = client.X - frame.X; @@ -129,7 +129,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){ return bounds; #elif defined(IS_WINDOWS) HWND hwnd; - if (isHwnd == 0) { + if (isPid == 0) { hwnd= GetHwndByPid(pid); } else { hwnd = (HWND)pid; @@ -147,13 +147,13 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){ #endif } -Bounds get_client(uintptr pid, uintptr isHwnd) { +Bounds get_client(uintptr pid, int8_t isPid) { // Check if the window is valid Bounds bounds; if (!is_valid()) { return bounds; } #if defined(IS_MACOSX) - return get_bounds(pid, isHwnd); + return get_bounds(pid, isPid); #elif defined(USE_X11) Display *rDisplay = XOpenDisplay(NULL); @@ -194,7 +194,7 @@ Bounds get_client(uintptr pid, uintptr isHwnd) { return bounds; #elif defined(IS_WINDOWS) HWND hwnd; - if (isHwnd == 0) { + if (isPid == 0) { hwnd = GetHwndByPid(pid); } else { hwnd = (HWND)pid; diff --git a/window/window.h b/window/window.h index b4a861f..301129a 100644 --- a/window/window.h +++ b/window/window.h @@ -50,7 +50,7 @@ bool Is64Bit() { return false; } -MData set_handle_pid(uintptr pid, uintptr isHwnd){ +MData set_handle_pid(uintptr pid, int8_t isPid){ MData win; #if defined(IS_MACOSX) // Handle to a AXUIElementRef @@ -59,7 +59,7 @@ MData set_handle_pid(uintptr pid, uintptr isHwnd){ win.XWin = (Window)pid; // Handle to an X11 window #elif defined(IS_WINDOWS) // win.HWnd = (HWND)pid; // Handle to a window HWND - if (isHwnd == 0) { + if (isPid == 0) { win.HWnd = GetHwndByPid(pid); } else { win.HWnd = (HWND)pid; @@ -69,8 +69,8 @@ MData set_handle_pid(uintptr pid, uintptr isHwnd){ return win; } -void set_handle_pid_mData(uintptr pid, uintptr isHwnd){ - MData win = set_handle_pid(pid, isHwnd); +void set_handle_pid_mData(uintptr pid, int8_t isPid){ + MData win = set_handle_pid(pid, isPid); mData = win; } @@ -464,8 +464,8 @@ void close_main_window () { close_window_by_Id(mData); } -void close_window_by_PId(uintptr pid, uintptr isHwnd){ - MData win = set_handle_pid(pid, isHwnd); +void close_window_by_PId(uintptr pid, int8_t isPid){ + MData win = set_handle_pid(pid, isPid); close_window_by_Id(win); } @@ -502,8 +502,8 @@ char* get_main_title(){ return get_title_by_hand(mData); } -char* get_title_by_pid(uintptr pid, uintptr isHwnd){ - MData win = set_handle_pid(pid, isHwnd); +char* get_title_by_pid(uintptr pid, int8_t isPid){ + MData win = set_handle_pid(pid, isPid); return get_title_by_hand(win); }