|
5 | 5 | package windows
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "encoding/binary" |
8 | 9 | "net"
|
9 | 10 | "syscall"
|
10 | 11 | "unsafe"
|
@@ -3561,3 +3562,50 @@ type InputRecord struct {
|
3561 | 3562 | // Event holds the actual event data.
|
3562 | 3563 | Event [16]byte
|
3563 | 3564 | }
|
| 3565 | + |
| 3566 | +// FocusEvent returns the event as a FOCUS_EVENT_RECORD. |
| 3567 | +func (ir InputRecord) FocusEvent() FocusEventRecord { |
| 3568 | + return FocusEventRecord{SetFocus: ir.Event[0] > 0} |
| 3569 | +} |
| 3570 | + |
| 3571 | +// KeyEvent returns the event as a KEY_EVENT_RECORD. |
| 3572 | +func (ir InputRecord) KeyEvent() KeyEventRecord { |
| 3573 | + return KeyEventRecord{ |
| 3574 | + KeyDown: binary.LittleEndian.Uint32(ir.Event[0:4]) > 0, |
| 3575 | + RepeatCount: binary.LittleEndian.Uint16(ir.Event[4:6]), |
| 3576 | + VirtualKeyCode: binary.LittleEndian.Uint16(ir.Event[6:8]), |
| 3577 | + VirtualScanCode: binary.LittleEndian.Uint16(ir.Event[8:10]), |
| 3578 | + Char: rune(binary.LittleEndian.Uint16(ir.Event[10:12])), |
| 3579 | + ControlKeyState: binary.LittleEndian.Uint32(ir.Event[12:16]), |
| 3580 | + } |
| 3581 | +} |
| 3582 | + |
| 3583 | +// MouseEvent returns the event as a MOUSE_EVENT_RECORD. |
| 3584 | +func (ir InputRecord) MouseEvent() MouseEventRecord { |
| 3585 | + return MouseEventRecord{ |
| 3586 | + MousePositon: Coord{ |
| 3587 | + X: int16(binary.LittleEndian.Uint16(ir.Event[0:2])), |
| 3588 | + Y: int16(binary.LittleEndian.Uint16(ir.Event[2:4])), |
| 3589 | + }, |
| 3590 | + ButtonState: binary.LittleEndian.Uint32(ir.Event[4:8]), |
| 3591 | + ControlKeyState: binary.LittleEndian.Uint32(ir.Event[8:12]), |
| 3592 | + EventFlags: binary.LittleEndian.Uint32(ir.Event[12:16]), |
| 3593 | + } |
| 3594 | +} |
| 3595 | + |
| 3596 | +// WindowBufferSizeEvent returns the event as a WINDOW_BUFFER_SIZE_RECORD. |
| 3597 | +func (ir InputRecord) WindowBufferSizeEvent() WindowBufferSizeRecord { |
| 3598 | + return WindowBufferSizeRecord{ |
| 3599 | + Size: Coord{ |
| 3600 | + X: int16(binary.LittleEndian.Uint16(ir.Event[0:2])), |
| 3601 | + Y: int16(binary.LittleEndian.Uint16(ir.Event[2:4])), |
| 3602 | + }, |
| 3603 | + } |
| 3604 | +} |
| 3605 | + |
| 3606 | +// MenuEvent returns the event as a MENU_EVENT_RECORD. |
| 3607 | +func (ir InputRecord) MenuEvent() MenuEventRecord { |
| 3608 | + return MenuEventRecord{ |
| 3609 | + CommandID: binary.LittleEndian.Uint32(ir.Event[0:4]), |
| 3610 | + } |
| 3611 | +} |
0 commit comments