| 1 |
|
| 2 |
package windows |
| 3 |
|
| 4 |
import ( |
| 5 |
"encoding/binary" |
| 6 |
|
| 7 |
"golang.org/x/sys/windows" |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
type FocusEventRecord struct { |
| 14 |
|
| 15 |
SetFocus bool |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
type MenuEventRecord struct { |
| 22 |
CommandID uint32 |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
type MouseEventRecord struct { |
| 29 |
|
| 30 |
|
| 31 |
MousePositon windows.Coord |
| 32 |
|
| 33 |
|
| 34 |
ButtonState uint32 |
| 35 |
|
| 36 |
|
| 37 |
ControlKeyState uint32 |
| 38 |
|
| 39 |
|
| 40 |
EventFlags uint32 |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
type WindowBufferSizeRecord struct { |
| 47 |
|
| 48 |
|
| 49 |
Size windows.Coord |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
func (ir InputRecord) FocusEvent() FocusEventRecord { |
| 54 |
return FocusEventRecord{SetFocus: ir.Event[0] > 0} |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
func (ir InputRecord) KeyEvent() KeyEventRecord { |
| 59 |
return KeyEventRecord{ |
| 60 |
KeyDown: binary.LittleEndian.Uint32(ir.Event[0:4]) > 0, |
| 61 |
RepeatCount: binary.LittleEndian.Uint16(ir.Event[4:6]), |
| 62 |
VirtualKeyCode: binary.LittleEndian.Uint16(ir.Event[6:8]), |
| 63 |
VirtualScanCode: binary.LittleEndian.Uint16(ir.Event[8:10]), |
| 64 |
Char: rune(binary.LittleEndian.Uint16(ir.Event[10:12])), |
| 65 |
ControlKeyState: binary.LittleEndian.Uint32(ir.Event[12:16]), |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
func (ir InputRecord) MouseEvent() MouseEventRecord { |
| 71 |
return MouseEventRecord{ |
| 72 |
MousePositon: windows.Coord{ |
| 73 |
X: int16(binary.LittleEndian.Uint16(ir.Event[0:2])), |
| 74 |
Y: int16(binary.LittleEndian.Uint16(ir.Event[2:4])), |
| 75 |
}, |
| 76 |
ButtonState: binary.LittleEndian.Uint32(ir.Event[4:8]), |
| 77 |
ControlKeyState: binary.LittleEndian.Uint32(ir.Event[8:12]), |
| 78 |
EventFlags: binary.LittleEndian.Uint32(ir.Event[12:16]), |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
func (ir InputRecord) WindowBufferSizeEvent() WindowBufferSizeRecord { |
| 84 |
return WindowBufferSizeRecord{ |
| 85 |
Size: windows.Coord{ |
| 86 |
X: int16(binary.LittleEndian.Uint16(ir.Event[0:2])), |
| 87 |
Y: int16(binary.LittleEndian.Uint16(ir.Event[2:4])), |
| 88 |
}, |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
func (ir InputRecord) MenuEvent() MenuEventRecord { |
| 94 |
return MenuEventRecord{ |
| 95 |
CommandID: binary.LittleEndian.Uint32(ir.Event[0:4]), |
| 96 |
} |
| 97 |
} |