Help us shape the future of Go! Take the 2026 Go Developer Survey

key

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddModifierKey

func AddModifierKey(key Key)

RegisterModifierKey registers a new modifier key.

func IsModifierKey

func IsModifierKey(key Key) bool

IsModifierKey returns true if the key is a modifier key.

func PanValueForKeyPosition

func PanValueForKeyPosition(kp KeyPosition, maxX int) float64

PanValueForKeyPosition returns the pan value for a given key position and maximum X value. The pan value is a float between -1.0 and 1.0, where -1.0 is left and 1.0 is right. The key position is the position of the key on the keyboard, and the maximum X value is the maximum number of contiguous horizontal keys in the keyboard.

func RemoveModifierKey

func RemoveModifierKey(key Key)

RemoveModifierKey removes a modifier key.

Types

type Key

type Key struct {
	// The platform specific code for the key. (VK_* on Windows, KEY_* on Linux)
	Code uint32
	// The name of the key.
	Name string
	// The platform to which the key code belongs.
	Platform string
}

Key represents a key on a keyboard.

var (
	Backspace      Key = Key{14, "Backspace", runtime.GOOS}
	Tab            Key = Key{15, "Tab", runtime.GOOS}
	Enter          Key = Key{28, "Enter", runtime.GOOS}
	Escape         Key = Key{1, "Escape", runtime.GOOS}
	Space          Key = Key{57, "Space", runtime.GOOS}
	PageUp         Key = Key{104, "PageUp", runtime.GOOS}
	PageDown       Key = Key{109, "PageDown", runtime.GOOS}
	End            Key = Key{107, "End", runtime.GOOS}
	Home           Key = Key{102, "Home", runtime.GOOS}
	Left           Key = Key{105, "Left", runtime.GOOS}
	Up             Key = Key{103, "Up", runtime.GOOS}
	Right          Key = Key{106, "Right", runtime.GOOS}
	Down           Key = Key{108, "Down", runtime.GOOS}
	Insert         Key = Key{110, "Insert", runtime.GOOS}
	Delete         Key = Key{111, "Delete", runtime.GOOS}
	Number0        Key = Key{11, "0", runtime.GOOS}
	Number1        Key = Key{2, "1", runtime.GOOS}
	Number2        Key = Key{3, "2", runtime.GOOS}
	Number3        Key = Key{4, "3", runtime.GOOS}
	Number4        Key = Key{5, "4", runtime.GOOS}
	Number5        Key = Key{6, "5", runtime.GOOS}
	Number6        Key = Key{7, "6", runtime.GOOS}
	Number7        Key = Key{8, "7", runtime.GOOS}
	Number8        Key = Key{9, "8", runtime.GOOS}
	Number9        Key = Key{10, "9", runtime.GOOS}
	A              Key = Key{30, "A", runtime.GOOS}
	B              Key = Key{48, "B", runtime.GOOS}
	C              Key = Key{46, "C", runtime.GOOS}
	D              Key = Key{32, "D", runtime.GOOS}
	E              Key = Key{18, "E", runtime.GOOS}
	F              Key = Key{33, "F", runtime.GOOS}
	G              Key = Key{34, "G", runtime.GOOS}
	H              Key = Key{35, "H", runtime.GOOS}
	I              Key = Key{23, "I", runtime.GOOS}
	J              Key = Key{36, "J", runtime.GOOS}
	K              Key = Key{37, "K", runtime.GOOS}
	L              Key = Key{38, "L", runtime.GOOS}
	M              Key = Key{50, "M", runtime.GOOS}
	N              Key = Key{49, "N", runtime.GOOS}
	O              Key = Key{24, "O", runtime.GOOS}
	P              Key = Key{25, "P", runtime.GOOS}
	Q              Key = Key{16, "Q", runtime.GOOS}
	R              Key = Key{19, "R", runtime.GOOS}
	S              Key = Key{31, "S", runtime.GOOS}
	T              Key = Key{20, "T", runtime.GOOS}
	U              Key = Key{22, "U", runtime.GOOS}
	V              Key = Key{47, "V", runtime.GOOS}
	W              Key = Key{17, "W", runtime.GOOS}
	X              Key = Key{45, "X", runtime.GOOS}
	Y              Key = Key{21, "Y", runtime.GOOS}
	Z              Key = Key{44, "Z", runtime.GOOS}
	LeftWin        Key = Key{125, "LeftWin", runtime.GOOS}
	RightWin       Key = Key{126, "RightWin", runtime.GOOS}
	NumPad0        Key = Key{82, "Num0", runtime.GOOS}
	NumPad1        Key = Key{79, "Num1", runtime.GOOS}
	NumPad2        Key = Key{80, "Num2", runtime.GOOS}
	NumPad3        Key = Key{81, "Num3", runtime.GOOS}
	NumPad4        Key = Key{75, "Num4", runtime.GOOS}
	NumPad5        Key = Key{76, "Num5", runtime.GOOS}
	NumPad6        Key = Key{77, "Num6", runtime.GOOS}
	NumPad7        Key = Key{71, "Num7", runtime.GOOS}
	NumPad8        Key = Key{72, "Num8", runtime.GOOS}
	NumPad9        Key = Key{73, "Num9", runtime.GOOS}
	NumPadMultiply Key = Key{55, "*", runtime.GOOS}
	NumPadAdd      Key = Key{78, "+", runtime.GOOS}
	NumPadSubtract Key = Key{74, "-", runtime.GOOS}
	NumPadDecimal  Key = Key{83, ".", runtime.GOOS}
	NumPadDivide   Key = Key{98, "/", runtime.GOOS}
	F1             Key = Key{59, "F1", runtime.GOOS}
	F2             Key = Key{60, "F2", runtime.GOOS}
	F3             Key = Key{61, "F3", runtime.GOOS}
	F4             Key = Key{62, "F4", runtime.GOOS}
	F5             Key = Key{63, "F5", runtime.GOOS}
	F6             Key = Key{64, "F6", runtime.GOOS}
	F7             Key = Key{65, "F7", runtime.GOOS}
	F8             Key = Key{66, "F8", runtime.GOOS}
	F9             Key = Key{67, "F9", runtime.GOOS}
	F10            Key = Key{68, "F10", runtime.GOOS}
	F11            Key = Key{87, "F11", runtime.GOOS}
	F12            Key = Key{88, "F12", runtime.GOOS}
	F13            Key = Key{183, "F13", runtime.GOOS}
	F14            Key = Key{184, "F14", runtime.GOOS}
	F15            Key = Key{185, "F15", runtime.GOOS}
	F16            Key = Key{186, "F16", runtime.GOOS}
	F17            Key = Key{187, "F17", runtime.GOOS}
	F18            Key = Key{188, "F18", runtime.GOOS}
	F19            Key = Key{189, "F19", runtime.GOOS}
	F20            Key = Key{190, "F20", runtime.GOOS}
	F21            Key = Key{191, "F21", runtime.GOOS}
	F22            Key = Key{192, "F22", runtime.GOOS}
	F23            Key = Key{193, "F23", runtime.GOOS}
	F24            Key = Key{194, "F24", runtime.GOOS}
	NumLock        Key = Key{69, "NumLock", runtime.GOOS}
	ScrollLock     Key = Key{70, "ScrollLock", runtime.GOOS}
	LeftShift      Key = Key{42, "LeftShift", runtime.GOOS}
	RightShift     Key = Key{54, "RightShift", runtime.GOOS}
	LeftControl    Key = Key{29, "LeftControl", runtime.GOOS}
	RightControl   Key = Key{97, "RightControl", runtime.GOOS}
	LeftAlt        Key = Key{56, "LeftAlt", runtime.GOOS}
	RightAlt       Key = Key{100, "RightAlt", runtime.GOOS}
	Backtick       Key = Key{41, "`", runtime.GOOS}
	LeftBracket    Key = Key{26, "[", runtime.GOOS}
	RightBracket   Key = Key{27, "]", runtime.GOOS}
	Backslash      Key = Key{43, "\\", runtime.GOOS}
	SemiColon      Key = Key{39, ";", runtime.GOOS}
	CapsLock       Key = Key{58, "CapsLock", runtime.GOOS}
	Plus           Key = Key{13, "+", runtime.GOOS}
	Comma          Key = Key{51, ",", runtime.GOOS}
	Minus          Key = Key{12, "-", runtime.GOOS}
	Period         Key = Key{52, ".", runtime.GOOS}
	Slash          Key = Key{53, "/", runtime.GOOS}
	Quote          Key = Key{40, "'", runtime.GOOS}
)

func FindKey

func FindKey(val string) (Key, bool)

FindKey returns a Key based on the name and a bool indicating if the key was found.

func FindKeyCode

func FindKeyCode(val uint32) Key

FindKeyCode returns a Key based on the platform specific code. If the key is not found, it returns a Key with the provided code and no name.

func ListModifierKeys

func ListModifierKeys() []Key

ListModifierKeys returns a list of all modifier keys.

func (Key) Equals

func (k Key) Equals(other Key) bool

Equals returns true if the key codes are equal.

func (Key) GetPosition

func (k Key) GetPosition() *KeyPosition

GetPosition returns the position of the key on the keyboard.

type KeyPosition

type KeyPosition struct {
	X, Y int
}

KeyPosition represents the position of a key on a keyboard.

Jump to

Keyboard shortcuts

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