diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index a8109e6fff..17ae354431 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -301,9 +301,22 @@ error_code cellKbRead(u32 port_no, vm::ptr data) data->mkey = current_data.mkey; data->len = std::min(CELL_KB_MAX_KEYCODES, current_data.len); - for (s32 i = 0; i < current_data.len; i++) + if (current_data.len > 0) { - data->keycode[i] = current_data.keycode[i].first; + for (s32 i = 0; i < current_data.len; i++) + { + data->keycode[i] = current_data.keycode[i].first; + } + + KbConfig& current_config = handler.GetConfig(port_no); + + // For single character mode to work properly we need to "flush" the buffer after reading or else we'll constantly get the same key presses with each call. + // Actual key repeats are handled by adding a new key code to the buffer periodically. Key releases are handled in a similar fashion. + // Warning: Don't do this in packet mode, which is basically the mouse and keyboard gaming mode. Otherwise games like Unreal Tournament will be unplayable. + if (current_config.read_mode == CELL_KB_RMODE_INPUTCHAR) + { + current_data.len = 0; + } } return CELL_OK; @@ -386,6 +399,10 @@ error_code cellKbSetReadMode(u32 port_no, u32 rmode) KbConfig& current_config = handler.GetConfig(port_no); current_config.read_mode = rmode; + // Key repeat must be disabled in packet mode. But let's just always enable it otherwise. + Keyboard& keyboard = handler.GetKeyboards()[port_no]; + keyboard.m_key_repeat = rmode != CELL_KB_RMODE_PACKET; + // can also return CELL_KB_ERROR_SYS_SETTING_FAILED return CELL_OK; diff --git a/rpcs3/Emu/Io/KeyboardHandler.cpp b/rpcs3/Emu/Io/KeyboardHandler.cpp index add28a1911..6d4479c6e8 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.cpp +++ b/rpcs3/Emu/Io/KeyboardHandler.cpp @@ -42,8 +42,6 @@ void fmt_class_string::format(std::string& out, u64 arg) void KeyboardHandlerBase::Key(u32 code, bool pressed) { - // TODO: Key Repeat - std::lock_guard lock(m_mutex); for (Keyboard& keyboard : m_keyboards) diff --git a/rpcs3/Emu/Io/KeyboardHandler.h b/rpcs3/Emu/Io/KeyboardHandler.h index 8538be319b..dba8d5f768 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.h +++ b/rpcs3/Emu/Io/KeyboardHandler.h @@ -74,7 +74,7 @@ struct KbButton struct Keyboard { - bool m_key_repeat = false; // for future use + bool m_key_repeat = false; KbData m_data; KbConfig m_config; std::vector m_buttons;