package windll
import (
"syscall"
"unsafe"
)
var (
modUser32, _ = syscall.LoadDLL("user32.dll")
procGetKeyboardState, _ = modUser32.FindProc("GetKeyboardState")
procGetAsyncKeyState, _ = modUser32.FindProc("GetAsyncKeyState")
getCursorPosState, _ = modUser32.FindProc("GetCursorPos")
)
type POINT struct {
X, Y int32
}
// GetAsyncKeyState 确定在调用该函数时某个键是按下还是按下,以及在上一次调用GetAsyncKeyState之后是否按下了该键
// 参考 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate
func GetAsyncKeyState(key int) uintptr {
res, _, _ := procGetAsyncKeyState.Call(uintptr(key))
return res & 0x8000
}
// GetCoords 获取当前光标位置
func GetCoords(point *POINT) bool {
getCursorPosState.Call(uintptr(unsafe.Pointer(point)), 0, 0, 0)
return true
}
标签:GetAsyncKeyState,modUser32,uintptr,dll,go,win10,FindProc,光标
From: https://www.cnblogs.com/ifnk/p/17223164.html