improve cellKB keyreleases and autorepeat

This commit is contained in:
Megamouse 2017-12-31 12:01:11 +01:00 committed by Ivan
parent 9614fef4b9
commit bb5bdb2e8c
3 changed files with 28 additions and 15 deletions

View File

@ -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<CellKbInfo> info)
{
info->status[i] = current_info.status[i];
}
return CELL_OK;
}
@ -165,7 +165,7 @@ error_code cellKbRead(u32 port_no, vm::ptr<CellKbData> 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;

View File

@ -248,6 +248,7 @@ struct KbButton
struct Keyboard
{
bool m_key_repeat; // for future use
KbData m_data;
KbConfig m_config;
std::vector<KbButton> 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;
}
}
}
}

View File

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