internal/ui: bug fix: move handling mod keys to ui.InputState

Closes #3320
This commit is contained in:
Hajime Hoshi
2025-09-24 04:56:29 +09:00
parent 7de26d3a30
commit 8d421df739
2 changed files with 12 additions and 14 deletions

View File

@@ -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 {

View File

@@ -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
}