hid

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hid encodes keyboard and mouse input as hidrpc messages (and the JSON-RPC fallbacks where hidrpc has no message type, e.g. the wheel).

Index

Constants

View Source
const (
	LayoutUS = "en-US"
	LayoutUK = "en-UK"
)

Layout names accepted by Type and Keys. Values follow the firmware's keyboard layout ISO codes ("en-US", "en-UK", ...).

View Source
const (
	ModCtrl       byte = 0x01
	ModShift      byte = 0x02
	ModAlt        byte = 0x04
	ModMeta       byte = 0x08
	ModRightCtrl  byte = 0x10
	ModRightShift byte = 0x20
	ModAltGr      byte = 0x40 // AltRight
	ModRightMeta  byte = 0x80
)

USB HID modifier bits (firmware ui/src/keyboardMappings.ts `modifiers`).

Variables

This section is empty.

Functions

func Keys

func Keys(ctx context.Context, d kvm.Device, combos []string, layout string, holdMS int) error

Keys presses each combo in turn ("win+x", "ctrl+alt+Delete", "enter", "f11", "shift"), releasing everything after each one. holdMS is how long each combo is held (0 = default).

func MouseClick

func MouseClick(ctx context.Context, d kvm.Device, p Point, b Button, count int) error

MouseClick moves to p, presses and releases b (count times).

func MouseMove

func MouseMove(ctx context.Context, d kvm.Device, p Point) error

MouseMove moves the absolute pointer.

func MouseScroll

func MouseScroll(ctx context.Context, d kvm.Device, dy, dx int) error

MouseScroll sends wheel detents; positive dy = up. hidrpc has a wheel message type but 0.5.9 does not handle it, so this uses the JSON-RPC wheelReport like the UI.

func Type

func Type(ctx context.Context, d kvm.Device, text string, opt TypeOptions) error

Type types text on the target with correct shift/AltGr handling for the layout. Characters the layout cannot produce are an error before anything is sent. It uses the device-side keyboard macro (as the UI's paste does), so timing does not depend on the network.

Types

type Button

type Button uint8

Button is a mouse button bitmask as sent in pointer reports.

const (
	ButtonLeft   Button = 1
	ButtonRight  Button = 2
	ButtonMiddle Button = 4
)

Mouse buttons.

type Point

type Point struct {
	X, Y          float64
	Normalized    bool
	Width, Height int // screen size in pixels; required when !Normalized
}

Point is an absolute position. If Normalized, X and Y are 0..1 of the screen; otherwise they are pixels of a Width x Height screen.

type TypeOptions

type TypeOptions struct {
	Layout string // "" = ask the device (getKeyboardLayout), else LayoutUS/LayoutUK
	// Delay between characters; 0 = sensible default.
	DelayMS int
}

TypeOptions controls Type.

type UntypableError

type UntypableError struct {
	Layout string
	Chars  []string // quoted runes, in the order they appear
}

UntypableError is returned by Type when the layout cannot produce some of the characters. Nothing has been sent to the device.

func (*UntypableError) Error

func (e *UntypableError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL