diff --git a/internal/inputstate/inputstate.go b/internal/inputstate/inputstate.go index eecb86fe8..97f215cdd 100644 --- a/internal/inputstate/inputstate.go +++ b/internal/inputstate/inputstate.go @@ -51,20 +51,7 @@ func (i *inputState) AppendInputChars(runes []rune) []rune { func (i *inputState) IsKeyPressed(key ui.Key) bool { i.m.Lock() defer i.m.Unlock() - - tick := ui.Get().Tick() - switch key { - case ui.KeyAlt: - return i.state.IsKeyPressed(ui.KeyAltLeft, tick) || i.state.IsKeyPressed(ui.KeyAltRight, tick) - case ui.KeyControl: - return i.state.IsKeyPressed(ui.KeyControlLeft, tick) || i.state.IsKeyPressed(ui.KeyControlRight, tick) - case ui.KeyShift: - return i.state.IsKeyPressed(ui.KeyShiftLeft, tick) || i.state.IsKeyPressed(ui.KeyShiftRight, tick) - case ui.KeyMeta: - return i.state.IsKeyPressed(ui.KeyMetaLeft, tick) || i.state.IsKeyPressed(ui.KeyMetaRight, tick) - default: - return i.state.IsKeyPressed(key, tick) - } + return i.state.IsKeyPressed(key, ui.Get().Tick()) } func (i *inputState) IsKeyJustPressed(key ui.Key) bool { diff --git a/internal/ui/input.go b/internal/ui/input.go index efb28afb6..e572723eb 100644 --- a/internal/ui/input.go +++ b/internal/ui/input.go @@ -95,6 +95,17 @@ func (i *InputState) releaseAllButtons(t InputTime) { } func (i *InputState) IsKeyPressed(key Key, tick int64) bool { + switch key { + case KeyAlt: + return i.IsKeyPressed(KeyAltLeft, tick) || i.IsKeyPressed(KeyAltRight, tick) + case KeyControl: + return i.IsKeyPressed(KeyControlLeft, tick) || i.IsKeyPressed(KeyControlRight, tick) + case KeyShift: + return i.IsKeyPressed(KeyShiftLeft, tick) || i.IsKeyPressed(KeyShiftRight, tick) + case KeyMeta: + return i.IsKeyPressed(KeyMetaLeft, tick) || i.IsKeyPressed(KeyMetaRight, tick) + } + if key < 0 || KeyMax < key { return false }