Skip to content

Commit

Permalink
Merge pull request scummvm#635 from jammm/master
Browse files Browse the repository at this point in the history
WINTERMUTE: Add more keyboard mappings, fix console warnings.
  • Loading branch information
somaen committed Dec 21, 2015
2 parents 774b375 + d090057 commit 952d632
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions engines/wintermute/base/base_keyboard_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ const char *BaseKeyboardState::scToString() {
bool BaseKeyboardState::readKey(Common::Event *event) {
//_currentPrintable = (event->type == SDL_TEXTINPUT); // TODO
_currentCharCode = keyCodeToVKey(event);
// 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->kbd.keycode >= Common::KEYCODE_F1 && event->kbd.keycode <= Common::KEYCODE_F12)) {
_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;
Expand Down Expand Up @@ -263,7 +269,11 @@ bool BaseKeyboardState::isCurrentPrintable() const {

//////////////////////////////////////////////////////////////////////////
enum VKeyCodes {
kVkBack = 8,
kVkTab = 9,

kVkReturn = 13,
kVkPause = 19,

kVkEscape = 27,

Expand All @@ -274,6 +284,7 @@ enum VKeyCodes {
kVkUp = 38,
kVkRight = 39,
kVkDown = 40,
kVkInsert = 45,

kVkF1 = 112,
kVkF2 = 113,
Expand All @@ -297,26 +308,53 @@ uint32 BaseKeyboardState::keyCodeToVKey(Common::Event *event) {
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) {
case Common::KEYCODE_BACKSPACE:
return kVkBack;
case Common::KEYCODE_TAB:
return kVkTab;
case Common::KEYCODE_RETURN:
case Common::KEYCODE_KP_ENTER:
return kVkReturn;
case Common::KEYCODE_PAUSE:
return kVkPause;
case Common::KEYCODE_ESCAPE:
return kVkEscape;
case Common::KEYCODE_SPACE:
return kVkSpace;
case Common::KEYCODE_END:
case Common::KEYCODE_KP1:
return kVkEnd;
case Common::KEYCODE_HOME:
case Common::KEYCODE_KP7:
return kVkHome;
case Common::KEYCODE_LEFT:
case Common::KEYCODE_KP4:
return kVkLeft;
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_KP6:
return kVkRight;
case Common::KEYCODE_UP:
case Common::KEYCODE_KP8:
return kVkUp;
case Common::KEYCODE_DOWN:
case Common::KEYCODE_KP2:
return kVkDown;
case Common::KEYCODE_INSERT:
case Common::KEYCODE_KP0:
return kVkInsert;
case Common::KEYCODE_F1:
return kVkF1;
case Common::KEYCODE_F2:
Expand All @@ -342,8 +380,12 @@ uint32 BaseKeyboardState::keyCodeToVKey(Common::Event *event) {
case Common::KEYCODE_F12:
return kVkF12;
default:
warning("Key not handled: %d '%c'", event->kbd.keycode, event->kbd.keycode);
return event->kbd.keycode;
// check if any non-sticky keys were used, otherwise key is unknown to us
if ((event->kbd.flags & Common::KBD_NON_STICKY) == 0) {
warning("Key pressed is not recognized, ASCII returned (%d '%c').", event->kbd.keycode, event->kbd.keycode);
}
// return ASCII if no match, since it could be used for typing
return event->kbd.ascii;
break;
}

Expand Down

0 comments on commit 952d632

Please sign in to comment.