engine: azul3d.org/engine/keyboard Index | Files

package keyboard

import "azul3d.org/engine/keyboard"

Package keyboard implements various keyboard related data types.

Index

Package Files

doc.go events.go keys.go state.go stringers.go watcher.go

type ButtonEvent Uses

type ButtonEvent struct {
    T     time.Time
    Key   Key
    State State
    Raw   uint64
}

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 (ButtonEvent) String Uses

func (b ButtonEvent) String() string

String returns an string representation of this event.

func (ButtonEvent) Time Uses

func (b ButtonEvent) Time() time.Time

Time returns the time at which this event occured.

type Key Uses

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.

func (Key) String Uses

func (i Key) String() string

type State Uses

type State uint8

State represents a single keyboard key state.

const (
    InvalidState State = iota
    Down
    Up
)

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.

func (State) String Uses

func (i State) String() string

type Typed Uses

type Typed struct {
    T   time.Time
    S   string
}

Typed represents an event where some sort of user input has generated a string of text which should be considered as user input.

func (Typed) String Uses

func (t Typed) String() string

String simply returns the user input string.

func (Typed) Time Uses

func (t Typed) Time() time.Time

Time returns the time at which this event occured.

type Watcher Uses

type Watcher struct {
    // contains filtered or unexported fields
}

Watcher watches the state of various keyboard keys.

func NewWatcher Uses

func NewWatcher() *Watcher

NewWatcher returns a new, initialized, watcher.

func (*Watcher) Down Uses

func (w *Watcher) Down(k Key) bool

Down tells whether the specified key is currently in the down state.

func (*Watcher) EachState Uses

func (w *Watcher) EachState(f func(k Key, s State) bool)

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 Uses

func (w *Watcher) RawDown(raw uint64) bool

RawDown tells whether the specified raw key value is currently in the down state.

func (*Watcher) RawState Uses

func (w *Watcher) RawState(raw uint64) State

RawState returns the current state of the specified raw key value.

func (*Watcher) RawStates Uses

func (w *Watcher) RawStates() map[uint64]State

RawStates returns an copy of the internal raw key state map used by this watcher.

func (*Watcher) RawUp Uses

func (w *Watcher) RawUp(raw uint64) bool

RawUp tells whether the specified raw key value is currently in the up state.

func (*Watcher) SetRawState Uses

func (w *Watcher) SetRawState(raw uint64, s State)

SetRawState specifies the current state of the specified raw key value.

func (*Watcher) SetState Uses

func (w *Watcher) SetState(k Key, s State)

SetState specifies the current state of the specified key.

func (*Watcher) State Uses

func (w *Watcher) State(k Key) State

State returns the current state of the specified key.

func (*Watcher) States Uses

func (w *Watcher) States() map[Key]State

States returns an copy of the internal key state map used by this watcher.

func (*Watcher) String Uses

func (w *Watcher) String() string

String returns a multi-line string representation of this keyboard watcher and it's associated states (but not raw ones).

func (*Watcher) Up Uses

func (w *Watcher) Up(k Key) bool

Up tells whether the specified key is currently in the up state.

Package keyboard imports 4 packages (graph) and is imported by 17 packages. Updated 2017-08-26. Refresh now. Tools for package owners.