diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 57a3bfd4b..f9a37664f 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -66,6 +66,16 @@ PhysicalKeyboardHandler::PhysicalKeyboardHandler(OSystem& system, EventHandler& setDefaultMapping(Event::NoType, EventMode::kMenuMode, true); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool PhysicalKeyboardHandler::isMappingUsed(EventMapping map) +{ + for(int i = 0; i < int(EventMode::kNumModes); ++i) + if(myKeyMap.check(EventMode(i), map.key, map.mod)) + return true; + + return false; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Depending on parameters, this method does the following: // 1. update all events with default (event == Event::NoType, updateDefault == true) @@ -83,7 +93,7 @@ void PhysicalKeyboardHandler::setDefaultKey(EventMapping map, Event::Type event, // if there is no existing mapping for the event and // the default mapping for the event is unused, set default key for event if (myKeyMap.getEventMapping(map.event, mode).size() == 0 && - !myKeyMap.check(mode, map.key, map.mod)) + !isMappingUsed(map)) { addMapping(map.event, mode, map.key, StellaMod(map.mod)); } diff --git a/src/common/PKeyboardHandler.hxx b/src/common/PKeyboardHandler.hxx index adb9b5106..33e19b421 100644 --- a/src/common/PKeyboardHandler.hxx +++ b/src/common/PKeyboardHandler.hxx @@ -87,6 +87,9 @@ class PhysicalKeyboardHandler }; using EventMappingArray = std::vector; + // Checks if the given mapping is used by any event mode + bool isMappingUsed(EventMapping map); + void setDefaultKey(EventMapping map, Event::Type event = Event::NoType, EventMode mode = EventMode::kEmulationMode, bool updateDefaults = false); diff --git a/src/emucore/EventHandlerConstants.hxx b/src/emucore/EventHandlerConstants.hxx index 7246983eb..8f11ecab6 100644 --- a/src/emucore/EventHandlerConstants.hxx +++ b/src/emucore/EventHandlerConstants.hxx @@ -82,7 +82,8 @@ enum class EventMode { kPaddlesMode, kKeypadMode, kCompuMateMode, // cannot be remapped - kCommonMode // mapping common between controllers + kCommonMode, // mapping common between controllers + kNumModes }; namespace GUI