From bb5bdb2e8c27fc766fc557a66a94c3fec8511add Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 31 Dec 2017 12:01:11 +0100 Subject: [PATCH] improve cellKB keyreleases and autorepeat --- rpcs3/Emu/Cell/Modules/cellKb.cpp | 10 +++++----- rpcs3/Emu/Io/KeyboardHandler.h | 23 +++++++++++++---------- rpcs3/basic_keyboard_handler.cpp | 10 ++++++++++ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index 7bf6a67b14..0c80f816ad 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -100,7 +100,7 @@ u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode) ((led&(CELL_KB_LED_CAPS_LOCK)) ? 0 : 0x20) : ((led&(CELL_KB_LED_CAPS_LOCK)) ? 0x20 : 0); return rawcode + 0x5D; - } + } if (rawcode >= 0x1E && rawcode <= 0x26) return rawcode + 0x13; // '1' - '9' if (rawcode == 0x27) return 0x30; // '0' if (rawcode == 0x28) return 0x0A; // '\n' @@ -136,7 +136,7 @@ error_code cellKbGetInfo(vm::ptr info) { info->status[i] = current_info.status[i]; } - + return CELL_OK; } @@ -165,7 +165,7 @@ error_code cellKbRead(u32 port_no, vm::ptr data) } current_data.len = 0; - + return CELL_OK; } @@ -180,7 +180,7 @@ error_code cellKbSetCodeType(u32 port_no, u32 type) if (port_no >= handler->GetKeyboards().size()) return CELL_KB_ERROR_INVALID_PARAMETER; - + KbConfig& current_config = handler->GetConfig(port_no); current_config.code_type = type; return CELL_OK; @@ -203,7 +203,7 @@ error_code cellKbSetReadMode(u32 port_no, u32 rmode) if (port_no >= handler->GetKeyboards().size()) return CELL_KB_ERROR_INVALID_PARAMETER; - + KbConfig& current_config = handler->GetConfig(port_no); current_config.read_mode = rmode; diff --git a/rpcs3/Emu/Io/KeyboardHandler.h b/rpcs3/Emu/Io/KeyboardHandler.h index 11e2a80c07..d8528982c1 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.h +++ b/rpcs3/Emu/Io/KeyboardHandler.h @@ -248,6 +248,7 @@ struct KbButton struct Keyboard { + bool m_key_repeat; // for future use KbData m_data; KbConfig m_config; std::vector m_buttons; @@ -255,6 +256,7 @@ struct Keyboard Keyboard() : m_data() , m_config() + , m_key_repeat(false) { } }; @@ -274,19 +276,20 @@ public: { for(Keyboard& keyboard : m_keyboards) { + KbData& data = keyboard.m_data; + KbConfig& config = keyboard.m_config; + + // TODO: handle read modes + for(KbButton& button : keyboard.m_buttons) { if(button.m_keyCode != code) continue; - KbData& data = keyboard.m_data; - KbConfig& config = keyboard.m_config; - if (pressed) { // Meta Keys - if (code == 308 || code == 307 || code == 306 || - code == 393 || code == 396 || code == 394) + if (code == 308 || code == 307 || code == 306 || code == 393 || code == 396 || code == 394) { data.mkey |= button.m_outKeyCode; } @@ -310,17 +313,17 @@ public: data.len++; } } - - if (!pressed) + else { // Meta Keys - if (code == 308 || code == 307 || code == 306 || - code == 393 || code == 396 || code == 394) + if (code == 308 || code == 307 || code == 306 || code == 393 || code == 396 || code == 394) { data.mkey &= ~button.m_outKeyCode; } + // Needed to indicate key releases. Without this you have to tap another key before using the same key again + data.keycode[0] = CELL_KEYC_NO_EVENT; + data.len = 1; } - } } } diff --git a/rpcs3/basic_keyboard_handler.cpp b/rpcs3/basic_keyboard_handler.cpp index aeee594934..5b7551eba1 100644 --- a/rpcs3/basic_keyboard_handler.cpp +++ b/rpcs3/basic_keyboard_handler.cpp @@ -60,11 +60,21 @@ bool basic_keyboard_handler::eventFilter(QObject* target, QEvent* ev) void basic_keyboard_handler::keyPressEvent(QKeyEvent* keyEvent) { + if (keyEvent->isAutoRepeat() && !m_keyboards[0].m_key_repeat) + { + keyEvent->ignore(); + return; + } Key(keyEvent->key(), 1); } void basic_keyboard_handler::keyReleaseEvent(QKeyEvent* keyEvent) { + if (keyEvent->isAutoRepeat() && !m_keyboards[0].m_key_repeat) + { + keyEvent->ignore(); + return; + } Key(keyEvent->key(), 0); }