input

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const PollingRate = 12 * time.Millisecond

Variables

View Source
var IsKeyJustPressed = inpututil.IsKeyJustPressed
View Source
var IsKeyPressed = ebiten.IsKeyPressed

Functions

func KeyToName added in v0.3.1

func KeyToName(k Key) string

https://go.dev/play/p/H8IQTm5BEBp

func KeysToNames added in v0.3.1

func KeysToNames(keys []Key) []string

func ToVirtualKey

func ToVirtualKey(k Key) uint32

See https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes for reference. Alt, Shift, and Control has 3 codes: overall, left and right. Order of ArrowKeys are different between Ebiten and Windows VK. Order of Page Up/Down are different between Ebiten and Windows VK. KeyNumpadEnter returns VK_RETURN, while main Enter returns the same. KeyReserved0 ~ KeyReserved3 are skipped. Supposed KeyContextMenu stands for Applications key, which is next to Right control Supposed KeyMeta Left and Right stands for Left and Right Windows key. Supposed KeyNumpadEqual returns VK_OEM_PLUS. I guess this is derived from Apple Keyboard.

Types

type Key

type Key = ebiten.Key

type Key int

const (
	KeyA Key = iota
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ
	KeyAltLeft
	KeyAltRight
	KeyArrowDown
	KeyArrowLeft
	KeyArrowRight
	KeyArrowUp
	KeyBackquote
	KeyBackslash
	KeyBackspace
	KeyBracketLeft
	KeyBracketRight
	KeyCapsLock
	KeyComma
	KeyContextMenu
	KeyControlLeft
	KeyControlRight
	KeyDelete
	KeyDigit0
	KeyDigit1
	KeyDigit2
	KeyDigit3
	KeyDigit4
	KeyDigit5
	KeyDigit6
	KeyDigit7
	KeyDigit8
	KeyDigit9
	KeyEnd
	KeyEnter
	KeyEqual
	KeyEscape
	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
	KeyHome
	KeyInsert
	KeyMetaLeft
	KeyMetaRight
	KeyMinus
	KeyNumLock
	KeyNumpad0
	KeyNumpad1
	KeyNumpad2
	KeyNumpad3
	KeyNumpad4
	KeyNumpad5
	KeyNumpad6
	KeyNumpad7
	KeyNumpad8
	KeyNumpad9
	KeyNumpadAdd
	KeyNumpadDecimal
	KeyNumpadDivide
	KeyNumpadEnter
	KeyNumpadEqual
	KeyNumpadMultiply
	KeyNumpadSubtract
	KeyPageDown
	KeyPageUp
	KeyPause
	KeyPeriod
	KeyPrintScreen
	KeyQuote
	KeyScrollLock
	KeySemicolon
	KeyShiftLeft
	KeyShiftRight
	KeySlash
	KeySpace
	KeyTab
	KeyReserved0
	KeyReserved1
	KeyReserved2
	KeyReserved3
)

The order is consistent with Ebiten.

const KeyNone Key = -1

func NamesToKeys

func NamesToKeys(names []string) []Key

type KeyActionType added in v0.6.0

type KeyActionType int
const (
	Idle KeyActionType = iota
	Hit
	Release
	Hold
)

func KeyAction

func KeyAction(last, current bool) KeyActionType

func KeyActions added in v0.6.0

func KeyActions(last, current []bool) []KeyActionType

type Keyboard added in v0.6.0

type Keyboard struct {
	KeyboardReader
	// contains filtered or unexported fields
}

No additional adjustment for keyboard when offset has changed. Both music and keyboard cannot seek at precise position once they start.

func NewKeyboard added in v0.6.0

func NewKeyboard(keys []Key, startTime time.Time) *Keyboard

func (*Keyboard) Close added in v0.6.0

func (kb *Keyboard) Close()

func (*Keyboard) Listen added in v0.6.0

func (kb *Keyboard) Listen()

func (*Keyboard) Pause added in v0.6.0

func (kb *Keyboard) Pause()

func (*Keyboard) Resume added in v0.6.0

func (kb *Keyboard) Resume()

type KeyboardAction added in v0.6.0

type KeyboardAction struct {
	Time       int32
	KeyActions []KeyActionType
}

KeyboardAction is for handling keyboard states conveniently.

type KeyboardReader added in v0.6.0

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

func NewKeyboardReader added in v0.6.0

func NewKeyboardReader(states []KeyboardState) KeyboardReader

func (KeyboardReader) IsEmpty added in v0.6.0

func (kb KeyboardReader) IsEmpty() bool

No worry of accessing with nil pointer. https://go.dev/play/p/B4Z1LwQC_jP

func (KeyboardReader) Output added in v0.6.0

func (kb KeyboardReader) Output() []KeyboardState

func (*KeyboardReader) Read added in v0.6.0

func (kb *KeyboardReader) Read(now int32) []KeyboardAction

func (*KeyboardReader) Tidy added in v0.6.0

func (kb *KeyboardReader) Tidy()

Tidy removes redundant states.

type KeyboardState added in v0.6.0

type KeyboardState struct {
	Time    int32
	Presses []bool
}

It is great to wrap a slice with a struct and name it in the singular form, as it ensures the slice is always handled in a packed form.

Jump to

Keyboard shortcuts

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