Documentation
¶
Overview ¶
Package input carries keyboard, mouse, and gamepad input from the client to the host: a fixed binary wire format, key code tables, and host injectors.
Index ¶
- Constants
- Variables
- func EvdevFromHID(usage uint16) (uint16, bool)
- func HIDFromEvdev(code uint16) (uint16, bool)
- func HIDFromMac(keyCode uint16) (uint16, bool)
- func HIDFromWindows(vk uint16, extended bool) (uint16, bool)
- func IsSecureAttention(ev Event) bool
- func KeyByName(name string) (uint16, bool)
- func KeyName(usage uint16) string
- func MacFromHID(usage uint16) (uint16, bool)
- func SendSAS() error
- func SwapsCmdCtrl(clientOS, hostOS string) bool
- func WindowsFromHID(usage uint16) (vk uint16, extended bool, ok bool)
- type Button
- type Event
- type GamepadState
- type Held
- type Injector
- type KeyEvent
- type LinuxInjector
- func (l *LinuxInjector) Backend() string
- func (l *LinuxInjector) Close() error
- func (l *LinuxInjector) Gamepads() (*gamepad.VirtualPads, error)
- func (l *LinuxInjector) Inject(ev Event) error
- func (l *LinuxInjector) SetGamepadType(t gamepad.PadType)
- func (l *LinuxInjector) SetTarget(display, desktop Rect)
- type MouseButton
- type MouseMoveAbs
- type MouseMoveRel
- type MouseWheel
- type Rect
- type RumbleEvent
- type SendTracer
- type SentMouse
- type Targeter
- type Type
Constants ¶
const ( PadDPadUp = gamepad.ButtonDPadUp PadDPadDown = gamepad.ButtonDPadDown PadDPadLeft = gamepad.ButtonDPadLeft PadDPadRight = gamepad.ButtonDPadRight PadStart = gamepad.ButtonStart PadBack = gamepad.ButtonBack PadLeftThumb = gamepad.ButtonLeftThumb PadRightThumb = gamepad.ButtonRightThumb PadLeftShoulder = gamepad.ButtonLeftShoulder PadRightShoulder = gamepad.ButtonRightShoulder PadGuide = gamepad.ButtonGuide PadA = gamepad.ButtonA PadB = gamepad.ButtonB PadX = gamepad.ButtonX PadY = gamepad.ButtonY )
Gamepad buttons use the XInput bit layout, plus Guide.
const ( KeyA uint16 = 0x04 + iota KeyB KeyC KeyD KeyE KeyF KeyG KeyH KeyI KeyJ KeyK KeyL KeyM KeyN KeyO KeyP KeyQ KeyR KeyS KeyT KeyU KeyV KeyW KeyX KeyY KeyZ Key1 Key2 Key3 Key4 Key5 Key6 Key7 Key8 Key9 Key0 KeyEnter KeyEscape KeyBackspace KeyTab KeySpace KeyMinus KeyEqual KeyLeftBracket KeyRightBracket KeyBackslash KeyNonUSHash KeySemicolon KeyQuote KeyGrave KeyComma KeyPeriod KeySlash KeyCapsLock KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyPrintScreen KeyScrollLock KeyPause KeyInsert KeyHome KeyPageUp KeyDelete KeyEnd KeyPageDown KeyRight KeyLeft KeyDown KeyUp KeyNumLock KeyKPDivide KeyKPMultiply KeyKPMinus KeyKPPlus KeyKPEnter KeyKP1 KeyKP2 KeyKP3 KeyKP4 KeyKP5 KeyKP6 KeyKP7 KeyKP8 KeyKP9 KeyKP0 KeyKPDecimal KeyNonUSBackslash KeyApplication KeyPower KeyKPEqual KeyF13 KeyF14 KeyF15 KeyF16 KeyF17 KeyF18 KeyF19 KeyF20 KeyF21 KeyF22 KeyF23 KeyF24 )
Key codes are USB HID usages from the Keyboard/Keypad page (0x07), the one key vocabulary every client and host maps through.
const ( KeyMute uint16 = 0x7F KeyVolumeUp uint16 = 0x80 KeyVolumeDown uint16 = 0x81 KeyKPComma uint16 = 0x85 KeyInternational1 uint16 = 0x87 // JIS Ro KeyInternational3 uint16 = 0x89 // JIS Yen KeyInternational4 uint16 = 0x8A // JIS Henkan KeyInternational5 uint16 = 0x8B // JIS Muhenkan KeyLang1 uint16 = 0x90 // Hangul, Mac Kana KeyLang2 uint16 = 0x91 // Hanja, Mac Eisu KeyLeftControl uint16 = 0xE0 KeyLeftShift uint16 = 0xE1 KeyLeftAlt uint16 = 0xE2 KeyLeftGUI uint16 = 0xE3 KeyRightControl uint16 = 0xE4 KeyRightShift uint16 = 0xE5 KeyRightAlt uint16 = 0xE6 KeyRightGUI uint16 = 0xE7 )
const ( ModLeftControl uint8 = 1 << iota ModLeftShift ModLeftAlt ModLeftGUI ModRightControl ModRightShift ModRightAlt ModRightGUI )
Modifier bits, in HID boot-report order.
const ( BackendUinput = "uinput" BackendXTest = "xtest" BackendPortal = "portal" )
Backend names of the Linux injector.
const InjectMarker = 0x504C4E4B // "PLNK"
InjectMarker tags the keys a host injects (dwExtraInfo on Windows, the event source's user data on macOS), so that a client capturing the system's keys on the same machine leaves them alone rather than sending them back to the host.
const MaxEventSize = 16
MaxEventSize is the largest encoded event in bytes.
const MaxGamepads = 16
const WheelNotch = 120
WheelNotch is one detent of a standard mouse wheel; finer values come from high-resolution wheels and trackpads.
Variables ¶
var ( ErrShortBuffer = errors.New("input: short buffer") ErrInvalid = errors.New("input: invalid event") )
var ErrUnsupported = errors.New("input: unsupported on this host")
ErrUnsupported is returned for events the host cannot inject, such as gamepads with no virtual controller driver or host-bound rumble.
Functions ¶
func EvdevFromHID ¶ added in v0.2.0
EvdevFromHID maps a HID usage to a Linux evdev key code.
func HIDFromEvdev ¶ added in v0.2.0
HIDFromEvdev maps a Linux evdev key code to a HID usage.
func HIDFromMac ¶
HIDFromMac maps a macOS virtual key code to a HID usage.
func HIDFromWindows ¶
HIDFromWindows maps a Windows virtual-key code and its extended-key flag to a HID usage. When the exact pair is unknown, the flag is ignored, since APIs disagree on it for some keys (NumLock, Pause).
func IsSecureAttention ¶
IsSecureAttention reports whether ev is Delete going down with Ctrl and Alt held, on either side: Ctrl+Alt+Del.
func KeyName ¶
KeyName is the chord name of the key with this HID usage, "" for a key chords cannot name, modifiers among them.
func MacFromHID ¶
MacFromHID maps a HID usage to a macOS virtual key code.
func SendSAS ¶
func SendSAS() error
SendSAS is Windows' secure attention sequence; other systems have none.
func SwapsCmdCtrl ¶
SwapsCmdCtrl reports whether a Cmd and Ctrl swap between a client and a host on these GOOS values does anything: one is macOS and the other not.
Types ¶
type Event ¶
type Event struct {
Type Type
Key KeyEvent
MouseAbs MouseMoveAbs
MouseRel MouseMoveRel
Button MouseButton
Wheel MouseWheel
Gamepad GamepadState
Rumble RumbleEvent
}
Event is one input event of any Type. Only the field matching Type is meaningful; a tagged struct rather than an interface keeps encoding and decoding free of allocations.
func CtrlAltDel ¶
CtrlAltDel is the key events of Ctrl+Alt+Del pressed and let go, over what held already has down, which stays down.
func SwapCmdCtrl ¶
SwapCmdCtrl is ev with Ctrl and the GUI key (Cmd, Windows) traded, on each side: the key itself and the modifiers it carries.
type GamepadState ¶
type GamepadState struct {
Index uint8
Buttons uint32
LeftTrigger, RightTrigger uint8
LeftX, LeftY int16
RightX, RightY int16
}
GamepadState is the full state of one controller. Stick axes are signed with positive X right and positive Y up, as in XInput.
type Held ¶
type Held struct {
// contains filtered or unexported fields
}
Held tracks the keys and mouse buttons a host injected down and not up, to let go of them when the client that pressed them is gone: a client that drops mid Alt-Tab must not leave Alt down on the host.
type Injector ¶
Injector replays client input on the host. Implementations post real OS events; tests must not call them unless PLANCK_LIVE_INPUT_TEST=1.
type KeyEvent ¶
type KeyEvent struct {
Usage uint16 // HID usage, page 0x07
Pressed bool
Modifiers uint8 // Mod* bits held once this event has taken effect
// SystemKeyCapture is set when the client captured a key combination
// its own OS would otherwise act on (Cmd-Tab, Alt-Tab, the Windows key).
SystemKeyCapture bool
}
KeyEvent is one key going down or up.
type LinuxInjector ¶ added in v0.2.0
type LinuxInjector struct {
// contains filtered or unexported fields
}
LinuxInjector injects keyboard and mouse input on a Linux host through /dev/uinput, X11 XTest or the RemoteDesktop portal, whichever opens first (see backendOrder), and plugs gamepads into virtual controllers.
func NewInjector ¶ added in v0.2.0
func NewInjector() (*LinuxInjector, error)
NewInjector opens the first injection backend that works. Set PLANCK_INJECT_BACKEND to uinput, xtest or portal to use only that one.
func (*LinuxInjector) Backend ¶ added in v0.2.0
func (l *LinuxInjector) Backend() string
Backend names the stack in use: BackendUinput, BackendXTest or BackendPortal.
func (*LinuxInjector) Close ¶ added in v0.2.0
func (l *LinuxInjector) Close() error
Close destroys the virtual devices and closes the controllers.
func (*LinuxInjector) Gamepads ¶ added in v0.2.0
func (l *LinuxInjector) Gamepads() (*gamepad.VirtualPads, error)
Gamepads opens the virtual controllers on first use, for slot management and rumble. A failed open is kept.
func (*LinuxInjector) Inject ¶ added in v0.2.0
func (l *LinuxInjector) Inject(ev Event) error
func (*LinuxInjector) SetGamepadType ¶ added in v0.2.0
func (l *LinuxInjector) SetGamepadType(t gamepad.PadType)
SetGamepadType sets what virtual controllers appear as.
func (*LinuxInjector) SetTarget ¶ added in v0.2.0
func (l *LinuxInjector) SetTarget(display, desktop Rect)
SetTarget makes absolute moves cover display, within the desktop of every display. A zero display goes back to the primary one.
type MouseButton ¶
type MouseMoveAbs ¶
type MouseMoveAbs struct{ X, Y uint16 }
MouseMoveAbs is a pointer position normalized over the streamed display: 0 is the left or top edge and 65535 the right or bottom edge.
type MouseMoveRel ¶
type MouseMoveRel struct{ DX, DY int16 }
type MouseWheel ¶
type MouseWheel struct{ DX, DY int16 }
MouseWheel scrolls in WheelNotch units; positive DY scrolls up (away from the user) and positive DX scrolls right.
type Rect ¶
type Rect struct{ X, Y, W, H int }
Rect is a display's place on the host's desktop, in physical pixels.
type RumbleEvent ¶
RumbleEvent travels host to client: motor strengths for one controller.
type SendTracer ¶ added in v0.2.1
SendTracer is an injector that reports each mouse event it posts to f while on reports true, on the goroutine that injects, for input traces. on is called for each event, so it should be an atomic load. Set it before the first Inject.
type SentMouse ¶ added in v0.2.1
type SentMouse struct {
Flags uint32 `json:"flags"`
DX int32 `json:"dx"`
DY int32 `json:"dy"`
MouseData uint32 `json:"mouse_data"`
Err string `json:"err,omitempty"`
}
SentMouse is one mouse event an injector posted, as the system call took it: SendInput's MOUSEINPUT on Windows.