| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package vt |
| 16 |
|
| 17 |
|
| 18 |
type KeyEvent struct { |
| 19 |
Down bool |
| 20 |
Repeat int |
| 21 |
Key Key |
| 22 |
Base BaseKey |
| 23 |
VK WinVK |
| 24 |
SC ScanCode |
| 25 |
Mod Modifier |
| 26 |
Utf string |
| 27 |
} |
| 28 |
|
| 29 |
type Modifier int |
| 30 |
|
| 31 |
const ( |
| 32 |
ModNone = Modifier(0) |
| 33 |
ModLShift = Modifier(1 << iota) |
| 34 |
ModRShift |
| 35 |
ModLCtrl |
| 36 |
ModRCtrl |
| 37 |
ModLAlt |
| 38 |
ModRAlt |
| 39 |
ModLMeta |
| 40 |
ModRMeta |
| 41 |
ModLHyper |
| 42 |
ModRHyper |
| 43 |
ModCapsLock |
| 44 |
ModNumLock |
| 45 |
) |
| 46 |
|
| 47 |
func (m Modifier) IsShift() bool { return (m & (ModLShift | ModRShift)) != 0 } |
| 48 |
func (m Modifier) IsCtrl() bool { return (m & (ModLCtrl | ModRCtrl)) != 0 } |
| 49 |
func (m Modifier) IsAlt() bool { return (m & (ModLAlt | ModRAlt)) != 0 } |
| 50 |
func (m Modifier) IsMeta() bool { return (m & (ModLMeta | ModRMeta)) != 0 } |
| 51 |
func (m Modifier) IsHyper() bool { return (m & (ModLHyper | ModRHyper)) != 0 } |
| 52 |
func (m Modifier) IsNumLock() bool { return m&ModNumLock != 0 } |
| 53 |
func (m Modifier) IsCapsLock() bool { return m&ModCapsLock != 0 } |
| 54 |
func (m Modifier) IsCapitals() bool { return m.IsCapsLock() != m.IsShift() } |
| 55 |
func (m Modifier) IsAltGr() bool { return m.IsCtrl() && m.IsAlt() } |
| 56 |
|
| 57 |
|
| 58 |
type Button int |
| 59 |
|
| 60 |
const ( |
| 61 |
NoButton = Button(0) |
| 62 |
Button1 = Button(1 << iota) |
| 63 |
Button2 |
| 64 |
Button3 |
| 65 |
Button4 |
| 66 |
Button5 |
| 67 |
Button6 |
| 68 |
Button7 |
| 69 |
Button8 |
| 70 |
WheelUp |
| 71 |
WheelDown |
| 72 |
WheelLeft |
| 73 |
WheelRight |
| 74 |
) |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
type MouseEvent struct { |
| 82 |
Position Coord |
| 83 |
Button Button |
| 84 |
Down bool |
| 85 |
Motion bool |
| 86 |
Mod Modifier |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
func (ev MouseEvent) encodeButton() byte { |
| 91 |
var btn byte |
| 92 |
switch ev.Button { |
| 93 |
case NoButton: |
| 94 |
btn = 3 |
| 95 |
case Button1: |
| 96 |
btn = 0 |
| 97 |
case Button2: |
| 98 |
btn = 2 |
| 99 |
case Button3: |
| 100 |
btn = 1 |
| 101 |
case WheelUp: |
| 102 |
btn = 0x40 |
| 103 |
case WheelDown: |
| 104 |
btn = 0x41 |
| 105 |
case WheelLeft: |
| 106 |
btn = 0x42 |
| 107 |
case WheelRight: |
| 108 |
btn = 0x43 |
| 109 |
case Button4: |
| 110 |
btn = 0x80 |
| 111 |
case Button5: |
| 112 |
btn = 0x81 |
| 113 |
case Button6: |
| 114 |
btn = 0x82 |
| 115 |
case Button7: |
| 116 |
btn = 0x83 |
| 117 |
default: |
| 118 |
btn = 3 |
| 119 |
} |
| 120 |
if ev.Motion { |
| 121 |
btn += 0x20 |
| 122 |
} |
| 123 |
if ev.Mod.IsShift() { |
| 124 |
btn += 4 |
| 125 |
} |
| 126 |
if ev.Mod.IsAlt() || ev.Mod.IsMeta() { |
| 127 |
btn += 8 |
| 128 |
} |
| 129 |
if ev.Mod.IsCtrl() { |
| 130 |
btn += 16 |
| 131 |
} |
| 132 |
return btn |
| 133 |
} |