keyboard

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WM_KEYDOWN = 0x0100
	WM_KEYUP   = 0x0101
	WM_CHAR    = 0x0102

	MAPVK_VSC_TO_VK = 1
)

Variables

This section is empty.

Functions

func KeyDown

func KeyDown(hwnd uintptr, key Key) error

KeyDown simulates a key down event for the specified window using PostMessage.

func KeyUp

func KeyUp(hwnd uintptr, key Key) error

KeyUp simulates a key up event for the specified window using PostMessage.

func MapScanCodeToVK

func MapScanCodeToVK(sc Key) uintptr

MapScanCodeToVK converts a hardware scan code to a virtual-key code.

func Press

func Press(hwnd uintptr, key Key) error

Press simulates a key press (down then up) for the specified window using PostMessage.

func Type

func Type(hwnd uintptr, text string) error

Type sends text to the specified window using WM_CHAR messages. This is reliable for background input but does not support non-character keys.

Types

type Key

type Key uint16

Key represents a hardware scan code.

const (
	KeyEsc       Key = 0x01
	Key1         Key = 0x02
	Key2         Key = 0x03
	Key3         Key = 0x04
	Key4         Key = 0x05
	Key5         Key = 0x06
	Key6         Key = 0x07
	Key7         Key = 0x08
	Key8         Key = 0x09
	Key9         Key = 0x0A
	Key0         Key = 0x0B
	KeyMinus     Key = 0x0C
	KeyEqual     Key = 0x0D
	KeyBkSp      Key = 0x0E
	KeyTab       Key = 0x0F
	KeyQ         Key = 0x10
	KeyW         Key = 0x11
	KeyE         Key = 0x12
	KeyR         Key = 0x13
	KeyT         Key = 0x14
	KeyY         Key = 0x15
	KeyU         Key = 0x16
	KeyI         Key = 0x17
	KeyO         Key = 0x18
	KeyP         Key = 0x19
	KeyLBr       Key = 0x1A
	KeyRBr       Key = 0x1B
	KeyEnter     Key = 0x1C
	KeyCtrl      Key = 0x1D
	KeyA         Key = 0x1E
	KeyS         Key = 0x1F
	KeyD         Key = 0x20
	KeyF         Key = 0x21
	KeyG         Key = 0x22
	KeyH         Key = 0x23
	KeyJ         Key = 0x24
	KeyK         Key = 0x25
	KeyL         Key = 0x26
	KeySemi      Key = 0x27
	KeyQuot      Key = 0x28
	KeyTick      Key = 0x29
	KeyShift     Key = 0x2A
	KeyBackslash Key = 0x2B
	KeyZ         Key = 0x2C
	KeyX         Key = 0x2D
	KeyC         Key = 0x2E
	KeyV         Key = 0x2F
	KeyB         Key = 0x30
	KeyN         Key = 0x31
	KeyM         Key = 0x32
	KeyComma     Key = 0x33
	KeyDot       Key = 0x34
	KeySlash     Key = 0x35
	KeyAlt       Key = 0x38
	KeySpace     Key = 0x39
	KeyCaps      Key = 0x3A
	KeyF1        Key = 0x3B
	KeyF2        Key = 0x3C
	KeyF3        Key = 0x3D
	KeyF4        Key = 0x3E
	KeyF5        Key = 0x3F
	KeyF6        Key = 0x40
	KeyF7        Key = 0x41
	KeyF8        Key = 0x42
	KeyF9        Key = 0x43
	KeyF10       Key = 0x44
	KeyNumLock   Key = 0x45
	KeyScroll    Key = 0x46
	KeyF11       Key = 0x57
	KeyF12       Key = 0x58

	// Extended Keys
	KeyHome      Key = 0x47
	KeyArrowUp   Key = 0x48
	KeyPageUp    Key = 0x49
	KeyLeft      Key = 0x4B
	KeyRight     Key = 0x4D
	KeyEnd       Key = 0x4F
	KeyArrowDown Key = 0x50
	KeyPageDown  Key = 0x51
	KeyInsert    Key = 0x52
	KeyDelete    Key = 0x53

	KeyRightCtrl Key = 0x1D
	KeyRightAlt  Key = 0x38
	KeyDivide    Key = 0x35
)

func LookupKey

func LookupKey(r rune) (Key, bool, bool)

LookupKey returns the Scan Code and whether Shift is required.

type KeyDef

type KeyDef struct {
	Code    Key
	Shifted bool
}

KeyDef represents a key definition mapping a rune to a scan code.

Jump to

Keyboard shortcuts

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