75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
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)
|
|
//}
|
|
}
|