mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-26 04:35:16 +00:00
WINTERMUTE: Fix printable flag for keyboard state
_currentPrintable was set depending on _currentCharCode, which is 112 for both F1 and 'p' keys, fixed after detailed research on which keys should be considered printable
This commit is contained in:
parent
8175439e3b
commit
20816b9f90
@ -198,20 +198,46 @@ const char *BaseKeyboardState::scToString() {
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool BaseKeyboardState::readKey(Common::Event *event) {
|
bool BaseKeyboardState::readKey(Common::Event *event) {
|
||||||
//_currentPrintable = (event->type == SDL_TEXTINPUT); // TODO
|
|
||||||
_currentCharCode = keyCodeToVKey(event);
|
Common::KeyCode code = event->kbd.keycode;
|
||||||
// convert all lowercase keys to uppercase to make it easier for handling later on for consistency
|
|
||||||
if (Common::isLower(_currentCharCode) && (event->kbd.hasFlags(Common::KBD_SHIFT) || event->kbd.flags & Common::KBD_CAPS)) {
|
if (event->type != Common::EVENT_KEYDOWN) {
|
||||||
if (!(event->kbd.keycode >= Common::KEYCODE_F1 && event->kbd.keycode <= Common::KEYCODE_F12)) {
|
_currentCharCode = 0;
|
||||||
_currentCharCode = toupper(_currentCharCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Verify that this is a printable ISO-8859-character (including the upper charset)
|
|
||||||
if ((_currentCharCode <= 0x7E && _currentCharCode >= 0x20) || (_currentCharCode <= 0xFF && _currentCharCode >= 0xA0)) {
|
|
||||||
_currentPrintable = true;
|
|
||||||
} else {
|
|
||||||
_currentPrintable = false;
|
_currentPrintable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use ASCII value if key pressed is an alphanumeric or punctuation key
|
||||||
|
// keys pressed on numpad are handled in next 2 blocks
|
||||||
|
else if (code > Common::KEYCODE_SPACE && code < Common::KEYCODE_DELETE) {
|
||||||
|
_currentCharCode = event->kbd.ascii;
|
||||||
|
_currentPrintable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use ASCII value for numpad '/', '*', '-', '+'
|
||||||
|
else if (code >= Common::KEYCODE_KP_DIVIDE && code <= Common::KEYCODE_KP_PLUS) {
|
||||||
|
_currentCharCode = event->kbd.ascii;
|
||||||
|
_currentPrintable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if NumLock is active, use ASCII for numpad keys '0'~'9' and '.'
|
||||||
|
// keys pressed on numpad without NumLock are considered as normal keycodes, handled in the next block
|
||||||
|
else if ((code >= Common::KEYCODE_KP0 && code <= Common::KEYCODE_KP_PERIOD) && ((event->kbd.flags & Common::KBD_NUM) != 0)) {
|
||||||
|
_currentCharCode = event->kbd.ascii;
|
||||||
|
_currentPrintable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use keyCodeToVKey mapping for all other events
|
||||||
|
// some keys are printable from those keys
|
||||||
|
else {
|
||||||
|
_currentCharCode = keyCodeToVKey(event);
|
||||||
|
_currentPrintable = code == Common::KEYCODE_BACKSPACE ||
|
||||||
|
code == Common::KEYCODE_TAB ||
|
||||||
|
code == Common::KEYCODE_RETURN ||
|
||||||
|
code == Common::KEYCODE_KP_ENTER ||
|
||||||
|
code == Common::KEYCODE_ESCAPE ||
|
||||||
|
code == Common::KEYCODE_SPACE;
|
||||||
|
}
|
||||||
|
|
||||||
//_currentKeyData = KeyData;
|
//_currentKeyData = KeyData;
|
||||||
|
|
||||||
_currentControl = isControlDown();
|
_currentControl = isControlDown();
|
||||||
@ -269,15 +295,13 @@ bool BaseKeyboardState::isCurrentPrintable() const {
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
enum VKeyCodes {
|
enum VKeyCodes {
|
||||||
kVkBack = 8,
|
kVkBack = 8, //printable
|
||||||
kVkTab = 9,
|
kVkTab = 9, //printable
|
||||||
|
kVkReturn = 13, //printable
|
||||||
kVkReturn = 13,
|
|
||||||
kVkPause = 19,
|
kVkPause = 19,
|
||||||
|
kVkEscape = 27, //printable
|
||||||
|
kVkSpace = 32, //printable
|
||||||
|
|
||||||
kVkEscape = 27,
|
|
||||||
|
|
||||||
kVkSpace = 32,
|
|
||||||
kVkEnd = 35,
|
kVkEnd = 35,
|
||||||
kVkHome = 36,
|
kVkHome = 36,
|
||||||
kVkLeft = 37,
|
kVkLeft = 37,
|
||||||
@ -304,22 +328,6 @@ enum VKeyCodes {
|
|||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
uint32 BaseKeyboardState::keyCodeToVKey(Common::Event *event) {
|
uint32 BaseKeyboardState::keyCodeToVKey(Common::Event *event) {
|
||||||
// todo
|
// todo
|
||||||
if (event->type != Common::EVENT_KEYDOWN) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return ASCII value if key pressed is an alphanumeric key
|
|
||||||
// number keys pressed on numpad are handled in next block
|
|
||||||
if (Common::isAlnum(event->kbd.keycode)) {
|
|
||||||
return event->kbd.ascii;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if NumLock is active, return ASCII for numpad keys
|
|
||||||
// keys pressed on numpad without NumLock are considered as normal keycodes, handled in the next block
|
|
||||||
if (Common::isDigit(event->kbd.ascii) && ((event->kbd.flags & Common::KBD_NUM) != 0)) {
|
|
||||||
return event->kbd.ascii;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event->kbd.keycode) {
|
switch (event->kbd.keycode) {
|
||||||
case Common::KEYCODE_BACKSPACE:
|
case Common::KEYCODE_BACKSPACE:
|
||||||
return kVkBack;
|
return kVkBack;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user