gui: kb shortcuts: handle Sys_TakeSnapshot with shift/ctrl better

There's only one plugin api for this, but GSdx also checks whether shift/ctrl
are held down, so PCSX2 needs to map those too to the same API.

Make this more systematic by only mapping one shortcut to this API, and then
deriving the other two from it amd mapping them too automatically.

This also makes it possible to override it at PCSX2_keys.ini since now it
doesn't need to handle different shortcuts for the same function (which it still
can't handle, but now it also doesn't need to for this function).
This commit is contained in:
Avi Halachmi (:avih) 2015-10-12 04:04:14 +03:00
parent 69a978fe05
commit 5379b89dbd
3 changed files with 37 additions and 8 deletions

View File

@ -48,10 +48,9 @@ FullscreenToggle = Alt-ENTER
Sys_Suspend = ESC
# PCSX2 binds F8, shift-F8 and ctrl-shift-f8 to Sys_TakeSnapshot.
# This ini file supports only one key per function, so if you override
# it then it will override all 3 original bindings (and show some warnings).
# Sys_TakeSnapshot = F8
# Screenshot. Note: must not include shift or ctrl. With these held - it will
# create debug GS dump. The two other shortcuts will be added automatically.
Sys_TakeSnapshot = F8
# Hardware/software rendering toggle
Sys_RenderswitchToggle = F9

View File

@ -67,9 +67,7 @@ void GSPanel::InitDefaultAccelerators()
m_Accels->Map( AAC( WXK_NUMPAD_DIVIDE ).Cmd().Alt(), "GSwindow_OffsetReset" );
m_Accels->Map( AAC( WXK_ESCAPE ), "Sys_Suspend" );
m_Accels->Map( AAC( WXK_F8 ), "Sys_TakeSnapshot" );
m_Accels->Map( AAC( WXK_F8 ).Shift(), "Sys_TakeSnapshot");
m_Accels->Map( AAC( WXK_F8 ).Shift().Cmd(), "Sys_TakeSnapshot");
m_Accels->Map( AAC( WXK_F8 ), "Sys_TakeSnapshot" ); // also shift and ctrl-shift will be added automatically
m_Accels->Map( AAC( WXK_F9 ), "Sys_RenderswitchToggle");
m_Accels->Map( AAC( WXK_F10 ), "Sys_LoggingToggle" );

View File

@ -661,7 +661,39 @@ void AcceleratorDictionary::Map( const KeyAcceleratorCode& _acode, const char *s
}
else
{
operator[](acode.val32) = result;
if (!strcmp("Sys_TakeSnapshot", searchfor)) {
// Sys_TakeSnapshot is special in a bad way. On its own it creates a screenshot
// but GSdx also checks whether shift or ctrl are held down, and for each of
// them it does a different thing (gs dumps). So we need to map a shortcut and
// also the same shortcut with shift and the same with ctrl to the same function.
// So make sure the shortcut doesn't include shift or ctrl, and then add two more
// which are derived from it.
// Also, looking at the GSdx code, it seems that it never cares about both shift
// and ctrl held together, but PCSX2 traditionally mapped f8, shift-f8 and ctrl-shift-f8
// to Sys_TakeSnapshot, so let's not change it - we'll keep adding only shift and
// ctrl-shift to the base shortcut.
if (acode.cmd || acode.shift) {
Console.Error(L"Cannot map %s to Sys_TakeSnapshot - must not include Shift or Ctrl - these modifiers will be added automatically.",
WX_STR(acode.ToString()));
}
else {
KeyAcceleratorCode shifted(acode); shifted.Shift();
KeyAcceleratorCode controlledShifted(shifted); controlledShifted.Cmd();
operator[](acode.val32) = result;
operator[](shifted.val32) = result;
operator[](controlledShifted.val32) = result;
if (_acode.val32 != acode.val32) { // overriding default
Console.WriteLn(Color_Green, L"Sys_TakeSnapshot: automatically mapping also %s and %s",
WX_STR(shifted.ToString()),
WX_STR(controlledShifted.ToString())
);
}
}
}
else {
operator[](acode.val32) = result;
}
}
}