Cw
2026-07-04 fecea2c7a4ecc48b2354868894e78be361a2ccf1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package hotkey
 
import (
    "fmt"
    "time"
)
 
// Listener provides hotkey state polling functionality.
type Listener interface {
    // IsKeyDown returns true if the given virtual key is currently pressed.
    IsKeyDown(vk int) bool
    // IsAnyOtherKeyPressed returns true if any key other than the given vk is pressed.
    IsAnyOtherKeyPressed(excludeVK int) bool
    // IsAnyOtherKeyPressedSince returns true if another key was pressed after since.
    IsAnyOtherKeyPressedSince(excludeVK int, since time.Time) bool
    // Close releases listener resources.
    Close()
}
 
// New creates a new platform-specific hotkey listener.
func New() Listener {
    return newPlatformListener()
}
 
// GetKeyName returns the display name for a virtual key code.
func GetKeyName(vk int) string {
    switch vk {
    case 0x11:
        return "Ctrl"
    case 0xA2:
        return "L-Ctrl"
    case 0xA3:
        return "R-Ctrl"
    case 0x12:
        return "Alt"
    case 0xA4:
        return "L-Alt"
    case 0xA5:
        return "R-Alt"
    case 0x10:
        return "Shift"
    case 0xA0:
        return "L-Shift"
    case 0xA1:
        return "R-Shift"
    case 0x14:
        return "Caps Lock"
    case 0x20:
        return "Space"
    case 0x09:
        return "Tab"
    case 0x0D:
        return "Enter"
    case 0x5B:
        return "L-Win"
    case 0x5C:
        return "R-Win"
    case 0x1B:
        return "Esc"
    default:
        if vk >= 0x41 && vk <= 0x5A {
            return string(rune(vk))
        }
        if vk >= 0x30 && vk <= 0x39 {
            return string(rune(vk))
        }
        if vk >= 0x70 && vk <= 0x7B {
            return fmt.Sprintf("F%d", vk-0x70+1)
        }
        return "Unknown"
    }
}