feat: exit use signal
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
5bd9fed346
commit
31511564dc
5
go.sum
5
go.sum
@ -31,10 +31,8 @@ github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934 h1:2lhSR8N3T6I30q096DT7
|
|||||||
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934/go.mod h1:SxQhJskUJ4rleVU44YvnrdvxQr0tKy5SRSigBrCgyyQ=
|
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 h1:2uX8QRLkkxn2EpAQ6I3KhA79BkdRZfvugJUzJadiJwk=
|
||||||
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770/go.mod h1:svkDXUDQjUiWzLrA0OZgHc4lbOts3C+uRfP6/yjwYnU=
|
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.6+incompatible/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc=
|
||||||
github.com/shirou/gopsutil v2.19.9+incompatible h1:IrPVlK4nfwW10DF7pW+7YJKws9NkgNzWozwwWv9FsgY=
|
github.com/shirou/gopsutil v2.19.11+incompatible h1:lJHR0foqAjI4exXqWsU3DbH7bX1xvdhGdnXTIARA9W4=
|
||||||
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/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 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
|
||||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
||||||
@ -56,7 +54,6 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smto
|
|||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
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-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-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-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-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 h1:S/FtSvpNLtFBgjTqcKsRpsa6aVsI6iztaz1bQd9BJwE=
|
||||||
|
64
main.go
64
main.go
@ -3,22 +3,21 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-vgo/robotgo"
|
"github.com/go-vgo/robotgo"
|
||||||
winapi "github.com/lxn/win"
|
"github.com/lxn/win"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"yumc.pw/desktop/color-pick/hot_key"
|
"yumc.pw/desktop/color-pick/hot_key"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
quit := make(chan bool)
|
quit := make(chan os.Signal)
|
||||||
_, _ = hot_key.RegisterHotKey(hot_key.ModCtrl, 'Q', func() {
|
signal.Notify(quit, os.Interrupt, os.Kill)
|
||||||
fmt.Println("Exit Color Pick...")
|
|
||||||
quit <- true
|
|
||||||
})
|
|
||||||
_, _ = hot_key.RegisterHotKey(hot_key.ModCtrl, 'S', func() {
|
_, _ = hot_key.RegisterHotKey(hot_key.ModCtrl, 'S', func() {
|
||||||
hWnd := winapi.GetForegroundWindow()
|
hWnd := win.GetForegroundWindow()
|
||||||
rect := &winapi.RECT{}
|
rect := &win.RECT{}
|
||||||
winapi.GetWindowRect(hWnd, rect)
|
win.GetWindowRect(hWnd, rect)
|
||||||
point := &winapi.POINT{}
|
point := &win.POINT{}
|
||||||
winapi.GetCursorPos(point)
|
win.GetCursorPos(point)
|
||||||
color := robotgo.GetPixelColor(int(point.X-1), int(point.Y-1))
|
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)
|
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",
|
fmt.Println(fmt.Sprintf("GetPixelColor hWnd: %v X: %v Y: %v color: %v",
|
||||||
@ -28,47 +27,4 @@ func main() {
|
|||||||
hot_key.ListenHotKey()
|
hot_key.ListenHotKey()
|
||||||
<-quit
|
<-quit
|
||||||
hot_key.UnregisterAllHotKey()
|
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