Documentation
¶
Overview ¶
Package input provides CGEvent-based keyboard and mouse input helpers.
It wraps CoreGraphics CGEvent functions via purego (cgo-free) for creating and posting keyboard and mouse events. Events can be posted to a specific process (e.g., a VM window) or to the system HID event tap.
Basic usage:
ev, err := input.CreateKeyboardEvent(0, input.KeyReturn, true)
if err != nil {
log.Fatal(err)
}
input.PostToSelf(ev)
Index ¶
- Constants
- func CreateKeyboardEvent(source uintptr, virtualKey uint16, keyDown bool) (uintptr, error)
- func CreateMouseEvent(source uintptr, mouseType uint32, position corefoundation.CGPoint, ...) (uintptr, error)
- func Post(tap uint32, event uintptr) error
- func PostToSelf(event uintptr) error
- func SetFlags(event uintptr, flags uint64) error
- func SetUnicodeString(event uintptr, s string) error
- func TypeCharacter(char rune) error
Constants ¶
const ( EventNull = 0 EventLeftMouseDown = 1 EventLeftMouseUp = 2 EventRightMouseDown = 3 EventRightMouseUp = 4 EventMouseMoved = 5 EventKeyDown = 10 EventKeyUp = 11 )
CGEvent mouse and keyboard event types.
const ( KeyReturn = 36 KeyTab = 48 KeySpace = 49 KeyDelete = 51 KeyEscape = 53 )
Common virtual key codes.
const HIDEventTap = 0
HIDEventTap is the location for posting events to the HID system.
Variables ¶
This section is empty.
Functions ¶
func CreateKeyboardEvent ¶
CreateKeyboardEvent creates a keyboard event. virtualKey is the macOS virtual key code (e.g., KeyReturn=36, KeyTab=48).
func CreateMouseEvent ¶
func CreateMouseEvent(source uintptr, mouseType uint32, position corefoundation.CGPoint, mouseButton uint32) (uintptr, error)
CreateMouseEvent creates a mouse event at the given position. The source parameter is typically 0 (no source). mouseType should be one of the Event* mouse constants. mouseButton is 0 for left, 1 for right.
func Post ¶
Post posts an event to the given HID event tap location. Use HIDEventTap for the system HID tap.
func PostToSelf ¶
PostToSelf posts an event to this process. This is useful for directing keystrokes to a VM window owned by the current process rather than whatever app the user has focused.
func SetUnicodeString ¶
SetUnicodeString sets the Unicode string on a keyboard event. This allows typing arbitrary characters that don't have a direct keycode.
func TypeCharacter ¶
TypeCharacter types a single character by creating key down/up events with the character set as a Unicode string. Events are posted to the current process.
Types ¶
This section is empty.