diff options
author | Colin Snover | 2017-09-26 00:45:17 -0500 |
---|---|---|
committer | Colin Snover | 2017-09-27 20:27:34 -0500 |
commit | 7a41b6f023e31a5f6845b9a256d966270fa60151 (patch) | |
tree | c295dccf350d9417bfee99317b185ca6164d840a /engines | |
parent | 4bd31dae9b638bb6c80ddc3db7b41f34c68626fc (diff) | |
download | scummvm-rg350-7a41b6f023e31a5f6845b9a256d966270fa60151.tar.gz scummvm-rg350-7a41b6f023e31a5f6845b9a256d966270fa60151.tar.bz2 scummvm-rg350-7a41b6f023e31a5f6845b9a256d966270fa60151.zip |
SCI: Add support for keyup events
Basic keyup event support appears to have been added in the SCI1.1
IBM keyboard driver, and more robust support was provided in SCI32
which actually gets used by at least Lighthouse. This patch adds
support for keyup events in SCI1.1+.
Fixes Trac#10242.
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/kevent.cpp | 4 | ||||
-rw-r--r-- | engines/sci/event.cpp | 46 |
2 files changed, 34 insertions, 16 deletions
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index 0f77b47640..608e2e4ce9 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -58,6 +58,8 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { // If there's a simkey pending, and the game wants a keyboard event, use the // simkey instead of a normal event + // TODO: This does not really work as expected for keyup events, since the + // fake event is disposed halfway through the normal event lifecycle. if (g_debug_simulated_key && (mask & kSciEventKeyDown)) { // In case we use a simulated event we query the current mouse position mousePos = g_sci->_gfxCursor->getPosition(); @@ -180,6 +182,7 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { break; case kSciEventKeyDown: + case kSciEventKeyUp: writeSelectorValue(segMan, obj, SELECTOR(type), curEvent.type); writeSelectorValue(segMan, obj, SELECTOR(message), curEvent.character); // We only care about the translated character @@ -230,6 +233,7 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { con->debugPrintf("quit event\n"); break; case kSciEventKeyDown: + case kSciEventKeyUp: con->debugPrintf("keyboard event\n"); break; case kSciEventMousePress: diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp index 2967b55ec5..e69095a6b1 100644 --- a/engines/sci/event.cpp +++ b/engines/sci/event.cpp @@ -253,10 +253,6 @@ SciEvent EventManager::getScummVMEvent() { } } - // If we reached here, make sure that it's a keydown event - if (ev.type != Common::EVENT_KEYDOWN) - return noEvent; - // Check for Control-Shift-D (debug console) if (ev.type == Common::EVENT_KEYDOWN && ev.kbd.hasFlags(Common::KBD_CTRL | Common::KBD_SHIFT) && ev.kbd.keycode == Common::KEYCODE_d) { // Open debug console @@ -265,19 +261,23 @@ SciEvent EventManager::getScummVMEvent() { return noEvent; } + // The IBM keyboard driver prior to SCI1.1 only sent keydown events to the + // interpreter + if (ev.type != Common::EVENT_KEYDOWN && getSciVersion() < SCI_VERSION_1_1) { + return noEvent; + } const Common::KeyCode scummVMKeycode = ev.kbd.keycode; input.character = ev.kbd.ascii; - input.type = kSciEventKeyDown; - - if (scummVMKeycode >= Common::KEYCODE_KP0 && scummVMKeycode <= Common::KEYCODE_KP9) { - if (!(scummVMKeyFlags & Common::KBD_NUM)) { - // HACK: Num-Lock not enabled - // We shouldn't get a valid ascii code in these cases. We fix it here, so that cursor keys - // on the numpad work properly. - input.character = 0; - } + + if (scummVMKeycode >= Common::KEYCODE_KP0 && scummVMKeycode <= Common::KEYCODE_KP9 && !(scummVMKeyFlags & Common::KBD_NUM)) { + // TODO: Leaky abstractions from SDL should not be handled in game + // engines! + // SDL may provide a character value for numpad keys even if numlock is + // turned off, but arrow/navigation keys won't get mapped below if a + // character value is provided + input.character = 0; } if (input.character && input.character <= 0xFF) { @@ -336,10 +336,24 @@ SciEvent EventManager::getScummVMEvent() { input.character -= 96; } - // If no actual key was pressed (e.g. if only a modifier key was pressed), - // ignore the event - if (!input.character) + // In SCI1.1, if only a modifier key is pressed, the IBM keyboard driver + // sends an event the same as if a key had been released + if (getSciVersion() != SCI_VERSION_1_1 && !input.character) { return noEvent; + } else if (!input.character || ev.type == Common::EVENT_KEYUP) { + input.type = kSciEventKeyUp; + + // SCI32 includes the released key character code in keyup messages, but + // the IBM keyboard driver in SCI1.1 sends a special character value + // instead. This is necessary to prevent at least Island of Dr Brain + // from processing keyup events as though they were keydown events in + // the word search puzzle + if (getSciVersion() == SCI_VERSION_1_1) { + input.character = 0x8000; + } + } else { + input.type = kSciEventKeyDown; + } return input; } |