Documentation
¶
Overview ¶
Package keyboard implements various keyboard related data types.
Index ¶
- func IsAlphaNumeric(k Key) bool
- func IsFunctionKey(k Key) bool
- func IsModifierKey(k Key) bool
- func IsNavigationKey(k Key) bool
- type ButtonEvent
- type Event
- type Key
- type State
- type Typed
- type Watcher
- func (w *Watcher) Down(k Key) bool
- func (w *Watcher) EachState(f func(k Key, s State) bool)
- func (w *Watcher) RawDown(raw uint64) bool
- func (w *Watcher) RawState(raw uint64) State
- func (w *Watcher) RawStates() map[uint64]State
- func (w *Watcher) RawUp(raw uint64) bool
- func (w *Watcher) SetRawState(raw uint64, s State)
- func (w *Watcher) SetState(k Key, s State)
- func (w *Watcher) State(k Key) State
- func (w *Watcher) States() map[Key]State
- func (w *Watcher) String() string
- func (w *Watcher) Up(k Key) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAlphaNumeric ¶
IsAlphaNumeric returns true if the key is a letter or number
func IsFunctionKey ¶
IsFunctionKey returns true if the key is a function key (F1-F25)
func IsModifierKey ¶
IsModifierKey returns true if the key is a modifier key (Shift, Ctrl, Alt, Super)
func IsNavigationKey ¶
IsNavigationKey returns true if the key is used for navigation (arrows, page up/down, etc.)
Types ¶
type ButtonEvent ¶
ButtonEvent represents an event when a keyboard button changes state (i.e. being pushed down when it was previously up, or being toggled on when it was previously off, etc)
If Key == Invalid then the key may not be known, but it can still be uniquely identified and it's state watched via the Raw member (e.g. for special or non-US keys).
The Raw member must uniquely identify the keyboard button whose state is changing, and must always be present regardless of whether or not Key == Invalid. It could (but does not have to be) e.g. the scancode of the key.
func NewButtonEvent ¶
func NewButtonEvent(key Key, state State, raw uint64) ButtonEvent
NewButtonEvent creates a new ButtonEvent with the current time
func (ButtonEvent) String ¶
func (b ButtonEvent) String() string
String returns a string representation of this event.
func (ButtonEvent) Time ¶
func (b ButtonEvent) Time() time.Time
Time returns the time at which this event occurred.
type Event ¶
type Event interface {
// Time returns the time at which this event occurred
Time() time.Time
// String returns a string representation of this event
String() string
}
Event represents a general keyboard event interface
type Key ¶
type Key int
Key represents an single keyboard button.
It should be noted that it does not represent an character that pressing an keyboard button would otherwise generate (hence you will find no capital keys defined).
const ( Invalid Key = iota Tilde // "~" Dash // "-" Equals // "=" Semicolon // ";" Apostrophe // "'" Comma // "," Period // "." ForwardSlash // "/" BackSlash // "\" Backspace Tab // "\t" CapsLock Space // " " Enter // "\r", "\n", "\r\n" Escape Insert PrintScreen Delete PageUp PageDown Home End Pause Sleep Clear Select Print Execute Help Applications ScrollLock Play Zoom // Arrow keys ArrowLeft ArrowRight ArrowDown ArrowUp // Lefties LeftBracket // [ LeftShift LeftCtrl LeftSuper LeftAlt // Righties RightBracket // ] RightShift RightCtrl RightSuper RightAlt // Numbers Zero // "0" One // "1" Two // "2" Three // "3" Four // "4" Five // "5" Six // "6" Seven // "7" Eight // "8" Nine // "9" // Functions F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 // English characters A // "a" B // "b" C // "c" D // "d" E // "e" F // "f" G // "g" H // "h" I // "i" J // "j" K // "k" L // "l" M // "m" N // "n" O // "o" P // "p" Q // "q" R // "r" S // "s" T // "t" U // "u" V // "v" W // "w" X // "x" Y // "y" Z // "z" // Number pads NumLock NumMultiply // "*" NumDivide // "/" NumAdd // "+" NumSubtract // "-" NumZero // "0" NumOne // "1" NumTwo // "2" NumThree // "3" NumFour // "4" NumFive // "5" NumSix // "6" NumSeven // "7" NumEight // "8" NumNine // "9" NumDecimal // "." NumComma // "," NumEnter // Browser key buttons. BrowserBack BrowserForward BrowserRefresh BrowserStop BrowserSearch BrowserFavorites BrowserHome // Media key buttons. MediaNext MediaPrevious MediaStop MediaPlayPause // Launcher key buttons. LaunchMail LaunchMedia LaunchAppOne LaunchAppTwo // Expanded int. key buttons. Kana Kanji Junja Attn CrSel ExSel EraseEOF )
Keyboard key constants. These are just for button state detection -- not for representing a character / text input being generated by pressing a key (for that, use TypedEvent).
The buttons are mapped onto a traditional U.S. keyboard layout, which you can find a diagram of here:
http://en.wikipedia.org/wiki/File:KB_United_States-NoAltGr.svg
The Invalid key is defined strictly to allow users to detect uninitialized variables.
type State ¶
type State uint8
State represents a single keyboard key state.
Keyboard key state constants, Down implies the key is currently pressed down, and up implies it is not. The InvalidState is declared to help users detect uninitialized variables.
type Typed ¶
Typed represents an event where some sort of user input has generated a string of text which should be considered as user input.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches the state of various keyboard keys.
func (*Watcher) EachState ¶
EachState calls f with each known key to this watcher and it's current key state. It does so until the function returns false or there are no more keys known to the watcher.
func (*Watcher) RawDown ¶
RawDown tells whether the specified raw key value is currently in the down state.
func (*Watcher) RawStates ¶
RawStates returns an copy of the internal raw key state map used by this watcher.
func (*Watcher) RawUp ¶
RawUp tells whether the specified raw key value is currently in the up state.
func (*Watcher) SetRawState ¶
SetRawState specifies the current state of the specified raw key value.