2019-12-31 07:10:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/go-vgo/robotgo"
|
2020-01-02 01:41:23 +00:00
|
|
|
"github.com/lxn/win"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2019-12-31 07:10:37 +00:00
|
|
|
"yumc.pw/desktop/color-pick/hot_key"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-01-02 01:41:23 +00:00
|
|
|
quit := make(chan os.Signal)
|
|
|
|
signal.Notify(quit, os.Interrupt, os.Kill)
|
2019-12-31 07:10:37 +00:00
|
|
|
_, _ = hot_key.RegisterHotKey(hot_key.ModCtrl, 'S', func() {
|
2020-01-02 01:41:23 +00:00
|
|
|
hWnd := win.GetForegroundWindow()
|
|
|
|
rect := &win.RECT{}
|
|
|
|
win.GetWindowRect(hWnd, rect)
|
|
|
|
point := &win.POINT{}
|
|
|
|
win.GetCursorPos(point)
|
2019-12-31 07:10:37 +00:00
|
|
|
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()
|
|
|
|
}
|