新增: SFTP直连+网站预览+OSS区域嗅探+热键+BGM播放
This commit is contained in:
41
internal/hotkey/hotkey.go
Normal file
41
internal/hotkey/hotkey.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package hotkey
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
moduser32 = syscall.NewLazyDLL("user32.dll")
|
||||
procRegisterHotKey = moduser32.NewProc("RegisterHotKey")
|
||||
procUnregisterHotKey = moduser32.NewProc("UnregisterHotKey")
|
||||
procPostMessage = moduser32.NewProc("PostMessageW")
|
||||
)
|
||||
|
||||
const (
|
||||
ModAlt = 0x0001
|
||||
ModControl = 0x0002
|
||||
ModShift = 0x0004
|
||||
ModWin = 0x0008
|
||||
|
||||
WM_HOTKEY = 0x0312
|
||||
WM_APP_HOTKEY = 0x8001 // 自定义消息:在主线程触发热键注册
|
||||
)
|
||||
|
||||
func Register(hwnd uintptr, id int32, modifiers uint32, vk uint32) error {
|
||||
ret, _, _ := procRegisterHotKey.Call(hwnd, uintptr(id), uintptr(modifiers), uintptr(vk))
|
||||
if ret == 0 {
|
||||
return fmt.Errorf("RegisterHotKey failed for id=%d", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Unregister(hwnd uintptr, id int32) bool {
|
||||
ret, _, _ := procUnregisterHotKey.Call(hwnd, uintptr(id))
|
||||
return ret != 0
|
||||
}
|
||||
|
||||
// PostMessage 向窗口投递异步消息(用于跨线程调度到主线程)
|
||||
func PostMessage(hwnd uintptr, msg uint32, wParam, lParam uintptr) {
|
||||
procPostMessage.Call(hwnd, uintptr(msg), wParam, lParam)
|
||||
}
|
||||
Reference in New Issue
Block a user