change key mapping strategy: left and right modifier key are not considered separately except when pressed alone

This commit is contained in:
Thomas Jentzsch 2019-08-09 08:42:46 +02:00
parent 8c332f3bd6
commit 0b15163c8a
1 changed files with 20 additions and 5 deletions

View File

@ -263,12 +263,14 @@ bool EventMappingWidget::handleKeyDown(StellaKey key, StellaMod mod)
// Remap keys in remap mode // Remap keys in remap mode
if (myRemapStatus && myActionSelected >= 0) if (myRemapStatus && myActionSelected >= 0)
{ {
// TODO: further improve logic here // Mod keys are only recorded if no other key has been recorded before
// Avoid overwriting normal keys with modifier keys if (key < KBDK_LCTRL || key > KBDK_RGUI
if (!myMod || (key < KBDK_LCTRL || key > KBDK_RGUI)) || (!myLastKey || myLastKey >= KBDK_LCTRL && myLastKey <= KBDK_RGUI))
{
myLastKey = key; myLastKey = key;
}
myMod |= mod; myMod |= mod;
// cerr << myLastKey << ", " << key << endl; cerr << myMod << ", " << myLastKey << " | " << mod << ", " << key << endl;
} }
return true; return true;
} }
@ -282,7 +284,20 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod)
{ {
Event::Type event = Event::Type event =
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode); instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
if (myLastKey == 0 || instance().eventHandler().addKeyMapping(event, myEventMode, StellaKey(myLastKey), StellaMod(myMod)))
// if not pressed alone, map left and right modifier keys
if(myLastKey < KBDK_LCTRL || myLastKey > KBDK_RGUI)
{
if(myMod & KBDM_CTRL)
myMod |= KBDM_CTRL;
if(myMod & KBDM_SHIFT)
myMod |= KBDM_SHIFT;
if(myMod & KBDM_ALT)
myMod |= KBDM_ALT;
if(myMod & KBDM_GUI)
myMod |= KBDM_GUI;
}
if (instance().eventHandler().addKeyMapping(event, myEventMode, StellaKey(myLastKey), StellaMod(myMod)))
stopRemapping(); stopRemapping();
} }
return true; return true;