Kernel: Fix shift sometimes staying pressed after releasing the key

Previous implementation sometimes didn't release the key after pressing
and holding shift due to repeating key updates when holding keys. This
meant repeating updates would set/unset `m_both_shift_keys_pressed`
repeatedly, sometimes resulting in shift still being considered pressed
even after you released it.

Simplify left and right shift key pressed logic by tracking both key
states separately and always updating modifiers based on them.
This commit is contained in:
LepkoQQ 2021-08-30 18:46:27 +02:00 committed by Andreas Kling
parent 57ac8ff1fd
commit 25f76ed771
Notes: sideshowbarker 2024-07-18 05:04:08 +09:00
2 changed files with 7 additions and 7 deletions

View file

@ -61,7 +61,8 @@ protected:
bool m_caps_lock_on { false };
bool m_num_lock_on { false };
bool m_has_e0_prefix { false };
bool m_both_shift_keys_pressed { false };
bool m_left_shift_pressed { false };
bool m_right_shift_pressed { false };
void key_state_changed(u8 raw, bool pressed);
};

View file

@ -53,13 +53,12 @@ void PS2KeyboardDevice::irq_handle_byte_read(u8 byte)
update_modifier(Mod_Super, pressed);
break;
case 0x2a:
m_left_shift_pressed = pressed;
update_modifier(Mod_Shift, m_left_shift_pressed || m_right_shift_pressed);
break;
case 0x36:
if (m_both_shift_keys_pressed)
m_both_shift_keys_pressed = false;
else if ((m_modifiers & Mod_Shift) != 0 && pressed)
m_both_shift_keys_pressed = true;
else
update_modifier(Mod_Shift, pressed);
m_right_shift_pressed = pressed;
update_modifier(Mod_Shift, m_left_shift_pressed || m_right_shift_pressed);
break;
}
switch (ch) {