stone/input.go

104 lines
2.7 KiB
Go

package stone
import "unicode"
// Button represents a keyboard or mouse button.
type Button int
const (
ButtonUnknown Button = 0
KeyInsert Button = 1
KeyMenu Button = 2
KeyPrintScreen Button = 3
KeyPause Button = 4
KeyCapsLock Button = 5
KeyScrollLock Button = 6
KeyNumLock Button = 7
KeyBackspace Button = 8
KeyTab Button = 9
KeyEnter Button = 10
KeyEscape Button = 11
KeyUp Button = 12
KeyDown Button = 13
KeyLeft Button = 14
KeyRight Button = 15
KeyPageUp Button = 16
KeyPageDown Button = 17
KeyHome Button = 18
KeyEnd Button = 19
KeyLeftShift Button = 20
KeyRightShift Button = 21
KeyLeftControl Button = 22
KeyRightControl Button = 23
KeyLeftAlt Button = 24
KeyRightAlt Button = 25
KeyLeftMeta Button = 26
KeyRightMeta Button = 27
KeyLeftSuper Button = 28
KeyRightSuper Button = 29
KeyLeftHyper Button = 30
KeyRightHyper Button = 31
KeyDelete Button = 127
MouseButton1 Button = 128
MouseButton2 Button = 129
MouseButton3 Button = 130
MouseButton4 Button = 131
MouseButton5 Button = 132
MouseButton6 Button = 133
MouseButton7 Button = 134
MouseButton8 Button = 135
MouseButton9 Button = 136
MouseButtonLeft Button = MouseButton1
MouseButtonMiddle Button = MouseButton2
MouseButtonRight Button = MouseButton3
MouseButtonBack Button = MouseButton8
MouseButtonForward Button = MouseButton9
KeyF1 Button = 144
KeyF2 Button = 145
KeyF3 Button = 146
KeyF4 Button = 147
KeyF5 Button = 148
KeyF6 Button = 149
KeyF7 Button = 150
KeyF8 Button = 151
KeyF9 Button = 152
KeyF10 Button = 153
KeyF11 Button = 154
KeyF12 Button = 155
KeyDead Button = 156
)
// Printable returns whether or not the character could show up on screen. If
// this function returns true, the button can be cast to a rune and used as
// such.
func (button Button) Printable () (printable bool) {
printable = unicode.IsPrint(rune(button))
return
}
// Modifiers lists what modifier keys are being pressed. This is used in
// conjunction with a button code in a button press event. These should be used
// instead of attempting to track the state of the modifier keys, because there
// is no guarantee that one press event will be coupled with one release event.
type Modifiers struct {
Shift bool
Control bool
Alt bool
Meta bool
Super bool
Hyper bool
// NumberPad does not represent a key, but it behaves like one. If it is
// set to true, the button was pressed on the number pad. It is treated
// as a modifier key because if you don't care whether a key was pressed
// on the number pad or not, you can just ignore this value.
NumberPad bool
}