Init: Create & Init Project...
This commit is contained in:
commit
5bd9fed346
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.exe
|
4
build.bat
Normal file
4
build.bat
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
@echo off
|
||||||
|
SET CGO_ENABLED=1
|
||||||
|
go build -ldflags="-s -w -extldflags -static"
|
||||||
|
pause
|
9
go.mod
Normal file
9
go.mod
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module yumc.pw/desktop/color-pick
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/go-vgo/robotgo v0.0.0-20191226160149-28f256a4c5a0
|
||||||
|
github.com/lxn/win v0.0.0-20191128105842-2da648fda5b4
|
||||||
|
github.com/shirou/gopsutil v2.19.11+incompatible // indirect
|
||||||
|
)
|
64
go.sum
Normal file
64
go.sum
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
|
||||||
|
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
|
||||||
|
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
|
||||||
|
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
|
||||||
|
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||||
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||||
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
|
||||||
|
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
||||||
|
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||||
|
github.com/go-vgo/robotgo v0.0.0-20191226160149-28f256a4c5a0 h1:tklJi7KyJZj/BCFpLdq7Pm64wIbX51gkVbft2oa5aL8=
|
||||||
|
github.com/go-vgo/robotgo v0.0.0-20191226160149-28f256a4c5a0/go.mod h1:P6/F9lmSF2Z/74P/m80qEm6ApjE5HmB+rSzfBCNqIPo=
|
||||||
|
github.com/lxn/win v0.0.0-20191024121223-cc00c7492fe1/go.mod h1:ouWl4wViUNh8tPSIwxTVMuS014WakR1hqvBc2I0bMoA=
|
||||||
|
github.com/lxn/win v0.0.0-20191128105842-2da648fda5b4 h1:5BmtGkQbch91lglMHQ9JIDGiYCL3kBRBA0ItZTvOcEI=
|
||||||
|
github.com/lxn/win v0.0.0-20191128105842-2da648fda5b4/go.mod h1:ouWl4wViUNh8tPSIwxTVMuS014WakR1hqvBc2I0bMoA=
|
||||||
|
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
|
||||||
|
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 h1:o59bHXu8Ejas8Kq6pjoVJQ9/neN66SM8AKh6wI42BBs=
|
||||||
|
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776/go.mod h1:3HNVkVOU7vZeFXocWuvtcS0XSFLcf2XUSDHkq9t1jU4=
|
||||||
|
github.com/otiai10/gosseract v2.2.1+incompatible h1:Ry5ltVdpdp4LAa2bMjsSJH34XHVOV7XMi41HtzL8X2I=
|
||||||
|
github.com/otiai10/gosseract v2.2.1+incompatible/go.mod h1:XrzWItCzCpFRZ35n3YtVTgq5bLAhFIkascoRo8G32QE=
|
||||||
|
github.com/otiai10/mint v1.2.4 h1:DxYL0itZyPaR5Z9HILdxSoHx+gNs6Yx+neOGS3IVUk0=
|
||||||
|
github.com/otiai10/mint v1.2.4/go.mod h1:d+b7n/0R3tdyUYYylALXpWQ/kTN+QobSq/4SRGBkR3M=
|
||||||
|
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/robotn/gohook v0.0.0-20191208195706-98eb507a75d9 h1:7vKLsPiS3XTrejZHaoKDS3/26K3t10rAtuf1+fRfIVA=
|
||||||
|
github.com/robotn/gohook v0.0.0-20191208195706-98eb507a75d9/go.mod h1:n1o8s7fg6QGcgIsN9AmWQnBi6KrcbEUX0kFVUwTP53g=
|
||||||
|
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 v2.19.6+incompatible h1:49/Gru26Lne9Cl3IoAVDZVM09hvkSrUodgIIsCVRwbs=
|
||||||
|
github.com/shirou/gopsutil v2.19.6+incompatible/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc=
|
||||||
|
github.com/shirou/gopsutil v2.19.9+incompatible h1:IrPVlK4nfwW10DF7pW+7YJKws9NkgNzWozwwWv9FsgY=
|
||||||
|
github.com/shirou/gopsutil v2.19.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
|
github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
|
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
|
||||||
|
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/vcaesar/gops v0.0.0-20190910162627-58ac09d12a53 h1:tYb/9KQi8dTCSDia2NwbuhUbKlaurqC/S7MFQo96nLk=
|
||||||
|
github.com/vcaesar/gops v0.0.0-20190910162627-58ac09d12a53/go.mod h1:5txYrXKrQG6ZJYdGIiMVVxiOhbdACnwBcHzIwGQ7Nkw=
|
||||||
|
github.com/vcaesar/imgo v0.0.0-20191008162304-a83ea7753bc8 h1:9Y+hoKBYa+UtzGqkODfs8c0Q6gp2UfniVNsHQWghPi0=
|
||||||
|
github.com/vcaesar/imgo v0.0.0-20191008162304-a83ea7753bc8/go.mod h1:52+3yYrTNjWKh+CkQozNRCLWCE/X666yAWPGbYC3DZI=
|
||||||
|
github.com/vcaesar/tt v0.0.0-20191103173835-6896a351024b h1:psGhQitWSo4KBpLghvJPlhHxTJ8LQl1y0ekjSreqvu4=
|
||||||
|
github.com/vcaesar/tt v0.0.0-20191103173835-6896a351024b/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
|
||||||
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
||||||
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
|
||||||
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c h1:S/FtSvpNLtFBgjTqcKsRpsa6aVsI6iztaz1bQd9BJwE=
|
||||||
|
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
63
hot_key/main.go
Normal file
63
hot_key/main.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package hot_key
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
winapi "github.com/lxn/win"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ModAlt = 1 << iota
|
||||||
|
ModCtrl
|
||||||
|
ModShift
|
||||||
|
ModWin
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
user32 = syscall.NewLazyDLL("user32")
|
||||||
|
registerHotKey = user32.NewProc("RegisterHotKey")
|
||||||
|
unregisterHotKey = user32.NewProc("UnregisterHotKey")
|
||||||
|
)
|
||||||
|
|
||||||
|
var keyHandle = map[int32]func(){0: func() {}}
|
||||||
|
|
||||||
|
func RegisterHotKey(Modifiers, KeyCode int, callback func()) (int, error) {
|
||||||
|
uid := len(keyHandle)
|
||||||
|
r1, _, err := registerHotKey.Call(0, uintptr(uid), uintptr(Modifiers), uintptr(KeyCode))
|
||||||
|
if r1 == 1 {
|
||||||
|
keyHandle[int32(uid)] = callback
|
||||||
|
return uid, nil
|
||||||
|
} else {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnregisterHotKey(uid int32) error {
|
||||||
|
r1, _, err := unregisterHotKey.Call(0, uintptr(uid))
|
||||||
|
if r1 == 1 {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnregisterAllHotKey() {
|
||||||
|
for id, _ := range keyHandle {
|
||||||
|
_ = UnregisterHotKey(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListenHotKey() {
|
||||||
|
go func() {
|
||||||
|
msg := &winapi.MSG{}
|
||||||
|
fmt.Println("Start HotKey Listen...")
|
||||||
|
for {
|
||||||
|
winapi.GetMessage(msg, 0, 0, 0)
|
||||||
|
if msg.Message == winapi.WM_HOTKEY {
|
||||||
|
if fnc, ok := keyHandle[int32(msg.WParam)]; ok {
|
||||||
|
fnc()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
74
main.go
Normal file
74
main.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/go-vgo/robotgo"
|
||||||
|
winapi "github.com/lxn/win"
|
||||||
|
"yumc.pw/desktop/color-pick/hot_key"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
quit := make(chan bool)
|
||||||
|
_, _ = hot_key.RegisterHotKey(hot_key.ModCtrl, 'Q', func() {
|
||||||
|
fmt.Println("Exit Color Pick...")
|
||||||
|
quit <- true
|
||||||
|
})
|
||||||
|
_, _ = hot_key.RegisterHotKey(hot_key.ModCtrl, 'S', func() {
|
||||||
|
hWnd := winapi.GetForegroundWindow()
|
||||||
|
rect := &winapi.RECT{}
|
||||||
|
winapi.GetWindowRect(hWnd, rect)
|
||||||
|
point := &winapi.POINT{}
|
||||||
|
winapi.GetCursorPos(point)
|
||||||
|
color := robotgo.GetPixelColor(int(point.X-1), int(point.Y-1))
|
||||||
|
rectX, rectY := int(point.X-rect.Left-1), int(point.Y-rect.Top-1)
|
||||||
|
fmt.Println(fmt.Sprintf("GetPixelColor hWnd: %v X: %v Y: %v color: %v",
|
||||||
|
hWnd, rectX, rectY, color,
|
||||||
|
))
|
||||||
|
})
|
||||||
|
hot_key.ListenHotKey()
|
||||||
|
<-quit
|
||||||
|
hot_key.UnregisterAllHotKey()
|
||||||
|
//hkey := hotkey.New()
|
||||||
|
//
|
||||||
|
//quit := make(chan bool)
|
||||||
|
//
|
||||||
|
//hkey.Register(hotkey.Ctrl, 'Q', func() {
|
||||||
|
// fmt.Println("Quit")
|
||||||
|
// quit <- true
|
||||||
|
//})
|
||||||
|
//
|
||||||
|
//fmt.Println("Start hotkey's loop")
|
||||||
|
//fmt.Println("Push Ctrl-Q to escape and quit")
|
||||||
|
//<-quit
|
||||||
|
//_ = hot_key.RegisterHotKey(hot_key.ModCtrl+hot_key.ModAlt+hot_key.ModShift, 'S', func() {
|
||||||
|
// hWnd := winapi.GetForegroundWindow()
|
||||||
|
// rect := &winapi.RECT{}
|
||||||
|
// winapi.GetWindowRect(hWnd, rect)
|
||||||
|
// point := &winapi.POINT{}
|
||||||
|
// winapi.GetCursorPos(point)
|
||||||
|
// robotgo.MoveMouse(int(point.X)+5, int(point.Y)+5)
|
||||||
|
// color := robotgo.GetPixelColor(int(point.X), int(point.Y))
|
||||||
|
// fmt.Println(fmt.Sprintf("GetPixelColor hWnd: %v X: %v Y: %v color: %v",
|
||||||
|
// hWnd, point.X-rect.Left, point.Y-rect.Top, color,
|
||||||
|
// ))
|
||||||
|
//})
|
||||||
|
//hot_key.ListenHotKey()
|
||||||
|
//select {}
|
||||||
|
|
||||||
|
//for {
|
||||||
|
// hWnd := winapi.GetForegroundWindow()
|
||||||
|
// rect := &winapi.RECT{}
|
||||||
|
// winapi.GetWindowRect(hWnd, rect)
|
||||||
|
// point := &winapi.POINT{}
|
||||||
|
// winapi.GetCursorPos(point)
|
||||||
|
// color := robotgo.GetPixelColor(int(point.X-1), int(point.Y-1))
|
||||||
|
// rectX, rectY := int(point.X-rect.Left-1), int(point.Y-rect.Top-1)
|
||||||
|
// if (rectX != preX || rectY != preY) && color != preColor {
|
||||||
|
// fmt.Println(fmt.Sprintf("GetPixelColor hWnd: %v X: %v Y: %v color: %v",
|
||||||
|
// hWnd, rectX, rectY, color,
|
||||||
|
// ))
|
||||||
|
// preX, preY, preColor = rectX, rectY, color
|
||||||
|
// }
|
||||||
|
// time.Sleep(time.Millisecond * 300)
|
||||||
|
//}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user