diff --git a/Core/Console.cpp b/Core/Console.cpp index b77c613c..bc7d3e83 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -24,7 +24,6 @@ #include "NsfPpu.h" #include "SoundMixer.h" #include "NsfMapper.h" -#include "ShortcutKeyHandler.h" #include "MovieManager.h" #include "RewindManager.h" #include "SaveStateManager.h" @@ -337,7 +336,6 @@ void Console::Run() double targetTime; uint32_t lastFrameNumber = -1; - ShortcutKeyHandler shortcutKeyHandler; _autoSaveManager.reset(new AutoSaveManager()); _runLock.Acquire(); diff --git a/Core/ControlManager.cpp b/Core/ControlManager.cpp index 0804499d..a1588018 100644 --- a/Core/ControlManager.cpp +++ b/Core/ControlManager.cpp @@ -53,12 +53,12 @@ bool ControlManager::IsMouseButtonPressed(MouseButton button) return false; } -uint32_t ControlManager::GetPressedKey() +vector ControlManager::GetPressedKeys() { if(_keyManager != nullptr) { - return _keyManager->GetPressedKey(); + return _keyManager->GetPressedKeys(); } - return 0; + return vector(); } string ControlManager::GetKeyName(uint32_t keyCode) diff --git a/Core/ControlManager.h b/Core/ControlManager.h index 0ade7d20..dd30a3f8 100644 --- a/Core/ControlManager.h +++ b/Core/ControlManager.h @@ -59,7 +59,7 @@ class ControlManager : public Snapshotable, public IMemoryHandler static void RefreshKeyState(); static bool IsKeyPressed(uint32_t keyCode); static bool IsMouseButtonPressed(MouseButton button); - static uint32_t GetPressedKey(); + static vector GetPressedKeys(); static string GetKeyName(uint32_t keyCode); static uint32_t GetKeyCode(string keyName); diff --git a/Core/EmulationSettings.cpp b/Core/EmulationSettings.cpp index 749e678a..3c997284 100644 --- a/Core/EmulationSettings.cpp +++ b/Core/EmulationSettings.cpp @@ -56,7 +56,8 @@ bool EmulationSettings::_nsfDisableApuIrqs = true; uint32_t EmulationSettings::_autoSaveDelay = 5; bool EmulationSettings::_autoSaveNotify = false; -EmulatorKeyMappingSet EmulationSettings::_emulatorKeys; +SimpleLock EmulationSettings::_shortcutLock; +std::unordered_map EmulationSettings::_emulatorKeys[2]; RamPowerOnState EmulationSettings::_ramPowerOnState = RamPowerOnState::AllZeros; diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index 59a97b99..29c7e003 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -272,45 +272,88 @@ struct KeyMappingSet uint32_t TurboSpeed; }; -struct EmulatorKeyMappings +enum class EmulatorShortcut { - uint32_t FastForward; - uint32_t Rewind; - uint32_t RewindTenSecs; - uint32_t RewindOneMin; + FastForward, + Rewind, + RewindTenSecs, + RewindOneMin, - uint32_t Pause; - uint32_t Reset; - uint32_t PowerCycle; - uint32_t PowerOff; - uint32_t Exit; + MoveToNextStateSlot, + MoveToPreviousStateSlot, + SaveState, + LoadState, - uint32_t MoveToNextStateSlot; - uint32_t MoveToPreviousStateSlot; - uint32_t SaveState; - uint32_t LoadState; + InsertNextDisk, + VsServiceButton, - uint32_t SwitchDiskSide; - uint32_t InsertNextDisk; + ToggleCheats, + ToggleAudio, - uint32_t InsertCoin1; - uint32_t InsertCoin2; - uint32_t VsServiceButton; + RunSingleFrame, - uint32_t TakeScreenshot; - uint32_t IncreaseSpeed; - uint32_t DecreaseSpeed; + // Everything below this is handled UI-side + SwitchDiskSide, + EjectDisk, - uint32_t ToggleCheats; - uint32_t ToggleAudio; + InsertCoin1, + InsertCoin2, - uint32_t RunSingleFrame; + TakeScreenshot, + + IncreaseSpeed, + DecreaseSpeed, + MaxSpeed, + + Pause, + Reset, + PowerCycle, + PowerOff, + Exit, + + SetScale1x, + SetScale2x, + SetScale3x, + SetScale4x, + SetScale5x, + SetScale6x, + ToggleFullscreen, + ToggleFps, + + LoadRandomGame, + SaveStateSlot1, + SaveStateSlot2, + SaveStateSlot3, + SaveStateSlot4, + SaveStateSlot5, + SaveStateSlot6, + SaveStateSlot7, + SaveStateToFile, + + LoadStateSlot1, + LoadStateSlot2, + LoadStateSlot3, + LoadStateSlot4, + LoadStateSlot5, + LoadStateSlot6, + LoadStateSlot7, + LoadStateSlot8, + LoadStateFromFile, + + OpenFile, + OpenDebugger, + OpenAssembler, + OpenPpuViewer, + OpenMemoryTools, + OpenScriptWindow, + OpenTraceLogger }; -struct EmulatorKeyMappingSet +struct KeyCombination { - EmulatorKeyMappings KeySet1 = {}; - EmulatorKeyMappings KeySet2 = {}; + uint32_t Key1; + uint32_t Key2; + uint32_t Key3; }; enum class Language @@ -442,10 +485,11 @@ private: static uint32_t _autoSaveDelay; static bool _autoSaveNotify; - static EmulatorKeyMappingSet _emulatorKeys; + static std::unordered_map _emulatorKeys[2]; static RamPowerOnState _ramPowerOnState; + static SimpleLock _shortcutLock; static SimpleLock _lock; public: @@ -1008,14 +1052,27 @@ public: return _controllerKeys[port]; } - static void SetEmulatorKeys(EmulatorKeyMappingSet keyMappings) + static void ClearShortcutKeys() { - _emulatorKeys = keyMappings; + auto lock = _shortcutLock.AcquireSafe(); + _emulatorKeys[0].clear(); + _emulatorKeys[1].clear(); } - static EmulatorKeyMappingSet GetEmulatorKeys() + static void SetShortcutKey(EmulatorShortcut shortcut, KeyCombination keyCombination, int keySetIndex) { - return _emulatorKeys; + auto lock = _shortcutLock.AcquireSafe(); + _emulatorKeys[keySetIndex][(int)shortcut] = keyCombination; + } + + static KeyCombination GetShortcutKey(EmulatorShortcut shortcut, int keySetIndex) + { + auto lock = _shortcutLock.AcquireSafe(); + auto result = _emulatorKeys[keySetIndex].find((int)shortcut); + if(result != _emulatorKeys[keySetIndex].end()) { + return result->second; + } + return {}; } static bool NeedControllerUpdate() diff --git a/Core/IKeyManager.h b/Core/IKeyManager.h index d0fbe6d8..dc2b51ca 100644 --- a/Core/IKeyManager.h +++ b/Core/IKeyManager.h @@ -18,10 +18,11 @@ public: virtual void UpdateDevices() = 0; virtual bool IsMouseButtonPressed(MouseButton button) = 0; virtual bool IsKeyPressed(uint32_t keyCode) = 0; - virtual uint32_t GetPressedKey() = 0; + virtual vector GetPressedKeys() = 0; virtual string GetKeyName(uint32_t keyCode) = 0; virtual uint32_t GetKeyCode(string keyName) = 0; virtual void SetKeyState(uint16_t scanCode, bool state) = 0; virtual void ResetKeyState() = 0; + virtual void SetDisabled(bool disabled) = 0; }; \ No newline at end of file diff --git a/Core/INotificationListener.h b/Core/INotificationListener.h index 91297eba..6bf05f87 100644 --- a/Core/INotificationListener.h +++ b/Core/INotificationListener.h @@ -20,11 +20,8 @@ enum class ConsoleNotificationType ConfigChanged = 14, DisconnectedFromServer = 15, PpuViewerDisplayFrame = 16, - RequestExit = 17, - ToggleCheats = 18, - ToggleAudio = 19, - RequestReset = 20, - RequestPowerCycle = 21, + + ExecuteShortcut = 17, }; class INotificationListener diff --git a/Core/ShortcutKeyHandler.cpp b/Core/ShortcutKeyHandler.cpp index e59e4b0b..00c65f3f 100644 --- a/Core/ShortcutKeyHandler.cpp +++ b/Core/ShortcutKeyHandler.cpp @@ -10,10 +10,11 @@ ShortcutKeyHandler::ShortcutKeyHandler() { + _keySetIndex = 0; _stopThread = false; _thread = std::thread([=]() { while(!_stopThread) { - ProcessKeys(EmulationSettings::GetEmulatorKeys()); + ProcessKeys(); std::this_thread::sleep_for(std::chrono::duration(50)); } }); @@ -25,134 +26,108 @@ ShortcutKeyHandler::~ShortcutKeyHandler() _thread.join(); } -bool ShortcutKeyHandler::DetectKeyPress(uint32_t keyCode) +bool ShortcutKeyHandler::IsKeyPressed(EmulatorShortcut shortcut) { - if(ControlManager::IsKeyPressed(keyCode)) { - _keysDown.emplace(keyCode); + KeyCombination comb = EmulationSettings::GetShortcutKey(shortcut, _keySetIndex); - if(_prevKeysDown.find(keyCode) == _prevKeysDown.end()) { + int keyCount = (comb.Key1 ? 1 : 0) + (comb.Key2 ? 1 : 0) + (comb.Key3 ? 1 : 0); + + if(keyCount == 0) { + return false; + } + + if(_pressedKeys.size() != keyCount) { + //Only allow shortcuts that use as many keys as the number of keys pressed + //e.g: Needed to prevent Shift-F1 from triggering a shortcut for F1 + return false; + } + + return ControlManager::IsKeyPressed(comb.Key1) && + (comb.Key2 == 0 || ControlManager::IsKeyPressed(comb.Key2)) && + (comb.Key3 == 0 || ControlManager::IsKeyPressed(comb.Key3)); +} + +bool ShortcutKeyHandler::DetectKeyPress(EmulatorShortcut shortcut) +{ + if(IsKeyPressed(shortcut)) { + _keysDown[_keySetIndex].emplace(shortcut); + + if(_prevKeysDown[_keySetIndex].find(shortcut) == _prevKeysDown[_keySetIndex].end()) { return true; } } return false; } -bool ShortcutKeyHandler::DetectKeyRelease(uint32_t keyCode) +bool ShortcutKeyHandler::DetectKeyRelease(EmulatorShortcut shortcut) { - if(!ControlManager::IsKeyPressed(keyCode)) { - if(_prevKeysDown.find(keyCode) != _prevKeysDown.end()) { + if(!IsKeyPressed(shortcut)) { + if(_prevKeysDown[_keySetIndex].find(shortcut) != _prevKeysDown[_keySetIndex].end()) { return true; } } return false; } -void ShortcutKeyHandler::CheckMappedKeys(EmulatorKeyMappings mappings) +void ShortcutKeyHandler::CheckMappedKeys() { bool isNetplayClient = GameClient::Connected(); bool isMovieActive = MovieManager::Playing() || MovieManager::Recording(); bool needConfirm = EmulationSettings::CheckFlag(ConfirmExitResetPower); - if(DetectKeyPress(mappings.FastForward)) { + //Let the UI handle these shortcuts + for(uint64_t i = (uint64_t)EmulatorShortcut::SwitchDiskSide; i <= (uint64_t)EmulatorShortcut::OpenTraceLogger; i++) { + if(DetectKeyPress((EmulatorShortcut)i)) { + void* param = (void*)i; + MessageManager::SendNotification(ConsoleNotificationType::ExecuteShortcut, param); + } + } + + if(DetectKeyPress(EmulatorShortcut::FastForward)) { EmulationSettings::SetFlags(EmulationFlags::Turbo); - } else if(DetectKeyRelease(mappings.FastForward)) { + } else if(DetectKeyRelease(EmulatorShortcut::FastForward)) { EmulationSettings::ClearFlags(EmulationFlags::Turbo); } - if(DetectKeyPress(mappings.IncreaseSpeed)) { - EmulationSettings::IncreaseEmulationSpeed(); - } - - if(DetectKeyPress(mappings.DecreaseSpeed)) { - EmulationSettings::DecreaseEmulationSpeed(); - } - - if(DetectKeyPress(mappings.TakeScreenshot)) { - VideoDecoder::GetInstance()->TakeScreenshot(); - } - if(VsControlManager::GetInstance() && !isNetplayClient && !isMovieActive) { VsControlManager* manager = VsControlManager::GetInstance(); - if(DetectKeyPress(mappings.InsertCoin1)) { - manager->InsertCoin(0); - } - if(DetectKeyPress(mappings.InsertCoin2)) { - manager->InsertCoin(1); - } - if(DetectKeyPress(mappings.VsServiceButton)) { + if(DetectKeyPress(EmulatorShortcut::VsServiceButton)) { manager->SetServiceButtonState(true); } - if(DetectKeyRelease(mappings.VsServiceButton)) { + if(DetectKeyRelease(EmulatorShortcut::VsServiceButton)) { manager->SetServiceButtonState(false); } } - if(DetectKeyPress(mappings.SwitchDiskSide) && !isNetplayClient && !isMovieActive) { - FDS::SwitchDiskSide(); - } - - if(DetectKeyPress(mappings.InsertNextDisk) && !isNetplayClient && !isMovieActive) { + if(DetectKeyPress(EmulatorShortcut::InsertNextDisk) && !isNetplayClient && !isMovieActive) { FDS::InsertNextDisk(); } - if(DetectKeyPress(mappings.MoveToNextStateSlot)) { + if(DetectKeyPress(EmulatorShortcut::MoveToNextStateSlot)) { SaveStateManager::MoveToNextSlot(); } - if(DetectKeyPress(mappings.MoveToPreviousStateSlot)) { + if(DetectKeyPress(EmulatorShortcut::MoveToPreviousStateSlot)) { SaveStateManager::MoveToPreviousSlot(); } - if(DetectKeyPress(mappings.SaveState)) { + if(DetectKeyPress(EmulatorShortcut::SaveState)) { SaveStateManager::SaveState(); } - if(DetectKeyPress(mappings.LoadState) && !isNetplayClient) { + if(DetectKeyPress(EmulatorShortcut::LoadState) && !isNetplayClient) { SaveStateManager::LoadState(); } - if(!isNetplayClient && !isMovieActive) { - if(DetectKeyPress(mappings.Reset)) { - if(needConfirm) { - MessageManager::SendNotification(ConsoleNotificationType::RequestReset); - } else { - Console::Reset(true); - } - } - if(DetectKeyPress(mappings.PowerCycle)) { - if(needConfirm) { - MessageManager::SendNotification(ConsoleNotificationType::RequestPowerCycle); - } else { - Console::Reset(false); - } - } + if(DetectKeyPress(EmulatorShortcut::ToggleCheats) && !isNetplayClient && !isMovieActive) { + MessageManager::SendNotification(ConsoleNotificationType::ExecuteShortcut, (void*)EmulatorShortcut::ToggleCheats); } - if(DetectKeyPress(mappings.PowerOff)) { - Console::GetInstance()->Stop(); + if(DetectKeyPress(EmulatorShortcut::ToggleAudio)) { + MessageManager::SendNotification(ConsoleNotificationType::ExecuteShortcut, (void*)EmulatorShortcut::ToggleAudio); } - if(DetectKeyPress(mappings.Exit)) { - MessageManager::SendNotification(ConsoleNotificationType::RequestExit); - } - - if(DetectKeyPress(mappings.Pause) && !isNetplayClient) { - if(EmulationSettings::CheckFlag(EmulationFlags::Paused)) { - EmulationSettings::ClearFlags(EmulationFlags::Paused); - } else { - EmulationSettings::SetFlags(EmulationFlags::Paused); - } - } - - if(DetectKeyPress(mappings.ToggleCheats) && !isNetplayClient && !isMovieActive) { - MessageManager::SendNotification(ConsoleNotificationType::ToggleCheats); - } - - if(DetectKeyPress(mappings.ToggleAudio)) { - MessageManager::SendNotification(ConsoleNotificationType::ToggleAudio); - } - - if(ControlManager::IsKeyPressed(mappings.RunSingleFrame)) { + if(IsKeyPressed(EmulatorShortcut::RunSingleFrame)) { if(EmulationSettings::CheckFlag(EmulationFlags::Paused)) { EmulationSettings::ClearFlags(EmulationFlags::Paused); Console::Pause(); @@ -165,24 +140,29 @@ void ShortcutKeyHandler::CheckMappedKeys(EmulatorKeyMappings mappings) } if(!isNetplayClient && !isMovieActive && !EmulationSettings::CheckFlag(NsfPlayerEnabled)) { - if(DetectKeyPress(mappings.Rewind)) { + if(DetectKeyPress(EmulatorShortcut::Rewind)) { RewindManager::StartRewinding(); - } else if(DetectKeyRelease(mappings.Rewind)) { + } else if(DetectKeyRelease(EmulatorShortcut::Rewind)) { RewindManager::StopRewinding(); - } else if(DetectKeyPress(mappings.RewindTenSecs)) { + } else if(DetectKeyPress(EmulatorShortcut::RewindTenSecs)) { RewindManager::RewindSeconds(10); - } else if(DetectKeyPress(mappings.RewindOneMin)) { + } else if(DetectKeyPress(EmulatorShortcut::RewindOneMin)) { RewindManager::RewindSeconds(60); } } } -void ShortcutKeyHandler::ProcessKeys(EmulatorKeyMappingSet mappings) +void ShortcutKeyHandler::ProcessKeys() { + auto lock = _lock.AcquireSafe(); ControlManager::RefreshKeyState(); - _keysDown.clear(); - CheckMappedKeys(mappings.KeySet1); - CheckMappedKeys(mappings.KeySet2); - _prevKeysDown = _keysDown; + _pressedKeys = ControlManager::GetPressedKeys(); + + for(int i = 0; i < 2; i++) { + _keysDown[i].clear(); + _keySetIndex = i; + CheckMappedKeys(); + _prevKeysDown[i] = _keysDown[i]; + } } \ No newline at end of file diff --git a/Core/ShortcutKeyHandler.h b/Core/ShortcutKeyHandler.h index 3639dd55..3d55a246 100644 --- a/Core/ShortcutKeyHandler.h +++ b/Core/ShortcutKeyHandler.h @@ -2,6 +2,7 @@ #include "stdafx.h" #include #include +#include "../Utilities/SimpleLock.h" #include "EmulationSettings.h" class ShortcutKeyHandler @@ -9,17 +10,24 @@ class ShortcutKeyHandler private: std::thread _thread; atomic _stopThread; + SimpleLock _lock; - std::unordered_set _keysDown; - std::unordered_set _prevKeysDown; + int _keySetIndex; + vector _pressedKeys; + + std::unordered_set _keysDown[2]; + std::unordered_set _prevKeysDown[2]; - void CheckMappedKeys(EmulatorKeyMappings mappings); - void ProcessKeys(EmulatorKeyMappingSet mappings); + void CheckMappedKeys(); - bool DetectKeyPress(uint32_t keyCode); - bool DetectKeyRelease(uint32_t keyCode); + bool IsKeyPressed(EmulatorShortcut key); + + bool DetectKeyPress(EmulatorShortcut key); + bool DetectKeyRelease(EmulatorShortcut key); public: ShortcutKeyHandler(); ~ShortcutKeyHandler(); + + void ProcessKeys(); }; \ No newline at end of file diff --git a/GUI.NET/Config/PreferenceInfo.cs b/GUI.NET/Config/PreferenceInfo.cs index 25e97cea..8c51f184 100644 --- a/GUI.NET/Config/PreferenceInfo.cs +++ b/GUI.NET/Config/PreferenceInfo.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Mesen.GUI.Forms; namespace Mesen.GUI.Config @@ -48,8 +49,9 @@ namespace Mesen.GUI.Config public bool CloudSaveIntegration = false; public DateTime CloudLastSync = DateTime.MinValue; - public EmulatorKeyMappings? EmulatorKeySet1; - public EmulatorKeyMappings? EmulatorKeySet2; + public bool DefaultsInitialized = false; + public List ShortcutKeys1; + public List ShortcutKeys2; public bool DisableGameDatabase = false; public bool DisableOsd = false; @@ -87,19 +89,63 @@ namespace Mesen.GUI.Config public void InitializeDefaults() { - if(EmulatorKeySet1 == null) { - EmulatorKeySet1 = new EmulatorKeyMappings() { - FastForward = InteropEmu.GetKeyCode("Tab"), - Rewind = InteropEmu.GetKeyCode("Backspace") - }; - } + if(!DefaultsInitialized) { + ShortcutKeys1 = new List(); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.FastForward, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Tab") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.Rewind, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Backspace") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.IncreaseSpeed, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("+") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.DecreaseSpeed, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("-") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.MaxSpeed, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F9") })); - if(EmulatorKeySet2 == null) { - EmulatorKeySet2 = new EmulatorKeyMappings() { - FastForward = InteropEmu.GetKeyCode("Pad1 R2"), - Rewind = InteropEmu.GetKeyCode("Pad1 L2") - }; + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.ToggleFps, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F10") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.ToggleFullscreen, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F11") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.TakeScreenshot, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F12") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadRandomGame, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("Ins") })); + + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.Reset, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("R") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.PowerCycle, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("T") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.Pause, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Esc") })); + + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale1x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("1") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale2x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("2") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale3x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("3") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale4x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("4") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale5x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("5") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale6x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("6") })); + + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenAssembler, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("A") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenDebugger, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("D") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenMemoryTools, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("M") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenPpuViewer, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("P") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenScriptWindow, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("J") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenTraceLogger, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("N") })); + + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenFile, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("O") })); + + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot1, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F1") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot2, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F2") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot3, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F3") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot4, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F4") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot5, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F5") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot6, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F6") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot7, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F7") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateToFile, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("S") })); + + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot1, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F1") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot2, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F2") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot3, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F3") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot4, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F4") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot5, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F5") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot6, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F6") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot7, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F7") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot8, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F8") })); + ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateFromFile, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("L") })); + + ShortcutKeys2 = new List(); + ShortcutKeys2.Add(new ShortcutKeyInfo(EmulatorShortcut.FastForward, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Pad1 R2") })); + ShortcutKeys2.Add(new ShortcutKeyInfo(EmulatorShortcut.Rewind, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Pad1 L2") })); } + DefaultsInitialized = true; } static public void ApplyConfig() @@ -141,11 +187,32 @@ namespace Mesen.GUI.Config InteropEmu.SetFlag(EmulationFlags.NsfShuffle, preferenceInfo.NsfShuffle); InteropEmu.SetAutoSaveOptions(preferenceInfo.AutoSave ? (uint)preferenceInfo.AutoSaveDelay : 0, preferenceInfo.AutoSaveNotify); - InteropEmu.SetEmulatorKeys(new EmulatorKeyMappingSet() { KeySet1 = preferenceInfo.EmulatorKeySet1.Value, KeySet2 = preferenceInfo.EmulatorKeySet2.Value }); + + InteropEmu.ClearShortcutKeys(); + foreach(ShortcutKeyInfo shortcutInfo in preferenceInfo.ShortcutKeys1) { + InteropEmu.SetShortcutKey(shortcutInfo.Shortcut, shortcutInfo.KeyCombination, 0); + } + foreach(ShortcutKeyInfo shortcutInfo in preferenceInfo.ShortcutKeys2) { + InteropEmu.SetShortcutKey(shortcutInfo.Shortcut, shortcutInfo.KeyCombination, 1); + } InteropEmu.SetRewindBufferSize(preferenceInfo.RewindBufferSize); InteropEmu.SetFolderOverrides(ConfigManager.SaveFolder, ConfigManager.SaveStateFolder, ConfigManager.ScreenshotFolder); } } + + public class ShortcutKeyInfo + { + public EmulatorShortcut Shortcut; + public KeyCombination KeyCombination; + + public ShortcutKeyInfo() { } + + public ShortcutKeyInfo(EmulatorShortcut key, KeyCombination keyCombination) + { + Shortcut = key; + KeyCombination = keyCombination; + } + } } diff --git a/GUI.NET/Controls/ctrlRecentGames.cs b/GUI.NET/Controls/ctrlRecentGames.cs index 10b9bcfc..21ba9086 100644 --- a/GUI.NET/Controls/ctrlRecentGames.cs +++ b/GUI.NET/Controls/ctrlRecentGames.cs @@ -228,9 +228,9 @@ namespace Mesen.GUI.Controls private void tmrInput_Tick(object sender, EventArgs e) { //Use player 1's controls to navigate the recent game selection screen - if(!InteropEmu.IsRunning()) { - uint keyCode = InteropEmu.GetPressedKey(); - + if(Application.OpenForms.Count > 0 && Application.OpenForms[0].ContainsFocus && !InteropEmu.IsRunning()) { + List keyCodes = InteropEmu.GetPressedKeys(); + uint keyCode = keyCodes.Count > 0 ? keyCodes[0] : 0; if(keyCode > 0) { if(!_waitForRelease) { foreach(KeyMappings mapping in ConfigManager.Config.InputInfo.Controllers[0].Keys) { diff --git a/GUI.NET/Dependencies/resources.ca.xml b/GUI.NET/Dependencies/resources.ca.xml index 5fe0385c..90298ef3 100644 --- a/GUI.NET/Dependencies/resources.ca.xml +++ b/GUI.NET/Dependencies/resources.ca.xml @@ -373,10 +373,13 @@ Insereix automàticament la cara A del disc 1 al carregar un joc de la FDS Activa l'avanç ràpid automàticament en jocs de la FDS mentre el disc o la BIOS es carreguen Canvia automàticament de disc en jocs de la FDS + Dreceres + Warning: Your current configuration contains conflicting key bindings. If this is not intentional, please review and correct your key bindings. Acció Drecera #1 Drecera #2 + Còpies de seguretat Desat de partida automàtic Desa automàticament cada @@ -680,6 +683,42 @@ Activa/Desactiva els trucs Activa/Desactiva el so Avança un sol fotograma + + FDS - Eject Disk + Set Scale 1x + Set Scale 2x + Set Scale 3x + Set Scale 4x + Set Scale 5x + Set Scale 6x + Toggle Fullscreen Mode + Toggle FPS Counter + Toggle Maximum Speed + Load Random Game + Save State - Slot 1 + Save State - Slot 2 + Save State - Slot 3 + Save State - Slot 4 + Save State - Slot 5 + Save State - Slot 6 + Save State - Slot 7 + Save State to File + Load State - Slot 1 + Load State - Slot 2 + Load State - Slot 3 + Load State - Slot 4 + Load State - Slot 5 + Load State - Slot 6 + Load State - Slot 7 + Load State - Slot 8 + Load State from File + Open File + Open Debugger + Open Assembler + Open Ppu Viewer + Open Memory Tools + Open Script Window + Open Trace Logger diff --git a/GUI.NET/Dependencies/resources.en.xml b/GUI.NET/Dependencies/resources.en.xml index 0d243a48..21eb4a5a 100644 --- a/GUI.NET/Dependencies/resources.en.xml +++ b/GUI.NET/Dependencies/resources.en.xml @@ -105,6 +105,42 @@ Enable/Disable Cheat Codes Enable/Disable Audio Run Single Frame + + FDS - Eject Disk + Set Scale 1x + Set Scale 2x + Set Scale 3x + Set Scale 4x + Set Scale 5x + Set Scale 6x + Toggle Fullscreen Mode + Toggle FPS Counter + Toggle Maximum Speed + Load Random Game + Save State - Slot 1 + Save State - Slot 2 + Save State - Slot 3 + Save State - Slot 4 + Save State - Slot 5 + Save State - Slot 6 + Save State - Slot 7 + Save State to File + Load State - Slot 1 + Load State - Slot 2 + Load State - Slot 3 + Load State - Slot 4 + Load State - Slot 5 + Load State - Slot 6 + Load State - Slot 7 + Load State - Slot 8 + Load State from File + Open File + Open Debugger + Open Assembler + Open Ppu Viewer + Open Memory Tools + Open Script Window + Open Trace Logger diff --git a/GUI.NET/Dependencies/resources.es.xml b/GUI.NET/Dependencies/resources.es.xml index 995093b6..64c53be9 100644 --- a/GUI.NET/Dependencies/resources.es.xml +++ b/GUI.NET/Dependencies/resources.es.xml @@ -388,10 +388,13 @@ Insertar la cara A del disco 1 al cargar un juego FDS Aumentar la velocidad de la emulación de juegos de carga FDS Cambiar los discos automáticamente para juegos FDS + Atajos + Warning: Your current configuration contains conflicting key bindings. If this is not intentional, please review and correct your key bindings. Acción Atajo #1 Atajo #2 + Copias de seguridad Guardado de estado automático Crear una copia de seguridad de cada estado @@ -714,6 +717,42 @@ Habilitar/Deshabilitar códigos de trucos Habilitar/Deshabilitar sonido Ejecutar un sólo fotograma + + FDS - Eject Disk + Set Scale 1x + Set Scale 2x + Set Scale 3x + Set Scale 4x + Set Scale 5x + Set Scale 6x + Toggle Fullscreen Mode + Toggle FPS Counter + Toggle Maximum Speed + Load Random Game + Save State - Slot 1 + Save State - Slot 2 + Save State - Slot 3 + Save State - Slot 4 + Save State - Slot 5 + Save State - Slot 6 + Save State - Slot 7 + Save State to File + Load State - Slot 1 + Load State - Slot 2 + Load State - Slot 3 + Load State - Slot 4 + Load State - Slot 5 + Load State - Slot 6 + Load State - Slot 7 + Load State - Slot 8 + Load State from File + Open File + Open Debugger + Open Assembler + Open Ppu Viewer + Open Memory Tools + Open Script Window + Open Trace Logger diff --git a/GUI.NET/Dependencies/resources.fr.xml b/GUI.NET/Dependencies/resources.fr.xml index f17ec5e8..54495a86 100644 --- a/GUI.NET/Dependencies/resources.fr.xml +++ b/GUI.NET/Dependencies/resources.fr.xml @@ -200,7 +200,7 @@ Position d'affichage : Afficher horizontalement - Attention: Votre configuration actuel contient des conflicts - certaines touches sur votre clavier ou manetter sont mappées à plusieurs boutons sur la console. Veuillez réviser votre configuration et la corriger au besoin. + Attention: Votre configuration actuelle contient des conflicts - certaines touches sur votre clavier ou manette sont mappées à plusieurs boutons sur la console. Veuillez réviser votre configuration et la corriger au besoin.
Vitesse du mode turbo: @@ -400,6 +400,7 @@ minutes (Utilise ≈1MB/min) Raccourcis + Attention: Votre configuration actuelle contient des conflicts. Veuillez réviser votre configuration et la corriger au besoin. Action Raccourci #1 Raccourci #2 @@ -729,6 +730,42 @@ Activer/Désactiver tous les codes Activer/Désactiver l'audio Avancer d'une seule image + + FDS - Éjecter le disque + Taille de l'image 1x + Taille de l'image 2x + Taille de l'image 3x + Taille de l'image 4x + Taille de l'image 5x + Taille de l'image 6x + Activer/Désactiver le mode plein écran + Activer/Désactiver le compteur FPS + Activer/Désactiver la vitesse maximale + Ouvrir un jeu aléatoire + Sauvegarde d'état - Position 1 + Sauvegarde d'état - Position 2 + Sauvegarde d'état - Position 3 + Sauvegarde d'état - Position 4 + Sauvegarde d'état - Position 5 + Sauvegarde d'état - Position 6 + Sauvegarde d'état - Position 7 + Sauvergarde l'état dans un fichier + Chargement d'état - Position 1 + Chargement d'état - Position 2 + Chargement d'état - Position 3 + Chargement d'état - Position 4 + Chargement d'état - Position 5 + Chargement d'état - Position 6 + Chargement d'état - Position 7 + Chargement d'état - Position 8 + Charger l'état à partir d'un fichier + Ouvrir un fichier + Ouvrir le débogueur + Ouvrir l'assembleur + Ouvrir le visualiseur du PPU + Ouvrir les outils mémoire + Ouvrir une fenêtre de script + Ouvrir l'enregistreur de trace diff --git a/GUI.NET/Dependencies/resources.ja.xml b/GUI.NET/Dependencies/resources.ja.xml index a4e7b860..38b7e17f 100644 --- a/GUI.NET/Dependencies/resources.ja.xml +++ b/GUI.NET/Dependencies/resources.ja.xml @@ -35,6 +35,8 @@ 2倍 3倍 4倍 + 5倍 + 6倍 カスタム 全画面表示 画面エフェクト @@ -399,6 +401,7 @@ 分をキープする (メモリの使用量:1分に約1MB) ショートカットキー + 注意: 使っている設定の中には同じマッピングが何回もあります。 間違いでこの設定にした場合は、設定を確認して直してください。 機能 ショートカットキー1 ショートカットキー2 @@ -712,6 +715,42 @@ チートコードを無効・有効にする 音声を無効・有効にする 次のフレームを表す + + FDS - ディスクを取り出す + 映像サイズ 1倍 + 映像サイズ 2倍 + 映像サイズ 3倍 + 映像サイズ 4倍 + 映像サイズ 5倍 + 映像サイズ 6倍 + 全画面表示 + フレームレート表示 + 最高速度を無効・有効にする + ランダムゲームを開く + クイックセーブスロット1に保存する + クイックセーブスロット2に保存する + クイックセーブスロット3に保存する + クイックセーブスロット4に保存する + クイックセーブスロット5に保存する + クイックセーブスロット6に保存する + クイックセーブスロット7に保存する + クイックセーブデータをファイルに保存する + クイックセーブスロット1からロードする + クイックセーブスロット2からロードする + クイックセーブスロット3からロードする + クイックセーブスロット4からロードする + クイックセーブスロット5からロードする + クイックセーブスロット6からロードする + クイックセーブスロット7からロードする + クイックセーブスロット8からロードする + クイックセーブデータをファイルからロードする + ファイルを開く + デバッガを開く + アセンブラを開く + PPUビューアーを開く + メモリツールを開く + スクリプトウインドウを開く + トレースロガーを開く diff --git a/GUI.NET/Dependencies/resources.pt.xml b/GUI.NET/Dependencies/resources.pt.xml index 505ad930..65baa4ba 100644 --- a/GUI.NET/Dependencies/resources.pt.xml +++ b/GUI.NET/Dependencies/resources.pt.xml @@ -388,10 +388,13 @@ Inserir a parte A do disco 1 ao carregar um jogo FDS Aumentar a velocidade da emulação de jogos ao carregar no FDS Trocar automaticamente disquetes para os jogos do FDS + Atalhos + Warning: Your current configuration contains conflicting key bindings. If this is not intentional, please review and correct your key bindings. Ação Atalho #1 Atalho #2 + Cópias de segurança Salvar estado automático Salvar estado do jogo automaticamente a cada @@ -714,6 +717,42 @@ Habilitar/Desabilitar códigos de cheat Habilitar/Desabilitar áudio Executar um só quadro + + FDS - Eject Disk + Set Scale 1x + Set Scale 2x + Set Scale 3x + Set Scale 4x + Set Scale 5x + Set Scale 6x + Toggle Fullscreen Mode + Toggle FPS Counter + Toggle Maximum Speed + Load Random Game + Save State - Slot 1 + Save State - Slot 2 + Save State - Slot 3 + Save State - Slot 4 + Save State - Slot 5 + Save State - Slot 6 + Save State - Slot 7 + Save State to File + Load State - Slot 1 + Load State - Slot 2 + Load State - Slot 3 + Load State - Slot 4 + Load State - Slot 5 + Load State - Slot 6 + Load State - Slot 7 + Load State - Slot 8 + Load State from File + Open File + Open Debugger + Open Assembler + Open Ppu Viewer + Open Memory Tools + Open Script Window + Open Trace Logger diff --git a/GUI.NET/Dependencies/resources.ru.xml b/GUI.NET/Dependencies/resources.ru.xml index e1451727..ecdc8923 100644 --- a/GUI.NET/Dependencies/resources.ru.xml +++ b/GUI.NET/Dependencies/resources.ru.xml @@ -399,6 +399,7 @@ minutes (Memory Usage ≈1MB/min) Горячие клавиши + Warning: Your current configuration contains conflicting key bindings. If this is not intentional, please review and correct your key bindings. Действие Вариант #1 Вариант #2 @@ -719,6 +720,42 @@ Enable/Disable Cheat Codes Enable/Disable Audio Run Single Frame + + FDS - Eject Disk + Set Scale 1x + Set Scale 2x + Set Scale 3x + Set Scale 4x + Set Scale 5x + Set Scale 6x + Toggle Fullscreen Mode + Toggle FPS Counter + Toggle Maximum Speed + Load Random Game + Save State - Slot 1 + Save State - Slot 2 + Save State - Slot 3 + Save State - Slot 4 + Save State - Slot 5 + Save State - Slot 6 + Save State - Slot 7 + Save State to File + Load State - Slot 1 + Load State - Slot 2 + Load State - Slot 3 + Load State - Slot 4 + Load State - Slot 5 + Load State - Slot 6 + Load State - Slot 7 + Load State - Slot 8 + Load State from File + Open File + Open Debugger + Open Assembler + Open Ppu Viewer + Open Memory Tools + Open Script Window + Open Trace Logger diff --git a/GUI.NET/Dependencies/resources.uk.xml b/GUI.NET/Dependencies/resources.uk.xml index 608749f5..e894f850 100644 --- a/GUI.NET/Dependencies/resources.uk.xml +++ b/GUI.NET/Dependencies/resources.uk.xml @@ -399,6 +399,7 @@ хвилин (Використання Пам'яті ≈1 МБ/хв) Гарячі клавіші + Warning: Your current configuration contains conflicting key bindings. If this is not intentional, please review and correct your key bindings. Дія Варiант #1 Варiант #2 @@ -719,6 +720,42 @@ Включити/Виключити Чит Коди Увімкнути/Вимкнути звук Запуск Одного Кадру + + FDS - Eject Disk + Set Scale 1x + Set Scale 2x + Set Scale 3x + Set Scale 4x + Set Scale 5x + Set Scale 6x + Toggle Fullscreen Mode + Toggle FPS Counter + Toggle Maximum Speed + Load Random Game + Save State - Slot 1 + Save State - Slot 2 + Save State - Slot 3 + Save State - Slot 4 + Save State - Slot 5 + Save State - Slot 6 + Save State - Slot 7 + Save State to File + Load State - Slot 1 + Load State - Slot 2 + Load State - Slot 3 + Load State - Slot 4 + Load State - Slot 5 + Load State - Slot 6 + Load State - Slot 7 + Load State - Slot 8 + Load State from File + Open File + Open Debugger + Open Assembler + Open Ppu Viewer + Open Memory Tools + Open Script Window + Open Trace Logger diff --git a/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.Designer.cs b/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.Designer.cs index c26bf20a..dc72dcc2 100644 --- a/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.Designer.cs +++ b/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.Designer.cs @@ -31,7 +31,16 @@ this.colAction = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.colBinding1 = new System.Windows.Forms.DataGridViewButtonColumn(); this.colBinding2 = new System.Windows.Forms.DataGridViewButtonColumn(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.pnlConflictWarning = new System.Windows.Forms.Panel(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.picWarning = new System.Windows.Forms.PictureBox(); + this.lblShortcutWarning = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.gridShortcuts)).BeginInit(); + this.tableLayoutPanel1.SuspendLayout(); + this.pnlConflictWarning.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.picWarning)).BeginInit(); this.SuspendLayout(); // // gridShortcuts @@ -47,14 +56,16 @@ this.colBinding1, this.colBinding2}); this.gridShortcuts.Dock = System.Windows.Forms.DockStyle.Fill; - this.gridShortcuts.Location = new System.Drawing.Point(0, 0); + this.gridShortcuts.Location = new System.Drawing.Point(0, 32); + this.gridShortcuts.Margin = new System.Windows.Forms.Padding(0); this.gridShortcuts.MultiSelect = false; this.gridShortcuts.Name = "gridShortcuts"; this.gridShortcuts.RowHeadersVisible = false; this.gridShortcuts.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.gridShortcuts.Size = new System.Drawing.Size(448, 248); + this.gridShortcuts.Size = new System.Drawing.Size(448, 216); this.gridShortcuts.TabIndex = 2; this.gridShortcuts.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.gridShortcuts_CellContentClick); + this.gridShortcuts.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.gridShortcuts_CellMouseDown); // // colAction // @@ -78,15 +89,85 @@ this.colBinding2.Name = "colBinding2"; this.colBinding2.Resizable = System.Windows.Forms.DataGridViewTriState.False; this.colBinding2.Width = 110; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 1; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Controls.Add(this.pnlConflictWarning, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.gridShortcuts, 0, 1); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(448, 248); + this.tableLayoutPanel1.TabIndex = 3; + // + // pnlConflictWarning + // + this.pnlConflictWarning.BackColor = System.Drawing.Color.WhiteSmoke; + this.pnlConflictWarning.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pnlConflictWarning.Controls.Add(this.tableLayoutPanel2); + this.pnlConflictWarning.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlConflictWarning.Location = new System.Drawing.Point(0, 0); + this.pnlConflictWarning.Margin = new System.Windows.Forms.Padding(0, 0, 0, 2); + this.pnlConflictWarning.Name = "pnlConflictWarning"; + this.pnlConflictWarning.Size = new System.Drawing.Size(448, 30); + this.pnlConflictWarning.TabIndex = 20; + this.pnlConflictWarning.Visible = false; + // + // tableLayoutPanel2 + // + this.tableLayoutPanel2.ColumnCount = 2; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.Controls.Add(this.picWarning, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.lblShortcutWarning, 1, 0); + this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 1; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.Size = new System.Drawing.Size(446, 28); + this.tableLayoutPanel2.TabIndex = 0; + // + // picWarning + // + this.picWarning.Anchor = System.Windows.Forms.AnchorStyles.None; + this.picWarning.Image = global::Mesen.GUI.Properties.Resources.Warning; + this.picWarning.Location = new System.Drawing.Point(3, 6); + this.picWarning.Name = "picWarning"; + this.picWarning.Size = new System.Drawing.Size(16, 16); + this.picWarning.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.picWarning.TabIndex = 0; + this.picWarning.TabStop = false; + // + // lblShortcutWarning + // + this.lblShortcutWarning.Dock = System.Windows.Forms.DockStyle.Fill; + this.lblShortcutWarning.Location = new System.Drawing.Point(25, 0); + this.lblShortcutWarning.Name = "lblShortcutWarning"; + this.lblShortcutWarning.Size = new System.Drawing.Size(418, 28); + this.lblShortcutWarning.TabIndex = 1; + this.lblShortcutWarning.Text = "Warning: Your current configuration contains conflicting key bindings. If this is" + + " not intentional, please review and correct your key bindings."; // // ctrlEmulatorShortcuts // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.gridShortcuts); + this.Controls.Add(this.tableLayoutPanel1); this.Name = "ctrlEmulatorShortcuts"; this.Size = new System.Drawing.Size(448, 248); ((System.ComponentModel.ISupportInitialize)(this.gridShortcuts)).EndInit(); + this.tableLayoutPanel1.ResumeLayout(false); + this.pnlConflictWarning.ResumeLayout(false); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.picWarning)).EndInit(); this.ResumeLayout(false); } @@ -96,5 +177,10 @@ private System.Windows.Forms.DataGridViewTextBoxColumn colAction; private System.Windows.Forms.DataGridViewButtonColumn colBinding1; private System.Windows.Forms.DataGridViewButtonColumn colBinding2; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Panel pnlConflictWarning; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.PictureBox picWarning; + private System.Windows.Forms.Label lblShortcutWarning; } } diff --git a/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.cs b/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.cs index 9aca3f9c..10c2e033 100644 --- a/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.cs +++ b/GUI.NET/Forms/Config/ctrlEmulatorShortcuts.cs @@ -4,6 +4,7 @@ using System.Windows.Forms; using Mesen.GUI.Config; using System.Reflection; using Mesen.GUI.Controls; +using System.Collections.Generic; namespace Mesen.GUI.Forms.Config { @@ -20,36 +21,150 @@ namespace Mesen.GUI.Forms.Config private void InitializeGrid() { - FieldInfo[] fields = typeof(EmulatorKeyMappings).GetFields(); - foreach(FieldInfo fieldInfo in fields) { - int index = gridShortcuts.Rows.Add(); - gridShortcuts.Rows[index].Cells[0].Tag = fieldInfo; - gridShortcuts.Rows[index].Cells[0].Value = ResourceHelper.GetMessage("EmulatorShortcutMappings_" + fieldInfo.Name); + EmulatorShortcut[] displayOrder = new EmulatorShortcut[] { + EmulatorShortcut.FastForward, + EmulatorShortcut.Rewind, + EmulatorShortcut.RewindTenSecs, + EmulatorShortcut.RewindOneMin, - UInt32 keyCode = (UInt32)fieldInfo.GetValue(ConfigManager.Config.PreferenceInfo.EmulatorKeySet1); - gridShortcuts.Rows[index].Cells[1].Value = InteropEmu.GetKeyName(keyCode); - gridShortcuts.Rows[index].Cells[1].Tag = keyCode; + EmulatorShortcut.Pause, + EmulatorShortcut.Reset, + EmulatorShortcut.PowerCycle, + EmulatorShortcut.PowerOff, + EmulatorShortcut.Exit, - keyCode = (UInt32)fieldInfo.GetValue(ConfigManager.Config.PreferenceInfo.EmulatorKeySet2); - gridShortcuts.Rows[index].Cells[2].Value = InteropEmu.GetKeyName(keyCode); - gridShortcuts.Rows[index].Cells[2].Tag = keyCode; + EmulatorShortcut.InsertNextDisk, + EmulatorShortcut.SwitchDiskSide, + EmulatorShortcut.EjectDisk, + + EmulatorShortcut.InsertCoin1, + EmulatorShortcut.InsertCoin2, + EmulatorShortcut.VsServiceButton, + + EmulatorShortcut.TakeScreenshot, + EmulatorShortcut.LoadRandomGame, + EmulatorShortcut.RunSingleFrame, + + EmulatorShortcut.SetScale1x, + EmulatorShortcut.SetScale2x, + EmulatorShortcut.SetScale3x, + EmulatorShortcut.SetScale4x, + EmulatorShortcut.SetScale5x, + EmulatorShortcut.SetScale6x, + EmulatorShortcut.ToggleFullscreen, + + EmulatorShortcut.ToggleFps, + EmulatorShortcut.ToggleCheats, + EmulatorShortcut.ToggleAudio, + + EmulatorShortcut.MaxSpeed, + EmulatorShortcut.IncreaseSpeed, + EmulatorShortcut.DecreaseSpeed, + + EmulatorShortcut.OpenFile, + EmulatorShortcut.OpenDebugger, + EmulatorShortcut.OpenAssembler, + EmulatorShortcut.OpenPpuViewer, + EmulatorShortcut.OpenMemoryTools, + EmulatorShortcut.OpenScriptWindow, + EmulatorShortcut.OpenTraceLogger, + + EmulatorShortcut.MoveToNextStateSlot, + EmulatorShortcut.MoveToPreviousStateSlot, + EmulatorShortcut.SaveState, + EmulatorShortcut.LoadState, + + EmulatorShortcut.SaveStateSlot1, + EmulatorShortcut.SaveStateSlot2, + EmulatorShortcut.SaveStateSlot3, + EmulatorShortcut.SaveStateSlot4, + EmulatorShortcut.SaveStateSlot5, + EmulatorShortcut.SaveStateSlot6, + EmulatorShortcut.SaveStateSlot7, + EmulatorShortcut.SaveStateToFile, + + EmulatorShortcut.LoadStateSlot1, + EmulatorShortcut.LoadStateSlot2, + EmulatorShortcut.LoadStateSlot3, + EmulatorShortcut.LoadStateSlot4, + EmulatorShortcut.LoadStateSlot5, + EmulatorShortcut.LoadStateSlot6, + EmulatorShortcut.LoadStateSlot7, + EmulatorShortcut.LoadStateSlot8, + EmulatorShortcut.LoadStateFromFile, + }; + + HashSet keyCombinations = new HashSet(); + + foreach(EmulatorShortcut shortcut in displayOrder) { + int i = gridShortcuts.Rows.Add(); + gridShortcuts.Rows[i].Cells[0].Tag = shortcut; + gridShortcuts.Rows[i].Cells[0].Value = ResourceHelper.GetMessage("EmulatorShortcutMappings_" + shortcut.ToString()); + + int keyIndex = ConfigManager.Config.PreferenceInfo.ShortcutKeys1.FindIndex((ShortcutKeyInfo shortcutInfo) => shortcutInfo.Shortcut == shortcut); + if(keyIndex >= 0) { + KeyCombination keyComb = ConfigManager.Config.PreferenceInfo.ShortcutKeys1[keyIndex].KeyCombination; + keyCombinations.Add(keyComb.ToString()); + gridShortcuts.Rows[i].Cells[1].Value = keyComb.ToString(); + gridShortcuts.Rows[i].Cells[1].Tag = keyComb; + } + + keyIndex = ConfigManager.Config.PreferenceInfo.ShortcutKeys2.FindIndex((ShortcutKeyInfo shortcutInfo) => shortcutInfo.Shortcut == shortcut); + if(keyIndex >= 0) { + KeyCombination keyComb = ConfigManager.Config.PreferenceInfo.ShortcutKeys2[keyIndex].KeyCombination; + keyCombinations.Add(keyComb.ToString()); + gridShortcuts.Rows[i].Cells[2].Value = keyComb.ToString(); + gridShortcuts.Rows[i].Cells[2].Tag = keyComb; + } } + + CheckConflicts(); + } + + private void CheckConflicts() + { + HashSet keyCombinations = new HashSet(); + + for(int i = gridShortcuts.Rows.Count - 1; i >= 0; i--) { + EmulatorShortcut shortcut = (EmulatorShortcut)gridShortcuts.Rows[i].Cells[0].Tag; + for(int j = 1; j <= 2; j++) { + if(gridShortcuts.Rows[i].Cells[j].Tag != null) { + KeyCombination keyComb = (KeyCombination)gridShortcuts.Rows[i].Cells[j].Tag; + if(!keyComb.IsEmpty && !keyCombinations.Add(keyComb.ToString())) { + pnlConflictWarning.Visible = true; + return; + } + } + } + } + + pnlConflictWarning.Visible = false; } public void UpdateConfig() { //Need to box the structs into objects for SetValue to work properly - object keySet1 = new EmulatorKeyMappings(); - object keySet2 = new EmulatorKeyMappings(); + var keySet1 = new List(); + var keySet2 = new List(); for(int i = gridShortcuts.Rows.Count - 1; i >= 0; i--) { - FieldInfo field = (FieldInfo)gridShortcuts.Rows[i].Cells[0].Tag; - field.SetValue(keySet1, gridShortcuts.Rows[i].Cells[1].Tag); - field.SetValue(keySet2, gridShortcuts.Rows[i].Cells[2].Tag); + EmulatorShortcut shortcut = (EmulatorShortcut)gridShortcuts.Rows[i].Cells[0].Tag; + if(gridShortcuts.Rows[i].Cells[1].Tag != null) { + KeyCombination keyComb = (KeyCombination)gridShortcuts.Rows[i].Cells[1].Tag; + if(!keyComb.IsEmpty) { + keySet1.Add(new ShortcutKeyInfo(shortcut, keyComb)); + } + } + if(gridShortcuts.Rows[i].Cells[2].Tag != null) { + KeyCombination keyComb = (KeyCombination)gridShortcuts.Rows[i].Cells[2].Tag; + if(!keyComb.IsEmpty) { + keySet2.Add(new ShortcutKeyInfo(shortcut, keyComb)); + } + } } - ConfigManager.Config.PreferenceInfo.EmulatorKeySet1 = (EmulatorKeyMappings)keySet1; - ConfigManager.Config.PreferenceInfo.EmulatorKeySet2 = (EmulatorKeyMappings)keySet2; + ConfigManager.Config.PreferenceInfo.ShortcutKeys1 = keySet1; + ConfigManager.Config.PreferenceInfo.ShortcutKeys2 = keySet2; } private void gridShortcuts_CellContentClick(object sender, DataGridViewCellEventArgs e) @@ -57,10 +172,26 @@ namespace Mesen.GUI.Forms.Config if(gridShortcuts.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { DataGridViewButtonCell button = gridShortcuts.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell; if(button != null) { - frmGetKey frm = new frmGetKey(); - frm.ShowDialog(); - button.Value = frm.BindedKeyName; - button.Tag = frm.BindedKeyCode; + using(frmGetKey frm = new frmGetKey(false)) { + frm.ShowDialog(); + button.Value = frm.ShortcutKey.ToString(); + button.Tag = frm.ShortcutKey; + + CheckConflicts(); + } + } + } + } + + private void gridShortcuts_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) + { + //Right-click on buttons to clear mappings + if(e.Button == MouseButtons.Right && gridShortcuts.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { + DataGridViewButtonCell button = gridShortcuts.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell; + if(button != null) { + button.Value = ""; + button.Tag = new KeyCombination(); + CheckConflicts(); } } } diff --git a/GUI.NET/Forms/Config/ctrlStandardController.cs b/GUI.NET/Forms/Config/ctrlStandardController.cs index 32b578cc..79b9afdd 100644 --- a/GUI.NET/Forms/Config/ctrlStandardController.cs +++ b/GUI.NET/Forms/Config/ctrlStandardController.cs @@ -126,11 +126,11 @@ namespace Mesen.GUI.Forms.Config private void btnMapping_Click(object sender, EventArgs e) { - frmGetKey frm = new frmGetKey(); - frm.ShowDialog(); - ((Button)sender).Text = frm.BindedKeyName; - ((Button)sender).Tag = frm.BindedKeyCode; - + using(frmGetKey frm = new frmGetKey(true)) { + frm.ShowDialog(); + ((Button)sender).Text = frm.ShortcutKey.ToString(); + ((Button)sender).Tag = frm.ShortcutKey.Key1; + } this.OnChange?.Invoke(this, null); } diff --git a/GUI.NET/Forms/Config/frmGetKey.Designer.cs b/GUI.NET/Forms/Config/frmGetKey.Designer.cs index ecd9eca5..ecdd946f 100644 --- a/GUI.NET/Forms/Config/frmGetKey.Designer.cs +++ b/GUI.NET/Forms/Config/frmGetKey.Designer.cs @@ -29,6 +29,7 @@ { this.components = new System.ComponentModel.Container(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.lblCurrentKeys = new System.Windows.Forms.Label(); this.lblSetKeyMessage = new System.Windows.Forms.Label(); this.tmrCheckKey = new System.Windows.Forms.Timer(this.components); this.groupBox1.SuspendLayout(); @@ -37,18 +38,28 @@ // groupBox1 // this.groupBox1.Controls.Add(this.lblSetKeyMessage); + this.groupBox1.Controls.Add(this.lblCurrentKeys); this.groupBox1.Location = new System.Drawing.Point(4, -1); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(369, 102); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; // + // lblCurrentKeys + // + this.lblCurrentKeys.Dock = System.Windows.Forms.DockStyle.Bottom; + this.lblCurrentKeys.Location = new System.Drawing.Point(3, 55); + this.lblCurrentKeys.Name = "lblCurrentKeys"; + this.lblCurrentKeys.Size = new System.Drawing.Size(363, 44); + this.lblCurrentKeys.TabIndex = 1; + this.lblCurrentKeys.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // lblSetKeyMessage // this.lblSetKeyMessage.Dock = System.Windows.Forms.DockStyle.Fill; this.lblSetKeyMessage.Location = new System.Drawing.Point(3, 16); this.lblSetKeyMessage.Name = "lblSetKeyMessage"; - this.lblSetKeyMessage.Size = new System.Drawing.Size(363, 83); + this.lblSetKeyMessage.Size = new System.Drawing.Size(363, 39); this.lblSetKeyMessage.TabIndex = 0; this.lblSetKeyMessage.Text = "Press any key on your keyboard or controller to set a new binding."; this.lblSetKeyMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -79,5 +90,6 @@ private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label lblSetKeyMessage; private System.Windows.Forms.Timer tmrCheckKey; + private System.Windows.Forms.Label lblCurrentKeys; } } \ No newline at end of file diff --git a/GUI.NET/Forms/Config/frmGetKey.cs b/GUI.NET/Forms/Config/frmGetKey.cs index 77e3238c..ffaf0f49 100644 --- a/GUI.NET/Forms/Config/frmGetKey.cs +++ b/GUI.NET/Forms/Config/frmGetKey.cs @@ -14,52 +14,71 @@ namespace Mesen.GUI.Forms.Config { const int WM_KEYDOWN = 0x100; const int WM_KEYUP = 0x101; + const int WM_SYSKEYDOWN = 0x104; + const int WM_SYSKEYUP = 0x105; + private bool _singleKeyMode = false; private string[] _invalidKeys = new string[] { "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12" }; - public frmGetKey() + public frmGetKey(bool singleKeyMode) { InitializeComponent(); + _singleKeyMode = singleKeyMode; + if(_singleKeyMode) { + lblCurrentKeys.Height = 1; + lblCurrentKeys.Visible = false; + } + ShortcutKey = new KeyCombination(); InteropEmu.UpdateInputDevices(); InteropEmu.ResetKeyState(); + + //Prevent other keybindings from interfering/activating + InteropEmu.DisableAllKeys(true); + Application.AddMessageFilter(this); - this.FormClosed += (s, e) => Application.RemoveMessageFilter(this); } bool IMessageFilter.PreFilterMessage(ref Message m) { - if(m.Msg == WM_KEYUP) { + if(m.Msg == WM_KEYUP || m.Msg == WM_SYSKEYUP) { int virtualKeyCode = (Int32)m.WParam; int scanCode = (Int32)(((Int64)m.LParam & 0x1FF0000) >> 16); InteropEmu.SetKeyState(scanCode, false); + } else if(m.Msg == WM_SYSKEYDOWN || m.Msg == WM_KEYDOWN) { + int virtualKeyCode = (Int32)((Int64)m.WParam & 0xFF); + int scanCode = (Int32)(((Int64)m.LParam & 0x1FF0000) >> 16); + InteropEmu.SetKeyState(scanCode, true); } return false; } - protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + protected override void OnFormClosing(FormClosingEventArgs e) { - if(msg.Msg == WM_KEYDOWN) { - int virtualKeyCode = (Int32)((Int64)msg.WParam & 0xFF); - int scanCode = (Int32)(((Int64)msg.LParam & 0x1FF0000) >> 16); - InteropEmu.SetKeyState(scanCode, true); - } - - return base.ProcessCmdKey(ref msg, keyData); + Application.RemoveMessageFilter(this); + InteropEmu.ResetKeyState(); + InteropEmu.DisableAllKeys(false); + base.OnFormClosing(e); } - public string BindedKeyName { get; set; } - public UInt32 BindedKeyCode { get; set; } + public KeyCombination ShortcutKey { get; set; } + private List _prevScanCodes = new List(); private void tmrCheckKey_Tick(object sender, EventArgs e) { - UInt32 scanCode = InteropEmu.GetPressedKey(); - string pressedKey = InteropEmu.GetKeyName(scanCode); - if(!string.IsNullOrWhiteSpace(pressedKey) && !_invalidKeys.Contains(pressedKey)) { - BindedKeyName = pressedKey; - BindedKeyCode = scanCode; - this.Close(); + List scanCodes = InteropEmu.GetPressedKeys(); + + KeyCombination key = new KeyCombination(_prevScanCodes); + lblCurrentKeys.Text = key.ToString(); + + if(_singleKeyMode && _prevScanCodes.Count > 0 || scanCodes.Count < _prevScanCodes.Count) { + if(!string.IsNullOrWhiteSpace(key.ToString())) { + ShortcutKey = key; + this.Close(); + } } + + _prevScanCodes = scanCodes; } } } diff --git a/GUI.NET/Forms/Config/frmGetKey.resx b/GUI.NET/Forms/Config/frmGetKey.resx index 2419cddd..bba63791 100644 --- a/GUI.NET/Forms/Config/frmGetKey.resx +++ b/GUI.NET/Forms/Config/frmGetKey.resx @@ -117,7 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 + + 107, 17 + \ No newline at end of file diff --git a/GUI.NET/Forms/frmMain.Designer.cs b/GUI.NET/Forms/frmMain.Designer.cs index 80854572..d9056ea2 100644 --- a/GUI.NET/Forms/frmMain.Designer.cs +++ b/GUI.NET/Forms/frmMain.Designer.cs @@ -337,53 +337,50 @@ namespace Mesen.GUI.Forms // this.mnuOpen.Image = global::Mesen.GUI.Properties.Resources.FolderOpen; this.mnuOpen.Name = "mnuOpen"; - this.mnuOpen.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); - this.mnuOpen.Size = new System.Drawing.Size(146, 22); + this.mnuOpen.Size = new System.Drawing.Size(136, 22); this.mnuOpen.Text = "Open"; - this.mnuOpen.Click += new System.EventHandler(this.mnuOpen_Click); // // toolStripMenuItem4 // this.toolStripMenuItem4.Name = "toolStripMenuItem4"; - this.toolStripMenuItem4.Size = new System.Drawing.Size(143, 6); + this.toolStripMenuItem4.Size = new System.Drawing.Size(133, 6); // // mnuSaveState // this.mnuSaveState.Name = "mnuSaveState"; - this.mnuSaveState.Size = new System.Drawing.Size(146, 22); + this.mnuSaveState.Size = new System.Drawing.Size(136, 22); this.mnuSaveState.Text = "Save State"; this.mnuSaveState.DropDownOpening += new System.EventHandler(this.mnuSaveState_DropDownOpening); // // mnuLoadState // this.mnuLoadState.Name = "mnuLoadState"; - this.mnuLoadState.Size = new System.Drawing.Size(146, 22); + this.mnuLoadState.Size = new System.Drawing.Size(136, 22); this.mnuLoadState.Text = "Load State"; this.mnuLoadState.DropDownOpening += new System.EventHandler(this.mnuLoadState_DropDownOpening); // // toolStripMenuItem7 // this.toolStripMenuItem7.Name = "toolStripMenuItem7"; - this.toolStripMenuItem7.Size = new System.Drawing.Size(143, 6); + this.toolStripMenuItem7.Size = new System.Drawing.Size(133, 6); // // mnuRecentFiles // this.mnuRecentFiles.Name = "mnuRecentFiles"; - this.mnuRecentFiles.Size = new System.Drawing.Size(146, 22); + this.mnuRecentFiles.Size = new System.Drawing.Size(136, 22); this.mnuRecentFiles.Text = "Recent Files"; // // toolStripMenuItem6 // this.toolStripMenuItem6.Name = "toolStripMenuItem6"; - this.toolStripMenuItem6.Size = new System.Drawing.Size(143, 6); + this.toolStripMenuItem6.Size = new System.Drawing.Size(133, 6); // // mnuExit // this.mnuExit.Image = global::Mesen.GUI.Properties.Resources.Exit; this.mnuExit.Name = "mnuExit"; - this.mnuExit.Size = new System.Drawing.Size(146, 22); + this.mnuExit.Size = new System.Drawing.Size(136, 22); this.mnuExit.Text = "Exit"; - this.mnuExit.Click += new System.EventHandler(this.mnuExit_Click); // // mnuGame // @@ -410,83 +407,73 @@ namespace Mesen.GUI.Forms this.mnuPause.Enabled = false; this.mnuPause.Image = global::Mesen.GUI.Properties.Resources.Pause; this.mnuPause.Name = "mnuPause"; - this.mnuPause.ShortcutKeyDisplayString = "Esc"; - this.mnuPause.Size = new System.Drawing.Size(200, 22); + this.mnuPause.Size = new System.Drawing.Size(182, 22); this.mnuPause.Text = "Pause"; - this.mnuPause.Click += new System.EventHandler(this.mnuPause_Click); // // mnuReset // this.mnuReset.Enabled = false; this.mnuReset.Image = global::Mesen.GUI.Properties.Resources.Reset; this.mnuReset.Name = "mnuReset"; - this.mnuReset.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.R))); - this.mnuReset.Size = new System.Drawing.Size(200, 22); + this.mnuReset.Size = new System.Drawing.Size(182, 22); this.mnuReset.Text = "Reset"; - this.mnuReset.Click += new System.EventHandler(this.mnuReset_Click); // // mnuPowerCycle // this.mnuPowerCycle.Enabled = false; this.mnuPowerCycle.Image = global::Mesen.GUI.Properties.Resources.PowerCycle; this.mnuPowerCycle.Name = "mnuPowerCycle"; - this.mnuPowerCycle.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); - this.mnuPowerCycle.Size = new System.Drawing.Size(200, 22); + this.mnuPowerCycle.Size = new System.Drawing.Size(182, 22); this.mnuPowerCycle.Text = "Power Cycle"; - this.mnuPowerCycle.Click += new System.EventHandler(this.mnuPowerCycle_Click); // // toolStripMenuItem24 // this.toolStripMenuItem24.Name = "toolStripMenuItem24"; - this.toolStripMenuItem24.Size = new System.Drawing.Size(197, 6); + this.toolStripMenuItem24.Size = new System.Drawing.Size(179, 6); // // mnuPowerOff // this.mnuPowerOff.Image = global::Mesen.GUI.Properties.Resources.Stop; this.mnuPowerOff.Name = "mnuPowerOff"; - this.mnuPowerOff.Size = new System.Drawing.Size(200, 22); + this.mnuPowerOff.Size = new System.Drawing.Size(182, 22); this.mnuPowerOff.Text = "Power Off"; - this.mnuPowerOff.Click += new System.EventHandler(this.mnuPowerOff_Click); // // sepFdsDisk // this.sepFdsDisk.Name = "sepFdsDisk"; - this.sepFdsDisk.Size = new System.Drawing.Size(197, 6); + this.sepFdsDisk.Size = new System.Drawing.Size(179, 6); // // mnuSwitchDiskSide // this.mnuSwitchDiskSide.Name = "mnuSwitchDiskSide"; - this.mnuSwitchDiskSide.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.B))); - this.mnuSwitchDiskSide.Size = new System.Drawing.Size(200, 22); + this.mnuSwitchDiskSide.Size = new System.Drawing.Size(182, 22); this.mnuSwitchDiskSide.Text = "Switch Disk Side"; - this.mnuSwitchDiskSide.Click += new System.EventHandler(this.mnuSwitchDiskSide_Click); // // mnuSelectDisk // this.mnuSelectDisk.Image = global::Mesen.GUI.Properties.Resources.Floppy; this.mnuSelectDisk.Name = "mnuSelectDisk"; - this.mnuSelectDisk.Size = new System.Drawing.Size(200, 22); + this.mnuSelectDisk.Size = new System.Drawing.Size(182, 22); this.mnuSelectDisk.Text = "Select Disk"; // // mnuEjectDisk // this.mnuEjectDisk.Image = global::Mesen.GUI.Properties.Resources.Eject; this.mnuEjectDisk.Name = "mnuEjectDisk"; - this.mnuEjectDisk.Size = new System.Drawing.Size(200, 22); + this.mnuEjectDisk.Size = new System.Drawing.Size(182, 22); this.mnuEjectDisk.Text = "Eject Disk"; - this.mnuEjectDisk.Click += new System.EventHandler(this.mnuEjectDisk_Click); // // sepVsSystem // this.sepVsSystem.Name = "sepVsSystem"; - this.sepVsSystem.Size = new System.Drawing.Size(197, 6); + this.sepVsSystem.Size = new System.Drawing.Size(179, 6); this.sepVsSystem.Visible = false; // // mnuVsGameConfig // this.mnuVsGameConfig.Image = global::Mesen.GUI.Properties.Resources.DipSwitches; this.mnuVsGameConfig.Name = "mnuVsGameConfig"; - this.mnuVsGameConfig.Size = new System.Drawing.Size(200, 22); + this.mnuVsGameConfig.Size = new System.Drawing.Size(182, 22); this.mnuVsGameConfig.Text = "Game Configuration"; this.mnuVsGameConfig.Click += new System.EventHandler(this.mnuVsGameConfig_Click); // @@ -494,19 +481,17 @@ namespace Mesen.GUI.Forms // this.mnuInsertCoin1.Image = global::Mesen.GUI.Properties.Resources.coins; this.mnuInsertCoin1.Name = "mnuInsertCoin1"; - this.mnuInsertCoin1.Size = new System.Drawing.Size(200, 22); + this.mnuInsertCoin1.Size = new System.Drawing.Size(182, 22); this.mnuInsertCoin1.Text = "Insert Coin (1)"; this.mnuInsertCoin1.Visible = false; - this.mnuInsertCoin1.Click += new System.EventHandler(this.mnuInsertCoin1_Click); // // mnuInsertCoin2 // this.mnuInsertCoin2.Image = global::Mesen.GUI.Properties.Resources.coins; this.mnuInsertCoin2.Name = "mnuInsertCoin2"; - this.mnuInsertCoin2.Size = new System.Drawing.Size(200, 22); + this.mnuInsertCoin2.Size = new System.Drawing.Size(182, 22); this.mnuInsertCoin2.Text = "Insert Coin (2)"; this.mnuInsertCoin2.Visible = false; - this.mnuInsertCoin2.Click += new System.EventHandler(this.mnuInsertCoin2_Click); // // mnuOptions // @@ -550,48 +535,42 @@ namespace Mesen.GUI.Forms // mnuEmuSpeedNormal // this.mnuEmuSpeedNormal.Name = "mnuEmuSpeedNormal"; - this.mnuEmuSpeedNormal.Size = new System.Drawing.Size(182, 22); + this.mnuEmuSpeedNormal.Size = new System.Drawing.Size(163, 22); this.mnuEmuSpeedNormal.Text = "Normal (100%)"; this.mnuEmuSpeedNormal.Click += new System.EventHandler(this.mnuEmulationSpeedOption_Click); // // toolStripMenuItem8 // this.toolStripMenuItem8.Name = "toolStripMenuItem8"; - this.toolStripMenuItem8.Size = new System.Drawing.Size(179, 6); + this.toolStripMenuItem8.Size = new System.Drawing.Size(160, 6); // // mnuIncreaseSpeed // this.mnuIncreaseSpeed.Name = "mnuIncreaseSpeed"; - this.mnuIncreaseSpeed.ShortcutKeyDisplayString = "="; - this.mnuIncreaseSpeed.Size = new System.Drawing.Size(182, 22); + this.mnuIncreaseSpeed.Size = new System.Drawing.Size(163, 22); this.mnuIncreaseSpeed.Text = "Increase Speed"; - this.mnuIncreaseSpeed.Click += new System.EventHandler(this.mnuIncreaseSpeed_Click); // // mnuDecreaseSpeed // this.mnuDecreaseSpeed.Name = "mnuDecreaseSpeed"; - this.mnuDecreaseSpeed.ShortcutKeyDisplayString = "-"; - this.mnuDecreaseSpeed.Size = new System.Drawing.Size(182, 22); + this.mnuDecreaseSpeed.Size = new System.Drawing.Size(163, 22); this.mnuDecreaseSpeed.Text = "Decrease Speed"; - this.mnuDecreaseSpeed.Click += new System.EventHandler(this.mnuDecreaseSpeed_Click); // // mnuEmuSpeedMaximumSpeed // this.mnuEmuSpeedMaximumSpeed.Name = "mnuEmuSpeedMaximumSpeed"; - this.mnuEmuSpeedMaximumSpeed.ShortcutKeys = System.Windows.Forms.Keys.F9; - this.mnuEmuSpeedMaximumSpeed.Size = new System.Drawing.Size(182, 22); + this.mnuEmuSpeedMaximumSpeed.Size = new System.Drawing.Size(163, 22); this.mnuEmuSpeedMaximumSpeed.Text = "Maximum Speed"; - this.mnuEmuSpeedMaximumSpeed.Click += new System.EventHandler(this.mnuEmuSpeedMaximumSpeed_Click); // // toolStripMenuItem9 // this.toolStripMenuItem9.Name = "toolStripMenuItem9"; - this.toolStripMenuItem9.Size = new System.Drawing.Size(179, 6); + this.toolStripMenuItem9.Size = new System.Drawing.Size(160, 6); // // mnuEmuSpeedTriple // this.mnuEmuSpeedTriple.Name = "mnuEmuSpeedTriple"; - this.mnuEmuSpeedTriple.Size = new System.Drawing.Size(182, 22); + this.mnuEmuSpeedTriple.Size = new System.Drawing.Size(163, 22); this.mnuEmuSpeedTriple.Tag = ""; this.mnuEmuSpeedTriple.Text = "Triple (300%)"; this.mnuEmuSpeedTriple.Click += new System.EventHandler(this.mnuEmulationSpeedOption_Click); @@ -599,37 +578,35 @@ namespace Mesen.GUI.Forms // mnuEmuSpeedDouble // this.mnuEmuSpeedDouble.Name = "mnuEmuSpeedDouble"; - this.mnuEmuSpeedDouble.Size = new System.Drawing.Size(182, 22); + this.mnuEmuSpeedDouble.Size = new System.Drawing.Size(163, 22); this.mnuEmuSpeedDouble.Text = "Double (200%)"; this.mnuEmuSpeedDouble.Click += new System.EventHandler(this.mnuEmulationSpeedOption_Click); // // mnuEmuSpeedHalf // this.mnuEmuSpeedHalf.Name = "mnuEmuSpeedHalf"; - this.mnuEmuSpeedHalf.Size = new System.Drawing.Size(182, 22); + this.mnuEmuSpeedHalf.Size = new System.Drawing.Size(163, 22); this.mnuEmuSpeedHalf.Text = "Half (50%)"; this.mnuEmuSpeedHalf.Click += new System.EventHandler(this.mnuEmulationSpeedOption_Click); // // mnuEmuSpeedQuarter // this.mnuEmuSpeedQuarter.Name = "mnuEmuSpeedQuarter"; - this.mnuEmuSpeedQuarter.Size = new System.Drawing.Size(182, 22); + this.mnuEmuSpeedQuarter.Size = new System.Drawing.Size(163, 22); this.mnuEmuSpeedQuarter.Text = "Quarter (25%)"; this.mnuEmuSpeedQuarter.Click += new System.EventHandler(this.mnuEmulationSpeedOption_Click); // // toolStripMenuItem14 // this.toolStripMenuItem14.Name = "toolStripMenuItem14"; - this.toolStripMenuItem14.Size = new System.Drawing.Size(179, 6); + this.toolStripMenuItem14.Size = new System.Drawing.Size(160, 6); // // mnuShowFPS // this.mnuShowFPS.CheckOnClick = true; this.mnuShowFPS.Name = "mnuShowFPS"; - this.mnuShowFPS.ShortcutKeys = System.Windows.Forms.Keys.F10; - this.mnuShowFPS.Size = new System.Drawing.Size(182, 22); + this.mnuShowFPS.Size = new System.Drawing.Size(163, 22); this.mnuShowFPS.Text = "Show FPS"; - this.mnuShowFPS.Click += new System.EventHandler(this.mnuShowFPS_Click); // // mnuVideoScale // @@ -650,69 +627,49 @@ namespace Mesen.GUI.Forms // mnuScale1x // this.mnuScale1x.Name = "mnuScale1x"; - this.mnuScale1x.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D1))); - this.mnuScale1x.Size = new System.Drawing.Size(152, 22); - this.mnuScale1x.Tag = "1"; + this.mnuScale1x.Size = new System.Drawing.Size(127, 22); this.mnuScale1x.Text = "1x"; - this.mnuScale1x.Click += new System.EventHandler(this.mnuScale_Click); // // mnuScale2x // this.mnuScale2x.Name = "mnuScale2x"; - this.mnuScale2x.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D2))); - this.mnuScale2x.Size = new System.Drawing.Size(152, 22); - this.mnuScale2x.Tag = "2"; + this.mnuScale2x.Size = new System.Drawing.Size(127, 22); this.mnuScale2x.Text = "2x"; - this.mnuScale2x.Click += new System.EventHandler(this.mnuScale_Click); // // mnuScale3x // this.mnuScale3x.Name = "mnuScale3x"; - this.mnuScale3x.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D3))); - this.mnuScale3x.Size = new System.Drawing.Size(152, 22); - this.mnuScale3x.Tag = "3"; + this.mnuScale3x.Size = new System.Drawing.Size(127, 22); this.mnuScale3x.Text = "3x"; - this.mnuScale3x.Click += new System.EventHandler(this.mnuScale_Click); // // mnuScale4x // this.mnuScale4x.Name = "mnuScale4x"; - this.mnuScale4x.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D4))); - this.mnuScale4x.Size = new System.Drawing.Size(152, 22); - this.mnuScale4x.Tag = "4"; + this.mnuScale4x.Size = new System.Drawing.Size(127, 22); this.mnuScale4x.Text = "4x"; - this.mnuScale4x.Click += new System.EventHandler(this.mnuScale_Click); // // mnuScale5x // this.mnuScale5x.Name = "mnuScale5x"; - this.mnuScale5x.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D5))); - this.mnuScale5x.Size = new System.Drawing.Size(152, 22); - this.mnuScale5x.Tag = "5"; + this.mnuScale5x.Size = new System.Drawing.Size(127, 22); this.mnuScale5x.Text = "5x"; - this.mnuScale5x.Click += new System.EventHandler(this.mnuScale_Click); // // mnuScale6x // this.mnuScale6x.Name = "mnuScale6x"; - this.mnuScale6x.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D6))); - this.mnuScale6x.Size = new System.Drawing.Size(152, 22); - this.mnuScale6x.Tag = "6"; + this.mnuScale6x.Size = new System.Drawing.Size(127, 22); this.mnuScale6x.Text = "6x"; - this.mnuScale6x.Click += new System.EventHandler(this.mnuScale_Click); // // toolStripMenuItem13 // this.toolStripMenuItem13.Name = "toolStripMenuItem13"; - this.toolStripMenuItem13.Size = new System.Drawing.Size(149, 6); + this.toolStripMenuItem13.Size = new System.Drawing.Size(124, 6); // // mnuFullscreen // this.mnuFullscreen.Name = "mnuFullscreen"; - this.mnuFullscreen.ShortcutKeys = System.Windows.Forms.Keys.F11; - this.mnuFullscreen.Size = new System.Drawing.Size(152, 22); + this.mnuFullscreen.Size = new System.Drawing.Size(127, 22); this.mnuFullscreen.Text = "Fullscreen"; - this.mnuFullscreen.Click += new System.EventHandler(this.mnuFullscreen_Click); // // mnuVideoFilter // @@ -1095,7 +1052,7 @@ namespace Mesen.GUI.Forms this.mnuProfile}); this.mnuNetPlay.Image = global::Mesen.GUI.Properties.Resources.NetPlay; this.mnuNetPlay.Name = "mnuNetPlay"; - this.mnuNetPlay.Size = new System.Drawing.Size(231, 22); + this.mnuNetPlay.Size = new System.Drawing.Size(182, 22); this.mnuNetPlay.Text = "Net Play"; // // mnuStartServer @@ -1193,7 +1150,7 @@ namespace Mesen.GUI.Forms this.mnuStopMovie}); this.mnuMovies.Image = global::Mesen.GUI.Properties.Resources.Movie; this.mnuMovies.Name = "mnuMovies"; - this.mnuMovies.Size = new System.Drawing.Size(231, 22); + this.mnuMovies.Size = new System.Drawing.Size(182, 22); this.mnuMovies.Text = "Movies"; // // mnuPlayMovie @@ -1240,14 +1197,14 @@ namespace Mesen.GUI.Forms // this.mnuCheats.Image = global::Mesen.GUI.Properties.Resources.CheatCode; this.mnuCheats.Name = "mnuCheats"; - this.mnuCheats.Size = new System.Drawing.Size(231, 22); + this.mnuCheats.Size = new System.Drawing.Size(182, 22); this.mnuCheats.Text = "Cheats"; this.mnuCheats.Click += new System.EventHandler(this.mnuCheats_Click); // // toolStripMenuItem22 // this.toolStripMenuItem22.Name = "toolStripMenuItem22"; - this.toolStripMenuItem22.Size = new System.Drawing.Size(228, 6); + this.toolStripMenuItem22.Size = new System.Drawing.Size(179, 6); // // mnuSoundRecorder // @@ -1256,7 +1213,7 @@ namespace Mesen.GUI.Forms this.mnuWaveStop}); this.mnuSoundRecorder.Image = global::Mesen.GUI.Properties.Resources.Microphone; this.mnuSoundRecorder.Name = "mnuSoundRecorder"; - this.mnuSoundRecorder.Size = new System.Drawing.Size(231, 22); + this.mnuSoundRecorder.Size = new System.Drawing.Size(182, 22); this.mnuSoundRecorder.Text = "Sound Recorder"; // // mnuWaveRecord @@ -1282,7 +1239,7 @@ namespace Mesen.GUI.Forms this.mnuAviStop}); this.mnuVideoRecorder.Image = global::Mesen.GUI.Properties.Resources.VideoRecorder; this.mnuVideoRecorder.Name = "mnuVideoRecorder"; - this.mnuVideoRecorder.Size = new System.Drawing.Size(231, 22); + this.mnuVideoRecorder.Size = new System.Drawing.Size(182, 22); this.mnuVideoRecorder.Text = "Video Recorder"; // // mnuAviRecord @@ -1304,7 +1261,7 @@ namespace Mesen.GUI.Forms // toolStripMenuItem12 // this.toolStripMenuItem12.Name = "toolStripMenuItem12"; - this.toolStripMenuItem12.Size = new System.Drawing.Size(228, 6); + this.toolStripMenuItem12.Size = new System.Drawing.Size(179, 6); // // mnuTests // @@ -1316,13 +1273,13 @@ namespace Mesen.GUI.Forms this.mnuRunAllGameTests, this.mnuRunAutomaticTest}); this.mnuTests.Name = "mnuTests"; - this.mnuTests.Size = new System.Drawing.Size(231, 22); + this.mnuTests.Size = new System.Drawing.Size(182, 22); this.mnuTests.Text = "Tests"; // // mnuTestRun // this.mnuTestRun.Name = "mnuTestRun"; - this.mnuTestRun.Size = new System.Drawing.Size(192, 22); + this.mnuTestRun.Size = new System.Drawing.Size(174, 22); this.mnuTestRun.Text = "Run..."; this.mnuTestRun.Click += new System.EventHandler(this.mnuTestRun_Click); // @@ -1334,64 +1291,62 @@ namespace Mesen.GUI.Forms this.mnuTestRecordMovie, this.mnuTestRecordTest}); this.mnuTestRecordFrom.Name = "mnuTestRecordFrom"; - this.mnuTestRecordFrom.Size = new System.Drawing.Size(192, 22); + this.mnuTestRecordFrom.Size = new System.Drawing.Size(174, 22); this.mnuTestRecordFrom.Text = "Record from..."; // // mnuTestRecordStart // this.mnuTestRecordStart.Name = "mnuTestRecordStart"; - this.mnuTestRecordStart.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.W))); - this.mnuTestRecordStart.Size = new System.Drawing.Size(143, 22); + this.mnuTestRecordStart.Size = new System.Drawing.Size(152, 22); this.mnuTestRecordStart.Text = "Start"; this.mnuTestRecordStart.Click += new System.EventHandler(this.mnuTestRecordStart_Click); // // mnuTestRecordNow // this.mnuTestRecordNow.Name = "mnuTestRecordNow"; - this.mnuTestRecordNow.Size = new System.Drawing.Size(143, 22); + this.mnuTestRecordNow.Size = new System.Drawing.Size(152, 22); this.mnuTestRecordNow.Text = "Now"; this.mnuTestRecordNow.Click += new System.EventHandler(this.mnuTestRecordNow_Click); // // mnuTestRecordMovie // this.mnuTestRecordMovie.Name = "mnuTestRecordMovie"; - this.mnuTestRecordMovie.Size = new System.Drawing.Size(143, 22); + this.mnuTestRecordMovie.Size = new System.Drawing.Size(152, 22); this.mnuTestRecordMovie.Text = "Movie"; this.mnuTestRecordMovie.Click += new System.EventHandler(this.mnuTestRecordMovie_Click); // // mnuTestRecordTest // this.mnuTestRecordTest.Name = "mnuTestRecordTest"; - this.mnuTestRecordTest.Size = new System.Drawing.Size(143, 22); + this.mnuTestRecordTest.Size = new System.Drawing.Size(152, 22); this.mnuTestRecordTest.Text = "Test"; this.mnuTestRecordTest.Click += new System.EventHandler(this.mnuTestRecordTest_Click); // // mnuTestStopRecording // this.mnuTestStopRecording.Name = "mnuTestStopRecording"; - this.mnuTestStopRecording.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E))); - this.mnuTestStopRecording.Size = new System.Drawing.Size(192, 22); + this.mnuTestStopRecording.Size = new System.Drawing.Size(174, 22); this.mnuTestStopRecording.Text = "Stop recording"; this.mnuTestStopRecording.Click += new System.EventHandler(this.mnuTestStopRecording_Click); // // mnuRunAllTests // this.mnuRunAllTests.Name = "mnuRunAllTests"; - this.mnuRunAllTests.Size = new System.Drawing.Size(192, 22); + this.mnuRunAllTests.Size = new System.Drawing.Size(174, 22); this.mnuRunAllTests.Text = "Run all tests"; this.mnuRunAllTests.Click += new System.EventHandler(this.mnuRunAllTests_Click); // // mnuRunAllGameTests // this.mnuRunAllGameTests.Name = "mnuRunAllGameTests"; - this.mnuRunAllGameTests.Size = new System.Drawing.Size(192, 22); + this.mnuRunAllGameTests.Size = new System.Drawing.Size(174, 22); this.mnuRunAllGameTests.Text = "Run all game tests"; this.mnuRunAllGameTests.Click += new System.EventHandler(this.mnuRunAllGameTests_Click); // // mnuRunAutomaticTest // this.mnuRunAutomaticTest.Name = "mnuRunAutomaticTest"; - this.mnuRunAutomaticTest.Size = new System.Drawing.Size(192, 22); + this.mnuRunAutomaticTest.Size = new System.Drawing.Size(174, 22); this.mnuRunAutomaticTest.Text = "Run automatic test"; this.mnuRunAutomaticTest.Click += new System.EventHandler(this.mnuRunAutomaticTest_Click); // @@ -1399,16 +1354,14 @@ namespace Mesen.GUI.Forms // this.mnuDebugger.Image = global::Mesen.GUI.Properties.Resources.Bug; this.mnuDebugger.Name = "mnuDebugger"; - this.mnuDebugger.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); - this.mnuDebugger.Size = new System.Drawing.Size(231, 22); + this.mnuDebugger.Size = new System.Drawing.Size(182, 22); this.mnuDebugger.Text = "Debugger"; - this.mnuDebugger.Click += new System.EventHandler(this.mnuDebugger_Click); // // mnuLogWindow // this.mnuLogWindow.Image = global::Mesen.GUI.Properties.Resources.LogWindow; this.mnuLogWindow.Name = "mnuLogWindow"; - this.mnuLogWindow.Size = new System.Drawing.Size(231, 22); + this.mnuLogWindow.Size = new System.Drawing.Size(182, 22); this.mnuLogWindow.Text = "Log Window"; this.mnuLogWindow.Click += new System.EventHandler(this.mnuLogWindow_Click); // @@ -1416,32 +1369,28 @@ namespace Mesen.GUI.Forms // this.mnuHdPackEditor.Image = global::Mesen.GUI.Properties.Resources.HdPack; this.mnuHdPackEditor.Name = "mnuHdPackEditor"; - this.mnuHdPackEditor.Size = new System.Drawing.Size(231, 22); + this.mnuHdPackEditor.Size = new System.Drawing.Size(182, 22); this.mnuHdPackEditor.Text = "HD Pack Builder"; this.mnuHdPackEditor.Click += new System.EventHandler(this.mnuHdPackEditor_Click); // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(228, 6); + this.toolStripMenuItem1.Size = new System.Drawing.Size(179, 6); // // mnuRandomGame // this.mnuRandomGame.Image = global::Mesen.GUI.Properties.Resources.Dice; this.mnuRandomGame.Name = "mnuRandomGame"; - this.mnuRandomGame.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Insert))); - this.mnuRandomGame.Size = new System.Drawing.Size(231, 22); + this.mnuRandomGame.Size = new System.Drawing.Size(182, 22); this.mnuRandomGame.Text = "Load Random Game"; - this.mnuRandomGame.Click += new System.EventHandler(this.mnuRandomGame_Click); // // mnuTakeScreenshot // this.mnuTakeScreenshot.Image = global::Mesen.GUI.Properties.Resources.Camera; this.mnuTakeScreenshot.Name = "mnuTakeScreenshot"; - this.mnuTakeScreenshot.ShortcutKeys = System.Windows.Forms.Keys.F12; - this.mnuTakeScreenshot.Size = new System.Drawing.Size(231, 22); + this.mnuTakeScreenshot.Size = new System.Drawing.Size(182, 22); this.mnuTakeScreenshot.Text = "Take Screenshot"; - this.mnuTakeScreenshot.Click += new System.EventHandler(this.mnuTakeScreenshot_Click); // // mnuDebug // @@ -1463,66 +1412,54 @@ namespace Mesen.GUI.Forms // this.mnuAssembler.Image = global::Mesen.GUI.Properties.Resources.Chip; this.mnuAssembler.Name = "mnuAssembler"; - this.mnuAssembler.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.K))); - this.mnuAssembler.Size = new System.Drawing.Size(196, 22); + this.mnuAssembler.Size = new System.Drawing.Size(162, 22); this.mnuAssembler.Text = "Assembler"; - this.mnuAssembler.Click += new System.EventHandler(this.mnuAssembler_Click); // // mnuDebugDebugger // this.mnuDebugDebugger.Image = global::Mesen.GUI.Properties.Resources.Bug; this.mnuDebugDebugger.Name = "mnuDebugDebugger"; - this.mnuDebugDebugger.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); - this.mnuDebugDebugger.Size = new System.Drawing.Size(196, 22); + this.mnuDebugDebugger.Size = new System.Drawing.Size(162, 22); this.mnuDebugDebugger.Text = "Debugger"; - this.mnuDebugDebugger.Click += new System.EventHandler(this.mnuDebugDebugger_Click); // // mnuMemoryViewer // this.mnuMemoryViewer.Image = global::Mesen.GUI.Properties.Resources.CheatCode; this.mnuMemoryViewer.Name = "mnuMemoryViewer"; - this.mnuMemoryViewer.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.M))); - this.mnuMemoryViewer.Size = new System.Drawing.Size(196, 22); + this.mnuMemoryViewer.Size = new System.Drawing.Size(162, 22); this.mnuMemoryViewer.Text = "Memory Tools"; - this.mnuMemoryViewer.Click += new System.EventHandler(this.mnuMemoryViewer_Click); // // mnuPpuViewer // this.mnuPpuViewer.Image = global::Mesen.GUI.Properties.Resources.Video; this.mnuPpuViewer.Name = "mnuPpuViewer"; - this.mnuPpuViewer.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P))); - this.mnuPpuViewer.Size = new System.Drawing.Size(196, 22); + this.mnuPpuViewer.Size = new System.Drawing.Size(162, 22); this.mnuPpuViewer.Text = "PPU Viewer"; - this.mnuPpuViewer.Click += new System.EventHandler(this.mnuPpuViewer_Click); // // mnuScriptWindow // this.mnuScriptWindow.Image = global::Mesen.GUI.Properties.Resources.Script; this.mnuScriptWindow.Name = "mnuScriptWindow"; - this.mnuScriptWindow.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.J))); - this.mnuScriptWindow.Size = new System.Drawing.Size(196, 22); + this.mnuScriptWindow.Size = new System.Drawing.Size(162, 22); this.mnuScriptWindow.Text = "Script Window"; - this.mnuScriptWindow.Click += new System.EventHandler(this.mnuScriptWindow_Click); // // mnuTraceLogger // this.mnuTraceLogger.Image = global::Mesen.GUI.Properties.Resources.LogWindow; this.mnuTraceLogger.Name = "mnuTraceLogger"; - this.mnuTraceLogger.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); - this.mnuTraceLogger.Size = new System.Drawing.Size(196, 22); + this.mnuTraceLogger.Size = new System.Drawing.Size(162, 22); this.mnuTraceLogger.Text = "Trace Logger"; - this.mnuTraceLogger.Click += new System.EventHandler(this.mnuTraceLogger_Click); // // toolStripMenuItem25 // this.toolStripMenuItem25.Name = "toolStripMenuItem25"; - this.toolStripMenuItem25.Size = new System.Drawing.Size(193, 6); + this.toolStripMenuItem25.Size = new System.Drawing.Size(159, 6); // // mnuEditHeader // this.mnuEditHeader.Image = global::Mesen.GUI.Properties.Resources.Edit; this.mnuEditHeader.Name = "mnuEditHeader"; - this.mnuEditHeader.Size = new System.Drawing.Size(196, 22); + this.mnuEditHeader.Size = new System.Drawing.Size(162, 22); this.mnuEditHeader.Text = "Edit iNES Header"; this.mnuEditHeader.Click += new System.EventHandler(this.mnuEditHeader_Click); // diff --git a/GUI.NET/Forms/frmMain.File.cs b/GUI.NET/Forms/frmMain.File.cs index 55526ac6..3e1e9c31 100644 --- a/GUI.NET/Forms/frmMain.File.cs +++ b/GUI.NET/Forms/frmMain.File.cs @@ -14,14 +14,12 @@ namespace Mesen.GUI.Forms partial class frmMain { const int NumberOfSaveSlots = 7; - private void InitializeStateMenu(ToolStripMenuItem menu, bool forSave) + private void UpdateStateMenu(ToolStripMenuItem menu, bool forSave) { if(this.InvokeRequired) { - this.BeginInvoke((MethodInvoker)(() => this.InitializeStateMenu(menu, forSave))); + this.BeginInvoke((MethodInvoker)(() => this.UpdateStateMenu(menu, forSave))); } else { - menu.DropDownItems.Clear(); - - Action addSaveStateInfo = (i) => { + for(uint i = 1; i <= frmMain.NumberOfSaveSlots + (forSave ? 0 : 1); i++) { Int64 fileTime = InteropEmu.GetStateInfo(i); string label; if(fileTime == 0) { @@ -31,50 +29,67 @@ namespace Mesen.GUI.Forms label = i.ToString() + ". " + dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(); } - ToolStripMenuItem item = new ToolStripMenuItem(label); - uint stateIndex = i; - item.Click += (object sender, EventArgs e) => { - if(_emuThread != null && !InteropEmu.IsNsf()) { - if(forSave) { - InteropEmu.SaveState(stateIndex); - } else { - if(!InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording()) { - InteropEmu.LoadState(stateIndex); - } - } - } - }; - - item.ShortcutKeys = (Keys)((int)Keys.F1 + i - 1); - if(forSave) { - item.ShortcutKeys |= Keys.Shift; + if(i == NumberOfSaveSlots + 1) { + //Autosave slot (load only) + menu.DropDownItems[NumberOfSaveSlots + 1].Text = label; + } else { + menu.DropDownItems[(int)i - 1].Text = label; } - menu.DropDownItems.Add(item); - }; - - for(uint i = 1; i <= frmMain.NumberOfSaveSlots; i++) { - addSaveStateInfo(i); - } - - if(!forSave) { - menu.DropDownItems.Add("-"); - addSaveStateInfo(NumberOfSaveSlots+1); - menu.DropDownItems.Add("-"); - ToolStripMenuItem loadFromFile = new ToolStripMenuItem(ResourceHelper.GetMessage("LoadFromFile"), Resources.FolderOpen); - loadFromFile.ShortcutKeys = Keys.Control | Keys.L; - loadFromFile.Click += LoadFromFile_Click; - menu.DropDownItems.Add(loadFromFile); - } else { - menu.DropDownItems.Add("-"); - ToolStripMenuItem saveToFile = new ToolStripMenuItem(ResourceHelper.GetMessage("SaveToFile"), Resources.Floppy); - saveToFile.ShortcutKeys = Keys.Control | Keys.S; - saveToFile.Click += SaveToFile_Click; - menu.DropDownItems.Add(saveToFile); } } } - private void LoadFromFile_Click(object sender, EventArgs e) + private void InitializeStateMenu(ToolStripMenuItem menu, bool forSave) + { + Action addSaveStateInfo = (i) => { + string label = i.ToString() + ". " + ResourceHelper.GetMessage("EmptyState"); + + ToolStripMenuItem item = new ToolStripMenuItem(label); + menu.DropDownItems.Add(item); + + if(forSave) { + BindShortcut(item, (EmulatorShortcut)((int)EmulatorShortcut.SaveStateSlot1 + i - 1)); + } else { + BindShortcut(item, (EmulatorShortcut)((int)EmulatorShortcut.LoadStateSlot1 + i - 1)); + } + }; + + for(uint i = 1; i <= frmMain.NumberOfSaveSlots; i++) { + addSaveStateInfo(i); + } + + if(!forSave) { + menu.DropDownItems.Add("-"); + addSaveStateInfo(NumberOfSaveSlots+1); + menu.DropDownItems.Add("-"); + ToolStripMenuItem loadFromFile = new ToolStripMenuItem(ResourceHelper.GetMessage("LoadFromFile"), Resources.FolderOpen); + menu.DropDownItems.Add(loadFromFile); + BindShortcut(loadFromFile, EmulatorShortcut.LoadStateFromFile); + } else { + menu.DropDownItems.Add("-"); + ToolStripMenuItem saveToFile = new ToolStripMenuItem(ResourceHelper.GetMessage("SaveToFile"), Resources.Floppy); + menu.DropDownItems.Add(saveToFile); + BindShortcut(saveToFile, EmulatorShortcut.SaveStateToFile); + } + } + + private void SaveState(uint slot) + { + if(_emuThread != null && !InteropEmu.IsNsf()) { + InteropEmu.SaveState(slot); + } + } + + private void LoadState(uint slot) + { + if(_emuThread != null && !InteropEmu.IsNsf()) { + if(!InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording()) { + InteropEmu.LoadState(slot); + } + } + } + + private void LoadStateFromFile() { if(_emuThread != null) { using(OpenFileDialog ofd = new OpenFileDialog()) { @@ -87,7 +102,7 @@ namespace Mesen.GUI.Forms } } - private void SaveToFile_Click(object sender, EventArgs e) + private void SaveStateToFile() { if(_emuThread != null) { using(SaveFileDialog sfd = new SaveFileDialog()) { @@ -101,22 +116,17 @@ namespace Mesen.GUI.Forms } } - private void mnuExit_Click(object sender, EventArgs e) - { - this.Close(); - } - private void mnuSaveState_DropDownOpening(object sender, EventArgs e) { - InitializeStateMenu(mnuSaveState, true); + UpdateStateMenu(mnuSaveState, true); } private void mnuLoadState_DropDownOpening(object sender, EventArgs e) { - InitializeStateMenu(mnuLoadState, false); + UpdateStateMenu(mnuLoadState, false); } - - private void mnuOpen_Click(object sender, EventArgs e) + + private void OpenFile() { using(OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterRomIps")); diff --git a/GUI.NET/Forms/frmMain.Game.cs b/GUI.NET/Forms/frmMain.Game.cs index ff9d32fd..fc1a8c67 100644 --- a/GUI.NET/Forms/frmMain.Game.cs +++ b/GUI.NET/Forms/frmMain.Game.cs @@ -11,26 +11,6 @@ namespace Mesen.GUI.Forms { public partial class frmMain { - private void mnuPause_Click(object sender, EventArgs e) - { - PauseEmu(); - } - - private void mnuReset_Click(object sender, EventArgs e) - { - ResetEmu(); - } - - private void mnuPowerCycle_Click(object sender, EventArgs e) - { - PowerCycleEmu(); - } - - private void mnuPowerOff_Click(object sender, EventArgs e) - { - InteropEmu.Stop(); - } - private void InitializeFdsDiskMenu() { if(this.InvokeRequired) { @@ -61,16 +41,6 @@ namespace Mesen.GUI.Forms } } - private void mnuEjectDisk_Click(object sender, EventArgs e) - { - InteropEmu.FdsEjectDisk(); - } - - private void mnuSwitchDiskSide_Click(object sender, EventArgs e) - { - InteropEmu.FdsSwitchDiskSide(); - } - private void InitializeVsSystemMenu() { if(this.InvokeRequired) { @@ -83,16 +53,6 @@ namespace Mesen.GUI.Forms } } - private void mnuInsertCoin1_Click(object sender, EventArgs e) - { - InteropEmu.VsInsertCoin(0); - } - - private void mnuInsertCoin2_Click(object sender, EventArgs e) - { - InteropEmu.VsInsertCoin(1); - } - private void ShowVsGameConfig() { VsConfigInfo configInfo = VsConfigInfo.GetCurrentGameConfig(true); diff --git a/GUI.NET/Forms/frmMain.Options.cs b/GUI.NET/Forms/frmMain.Options.cs index e11d741f..c0bf51f4 100644 --- a/GUI.NET/Forms/frmMain.Options.cs +++ b/GUI.NET/Forms/frmMain.Options.cs @@ -205,25 +205,6 @@ namespace Mesen.GUI.Forms UpdateEmulationSpeedMenu(); } - private void mnuIncreaseSpeed_Click(object sender, EventArgs e) - { - InteropEmu.IncreaseEmulationSpeed(); - } - - private void mnuDecreaseSpeed_Click(object sender, EventArgs e) - { - InteropEmu.DecreaseEmulationSpeed(); - } - - private void mnuEmuSpeedMaximumSpeed_Click(object sender, EventArgs e) - { - if(ConfigManager.Config.EmulationInfo.EmulationSpeed == 0) { - SetEmulationSpeed(100); - } else { - SetEmulationSpeed(0); - } - } - private void mnuEmulationSpeedOption_Click(object sender, EventArgs e) { SetEmulationSpeed((uint)(int)((ToolStripItem)sender).Tag); @@ -236,22 +217,6 @@ namespace Mesen.GUI.Forms VideoInfo.ApplyConfig(); } - private void mnuShowFPS_Click(object sender, EventArgs e) - { - UpdateEmulationFlags(); - } - - private void mnuScale_Click(object sender, EventArgs e) - { - UInt32 scale = UInt32.Parse((string)((ToolStripMenuItem)sender).Tag); - SetScale(scale); - } - - private void mnuFullscreen_Click(object sender, EventArgs e) - { - SetFullscreenState(!_fullscreenMode); - } - private void mnuNoneFilter_Click(object sender, EventArgs e) { SetVideoFilter(VideoFilterType.None); diff --git a/GUI.NET/Forms/frmMain.Tools.cs b/GUI.NET/Forms/frmMain.Tools.cs index 82a587e9..10f640fe 100644 --- a/GUI.NET/Forms/frmMain.Tools.cs +++ b/GUI.NET/Forms/frmMain.Tools.cs @@ -20,41 +20,6 @@ namespace Mesen.GUI.Forms mnuEditHeader.Enabled = _emuThread != null && InteropEmu.GetRomInfo().Format == RomFormat.iNes; } - private void mnuDebugger_Click(object sender, EventArgs e) - { - DebugWindowManager.OpenDebugWindow(DebugWindow.Debugger); - } - - private void mnuDebugDebugger_Click(object sender, EventArgs e) - { - DebugWindowManager.OpenDebugWindow(DebugWindow.Debugger); - } - - private void mnuTraceLogger_Click(object sender, EventArgs e) - { - DebugWindowManager.OpenDebugWindow(DebugWindow.TraceLogger); - } - - private void mnuPpuViewer_Click(object sender, EventArgs e) - { - DebugWindowManager.OpenDebugWindow(DebugWindow.PpuViewer); - } - - private void mnuMemoryViewer_Click(object sender, EventArgs e) - { - DebugWindowManager.OpenDebugWindow(DebugWindow.MemoryViewer); - } - - private void mnuAssembler_Click(object sender, EventArgs e) - { - DebugWindowManager.OpenDebugWindow(DebugWindow.Assembler); - } - - private void mnuScriptWindow_Click(object sender, EventArgs e) - { - DebugWindowManager.OpenDebugWindow(DebugWindow.ScriptWindow); - } - private void mnuEditHeader_Click(object sender, EventArgs e) { using(frmEditHeader frm = new frmEditHeader()) { @@ -146,8 +111,8 @@ namespace Mesen.GUI.Forms _cheatListWindow.Focus(); } } - - private void mnuRandomGame_Click(object sender, EventArgs e) + + private void LoadRandomGame() { IEnumerable gameFolders = ConfigManager.Config.RecentFiles.Select(recentFile => recentFile.RomFile.Folder.ToLowerInvariant()).Distinct(); List gameRoms = new List(); @@ -194,11 +159,6 @@ namespace Mesen.GUI.Forms _hdPackEditorWindow.Focus(); } } - - private void mnuTakeScreenshot_Click(object sender, EventArgs e) - { - InteropEmu.TakeScreenshot(); - } private void mnuStartServer_Click(object sender, EventArgs e) { diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 3456ba4b..bf3e77ca 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -26,6 +26,8 @@ namespace Mesen.GUI.Forms { private const int WM_KEYDOWN = 0x100; private const int WM_KEYUP = 0x101; + const int WM_SYSKEYDOWN = 0x104; + const int WM_SYSKEYUP = 0x105; private InteropEmu.NotificationListener _notifListener; private Thread _emuThread; @@ -46,6 +48,8 @@ namespace Mesen.GUI.Forms private bool _removeFocus = false; private bool _showUpgradeMessage = false; + private Dictionary> _actionEnabledFuncs = new Dictionary>(); + private string[] _commandLineArgs; private bool _noAudio = false; private bool _noVideo = false; @@ -153,7 +157,10 @@ namespace Mesen.GUI.Forms UpdateRecentFiles(); UpdateViewerSize(); - + + InitializeStateMenu(mnuSaveState, true); + InitializeStateMenu(mnuLoadState, false); + if(ConfigManager.Config.WindowLocation.HasValue) { this.StartPosition = FormStartPosition.Manual; this.Location = ConfigManager.Config.WindowLocation.Value; @@ -190,6 +197,8 @@ namespace Mesen.GUI.Forms { base.OnShown(e); + this.BindShortcuts(); + if(ConfigManager.Config.WindowSize.HasValue) { this.Size = ConfigManager.Config.WindowSize.Value; } @@ -384,8 +393,8 @@ namespace Mesen.GUI.Forms InitializeVsSystemMenu(); CheatInfo.ApplyCheats(); VsConfigInfo.ApplyConfig(); - InitializeStateMenu(mnuSaveState, true); - InitializeStateMenu(mnuLoadState, false); + UpdateStateMenu(mnuSaveState, true); + UpdateStateMenu(mnuLoadState, false); if(ConfigManager.Config.PreferenceInfo.ShowVsConfigOnLoad && InteropEmu.IsVsSystem()) { this.Invoke((MethodInvoker)(() => { this.ShowVsGameConfig(); @@ -441,34 +450,9 @@ namespace Mesen.GUI.Forms })); break; - case InteropEmu.ConsoleNotificationType.RequestReset: - this.BeginInvoke((MethodInvoker)(() => this.ResetEmu())); - break; - - case InteropEmu.ConsoleNotificationType.RequestPowerCycle: - this.BeginInvoke((MethodInvoker)(() => this.PowerCycleEmu())); - break; - - case InteropEmu.ConsoleNotificationType.RequestExit: - this.BeginInvoke((MethodInvoker)(() => this.Close())); - break; - - case InteropEmu.ConsoleNotificationType.ToggleCheats: + case InteropEmu.ConsoleNotificationType.ExecuteShortcut: this.BeginInvoke((MethodInvoker)(() => { - ConfigManager.Config.DisableAllCheats = !ConfigManager.Config.DisableAllCheats; - if(ConfigManager.Config.DisableAllCheats) { - InteropEmu.DisplayMessage("Cheats", "CheatsDisabled"); - } - CheatInfo.ApplyCheats(); - ConfigManager.ApplyChanges(); - })); - break; - - case InteropEmu.ConsoleNotificationType.ToggleAudio: - this.BeginInvoke((MethodInvoker)(() => { - ConfigManager.Config.AudioInfo.EnableAudio = !ConfigManager.Config.AudioInfo.EnableAudio; - AudioInfo.ApplyConfig(); - ConfigManager.ApplyChanges(); + ExecuteShortcut((EmulatorShortcut)e.Parameter); })); break; @@ -485,7 +469,198 @@ namespace Mesen.GUI.Forms UpdateMenus(); } } + + private void BindShortcuts() + { + Func runningNotClient = () => { return _emuThread != null && !InteropEmu.IsConnected(); }; + Func runningNotClientNotMovie = () => { return _emuThread != null && !InteropEmu.IsConnected() && !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording(); }; + + Func runningNotNsf = () => { return _emuThread != null && !InteropEmu.IsNsf(); }; + Func runningFdsNoAutoInsert = () => { return _emuThread != null && InteropEmu.FdsGetSideCount() > 0 && !InteropEmu.FdsIsAutoInsertDiskEnabled() && !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording(); }; + Func runningVsSystem = () => { return _emuThread != null && InteropEmu.IsVsSystem() && !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording(); }; + + BindShortcut(mnuOpen, EmulatorShortcut.OpenFile); + BindShortcut(mnuExit, EmulatorShortcut.Exit); + BindShortcut(mnuIncreaseSpeed, EmulatorShortcut.IncreaseSpeed, runningNotClient); + BindShortcut(mnuDecreaseSpeed, EmulatorShortcut.DecreaseSpeed, runningNotClient); + BindShortcut(mnuEmuSpeedMaximumSpeed, EmulatorShortcut.MaxSpeed, runningNotClient); + + BindShortcut(mnuPause, EmulatorShortcut.Pause, runningNotClient); + BindShortcut(mnuReset, EmulatorShortcut.Reset, runningNotClientNotMovie); + BindShortcut(mnuPowerCycle, EmulatorShortcut.PowerCycle, runningNotClientNotMovie); + BindShortcut(mnuPowerOff, EmulatorShortcut.PowerOff, runningNotClient); + + BindShortcut(mnuSwitchDiskSide, EmulatorShortcut.SwitchDiskSide, runningFdsNoAutoInsert); + BindShortcut(mnuEjectDisk, EmulatorShortcut.EjectDisk, runningFdsNoAutoInsert); + + BindShortcut(mnuInsertCoin1, EmulatorShortcut.InsertCoin1, runningVsSystem); + BindShortcut(mnuInsertCoin2, EmulatorShortcut.InsertCoin2, runningVsSystem); + + BindShortcut(mnuShowFPS, EmulatorShortcut.ToggleFps); + + BindShortcut(mnuScale1x, EmulatorShortcut.SetScale1x); + BindShortcut(mnuScale2x, EmulatorShortcut.SetScale2x); + BindShortcut(mnuScale3x, EmulatorShortcut.SetScale3x); + BindShortcut(mnuScale4x, EmulatorShortcut.SetScale4x); + BindShortcut(mnuScale5x, EmulatorShortcut.SetScale5x); + BindShortcut(mnuScale6x, EmulatorShortcut.SetScale6x); + + BindShortcut(mnuFullscreen, EmulatorShortcut.ToggleFullscreen); + + BindShortcut(mnuTakeScreenshot, EmulatorShortcut.TakeScreenshot, runningNotNsf); + BindShortcut(mnuRandomGame, EmulatorShortcut.LoadRandomGame); + + BindShortcut(mnuDebugDebugger, EmulatorShortcut.OpenDebugger, runningNotClient); + BindShortcut(mnuDebugger, EmulatorShortcut.OpenDebugger, runningNotClient); + BindShortcut(mnuAssembler, EmulatorShortcut.OpenAssembler, runningNotClient); + BindShortcut(mnuMemoryViewer, EmulatorShortcut.OpenMemoryTools, runningNotClient); + BindShortcut(mnuPpuViewer, EmulatorShortcut.OpenPpuViewer, runningNotClient); + BindShortcut(mnuScriptWindow, EmulatorShortcut.OpenScriptWindow, runningNotClient); + BindShortcut(mnuTraceLogger, EmulatorShortcut.OpenTraceLogger, runningNotClient); + } + private void BindShortcut(ToolStripMenuItem item, EmulatorShortcut shortcut, Func isActionEnabled = null) + { + item.Click += (object sender, EventArgs e) => { + if(isActionEnabled == null || isActionEnabled()) { + ExecuteShortcut(shortcut); + } + }; + + _actionEnabledFuncs[shortcut] = isActionEnabled; + + if(item.OwnerItem is ToolStripMenuItem) { + Action updateShortcut = () => { + int keyIndex = ConfigManager.Config.PreferenceInfo.ShortcutKeys1.FindIndex((ShortcutKeyInfo shortcutInfo) => shortcutInfo.Shortcut == shortcut); + if(keyIndex >= 0) { + item.ShortcutKeyDisplayString = ConfigManager.Config.PreferenceInfo.ShortcutKeys1[keyIndex].KeyCombination.ToString(); + } else { + keyIndex = ConfigManager.Config.PreferenceInfo.ShortcutKeys2.FindIndex((ShortcutKeyInfo shortcutInfo) => shortcutInfo.Shortcut == shortcut); + if(keyIndex >= 0) { + item.ShortcutKeyDisplayString = ConfigManager.Config.PreferenceInfo.ShortcutKeys2[keyIndex].KeyCombination.ToString(); + } else { + item.ShortcutKeyDisplayString = ""; + } + } + item.Enabled = isActionEnabled == null || isActionEnabled(); + }; + + updateShortcut(); + + //Update item shortcut text when its parent opens + ((ToolStripMenuItem)item.OwnerItem).DropDownOpening += (object sender, EventArgs e) => { updateShortcut(); }; + } + } + + private void ExecuteShortcut(EmulatorShortcut shortcut) + { + Func isActionEnabled; + if(_actionEnabledFuncs.TryGetValue(shortcut, out isActionEnabled)) { + isActionEnabled = _actionEnabledFuncs[shortcut]; + if(isActionEnabled != null && !isActionEnabled()) { + //Action disabled + return; + } + } + + switch(shortcut) { + case EmulatorShortcut.Pause: PauseEmu(); break; + case EmulatorShortcut.Reset: this.ResetEmu(); break; + case EmulatorShortcut.PowerCycle: this.PowerCycleEmu(); break; + case EmulatorShortcut.PowerOff: InteropEmu.Stop(); break; + case EmulatorShortcut.Exit: this.Close(); break; + + case EmulatorShortcut.ToggleCheats: ToggleCheats(); break; + case EmulatorShortcut.ToggleAudio: ToggleAudio(); break; + case EmulatorShortcut.ToggleFps: ToggleFps(); break; + case EmulatorShortcut.MaxSpeed: ToggleMaxSpeed(); break; + case EmulatorShortcut.ToggleFullscreen: ToggleFullscreen(); break; + + case EmulatorShortcut.OpenFile: OpenFile(); break; + case EmulatorShortcut.IncreaseSpeed: InteropEmu.IncreaseEmulationSpeed(); break; + case EmulatorShortcut.DecreaseSpeed: InteropEmu.DecreaseEmulationSpeed(); break; + case EmulatorShortcut.SwitchDiskSide: InteropEmu.FdsSwitchDiskSide(); break; + case EmulatorShortcut.EjectDisk: InteropEmu.FdsEjectDisk(); break; + + case EmulatorShortcut.SetScale1x: SetScale(1); break; + case EmulatorShortcut.SetScale2x: SetScale(2); break; + case EmulatorShortcut.SetScale3x: SetScale(3); break; + case EmulatorShortcut.SetScale4x: SetScale(4); break; + case EmulatorShortcut.SetScale5x: SetScale(5); break; + case EmulatorShortcut.SetScale6x: SetScale(6); break; + + case EmulatorShortcut.InsertCoin1: InteropEmu.VsInsertCoin(0); break; + case EmulatorShortcut.InsertCoin2: InteropEmu.VsInsertCoin(1); break; + + case EmulatorShortcut.TakeScreenshot: InteropEmu.TakeScreenshot(); break; + case EmulatorShortcut.LoadRandomGame: LoadRandomGame(); break; + + case EmulatorShortcut.OpenAssembler: DebugWindowManager.OpenDebugWindow(DebugWindow.Assembler); break; + case EmulatorShortcut.OpenDebugger: DebugWindowManager.OpenDebugWindow(DebugWindow.Debugger); break; + case EmulatorShortcut.OpenTraceLogger: DebugWindowManager.OpenDebugWindow(DebugWindow.TraceLogger); break; + case EmulatorShortcut.OpenPpuViewer: DebugWindowManager.OpenDebugWindow(DebugWindow.PpuViewer); break; + case EmulatorShortcut.OpenMemoryTools: DebugWindowManager.OpenDebugWindow(DebugWindow.MemoryViewer); break; + case EmulatorShortcut.OpenScriptWindow: DebugWindowManager.OpenDebugWindow(DebugWindow.ScriptWindow); break; + + case EmulatorShortcut.LoadStateFromFile: LoadStateFromFile(); break; + case EmulatorShortcut.SaveStateToFile: SaveStateToFile(); break; + + case EmulatorShortcut.SaveStateSlot1: SaveState(1); break; + case EmulatorShortcut.SaveStateSlot2: SaveState(2); break; + case EmulatorShortcut.SaveStateSlot3: SaveState(3); break; + case EmulatorShortcut.SaveStateSlot4: SaveState(4); break; + case EmulatorShortcut.SaveStateSlot5: SaveState(5); break; + case EmulatorShortcut.SaveStateSlot6: SaveState(6); break; + case EmulatorShortcut.SaveStateSlot7: SaveState(7); break; + case EmulatorShortcut.LoadStateSlot1: LoadState(1); break; + case EmulatorShortcut.LoadStateSlot2: LoadState(2); break; + case EmulatorShortcut.LoadStateSlot3: LoadState(3); break; + case EmulatorShortcut.LoadStateSlot4: LoadState(4); break; + case EmulatorShortcut.LoadStateSlot5: LoadState(5); break; + case EmulatorShortcut.LoadStateSlot6: LoadState(6); break; + case EmulatorShortcut.LoadStateSlot7: LoadState(7); break; + case EmulatorShortcut.LoadStateSlot8: LoadState(8); break; + } + } + + private void ToggleFullscreen() + { + SetFullscreenState(!_fullscreenMode); + mnuFullscreen.Checked = _fullscreenMode; + } + + private void ToggleMaxSpeed() + { + if(ConfigManager.Config.EmulationInfo.EmulationSpeed == 0) { + SetEmulationSpeed(100); + } else { + SetEmulationSpeed(0); + } + } + + private void ToggleFps() + { + mnuShowFPS.Checked = !mnuShowFPS.Checked; + UpdateEmulationFlags(); + } + + private static void ToggleAudio() + { + ConfigManager.Config.AudioInfo.EnableAudio = !ConfigManager.Config.AudioInfo.EnableAudio; + AudioInfo.ApplyConfig(); + ConfigManager.ApplyChanges(); + } + + private static void ToggleCheats() + { + ConfigManager.Config.DisableAllCheats = !ConfigManager.Config.DisableAllCheats; + if(ConfigManager.Config.DisableAllCheats) { + InteropEmu.DisplayMessage("Cheats", "CheatsDisabled"); + } + CheatInfo.ApplyCheats(); + ConfigManager.ApplyChanges(); + } + private void UpdateFocusFlag() { bool hasFocus = false; @@ -512,13 +687,6 @@ namespace Mesen.GUI.Forms bool devMode = ConfigManager.Config.PreferenceInfo.DeveloperMode; mnuDebug.Visible = devMode; - mnuAssembler.Enabled = running; - mnuMemoryViewer.Enabled = running; - mnuPpuViewer.Enabled = running; - mnuTraceLogger.Enabled = running; - mnuDebugDebugger.Enabled = running; - mnuScriptWindow.Enabled = running; - panelInfo.Visible = !running; ctrlRecentGames.Visible = !running; @@ -529,7 +697,6 @@ namespace Mesen.GUI.Forms bool isNetPlayClient = InteropEmu.IsConnected(); - mnuPause.Enabled = mnuPowerCycle.Enabled = mnuReset.Enabled = mnuPowerOff.Enabled = (running && !isNetPlayClient); mnuSaveState.Enabled = (running && !isNetPlayClient && !InteropEmu.IsNsf()); mnuLoadState.Enabled = (running && !isNetPlayClient && !InteropEmu.IsNsf() && !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording()); @@ -567,9 +734,6 @@ namespace Mesen.GUI.Forms mnuCheats.Enabled = !isNetPlayClient; mnuEmulationSpeed.Enabled = !isNetPlayClient; - mnuIncreaseSpeed.Enabled = !isNetPlayClient; - mnuDecreaseSpeed.Enabled = !isNetPlayClient; - mnuEmuSpeedMaximumSpeed.Enabled = !isNetPlayClient; mnuInput.Enabled = !isNetPlayClient; mnuRegion.Enabled = !isNetPlayClient; @@ -600,10 +764,8 @@ namespace Mesen.GUI.Forms mnuTestRecordFrom.Enabled = (mnuTestRecordStart.Enabled || mnuTestRecordNow.Enabled || mnuTestRecordMovie.Enabled || mnuTestRecordTest.Enabled); mnuDebugger.Visible = !devMode; - mnuDebugger.Enabled = !netPlay && running && !devMode; mnuHdPackEditor.Enabled = !netPlay && running; - mnuTakeScreenshot.Enabled = running && !InteropEmu.IsNsf(); mnuNetPlay.Enabled = !InteropEmu.IsNsf(); if(running && InteropEmu.IsNsf()) { mnuPowerCycle.Enabled = false; @@ -617,8 +779,6 @@ namespace Mesen.GUI.Forms bool autoInsertDisabled = !InteropEmu.FdsIsAutoInsertDiskEnabled(); mnuSelectDisk.Enabled = autoInsertDisabled; - mnuEjectDisk.Enabled = autoInsertDisabled; - mnuSwitchDiskSide.Enabled = autoInsertDisabled; bool isHdPackLoader = InteropEmu.IsHdPpu(); mnuNtscFilter.Enabled = !isHdPackLoader; @@ -695,21 +855,20 @@ namespace Mesen.GUI.Forms bool IMessageFilter.PreFilterMessage(ref Message m) { - if(m.Msg == WM_KEYUP) { - int scanCode = (Int32)(((Int64)m.LParam & 0x1FF0000) >> 16); - InteropEmu.SetKeyState(scanCode, false); + if(Application.OpenForms.Count > 0 && Application.OpenForms[0].ContainsFocus) { + if(m.Msg == WM_KEYUP || m.Msg == WM_SYSKEYUP) { + int scanCode = (Int32)(((Int64)m.LParam & 0x1FF0000) >> 16); + InteropEmu.SetKeyState(scanCode, false); + } else if(m.Msg == WM_SYSKEYDOWN || m.Msg == WM_KEYDOWN) { + int scanCode = (Int32)(((Int64)m.LParam & 0x1FF0000) >> 16); + InteropEmu.SetKeyState(scanCode, true); + } } - return false; } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { - if(msg.Msg == WM_KEYDOWN) { - int scanCode = (Int32)(((Int64)msg.LParam & 0x1FF0000) >> 16); - InteropEmu.SetKeyState(scanCode, true); - } - if(!this.menuStrip.Enabled) { //Make sure we disable all shortcut keys while the bar is disabled (i.e when running tests) return false; @@ -734,16 +893,6 @@ namespace Mesen.GUI.Forms } #endif - if(keyData == Keys.Escape && _emuThread != null && mnuPause.Enabled) { - PauseEmu(); - return true; - } else if(keyData == Keys.Oemplus) { - mnuIncreaseSpeed.PerformClick(); - return true; - } else if(keyData == Keys.OemMinus) { - mnuDecreaseSpeed.PerformClick(); - return true; - } return base.ProcessCmdKey(ref msg, keyData); } diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 75671719..e1feb6a3 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -44,18 +44,21 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void SetZapperDetectionRadius(UInt32 detectionRadius); [DllImport(DLLPath)] public static extern void SetExpansionDevice(ExpansionPortDevice device); [DllImport(DLLPath)] public static extern void SetConsoleType(ConsoleType type); - [DllImport(DLLPath)] public static extern void SetEmulatorKeys(EmulatorKeyMappingSet mappings); + [DllImport(DLLPath)] public static extern void ClearShortcutKeys(); + [DllImport(DLLPath)] public static extern void SetShortcutKey(EmulatorShortcut shortcut, KeyCombination keyCombination, int keySetIndex); [DllImport(DLLPath)] public static extern ControllerType GetControllerType(int port); [DllImport(DLLPath)] public static extern ExpansionPortDevice GetExpansionDevice(); [DllImport(DLLPath)] public static extern ConsoleType GetConsoleType(); [DllImport(DLLPath)] public static extern void UpdateInputDevices(); - [DllImport(DLLPath)] public static extern UInt32 GetPressedKey(); + + [DllImport(DLLPath, EntryPoint = "GetPressedKeys")] private static extern void GetPressedKeysWrapper(IntPtr keyBuffer); [DllImport(DLLPath)] public static extern UInt32 GetKeyCode([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string keyName); [DllImport(DLLPath, EntryPoint = "GetKeyName")] private static extern IntPtr GetKeyNameWrapper(UInt32 key); [DllImport(DLLPath)] public static extern void SetKeyState(Int32 scanCode, [MarshalAs(UnmanagedType.I1)]bool pressed); [DllImport(DLLPath)] public static extern void ResetKeyState(); + [DllImport(DLLPath)] public static extern void DisableAllKeys([MarshalAs(UnmanagedType.I1)]bool disabled); [DllImport(DLLPath)] public static extern void Run(); [DllImport(DLLPath)] public static extern void Pause(); @@ -589,6 +592,25 @@ namespace Mesen.GUI return bankList; } + public static List GetPressedKeys() + { + UInt32[] keyBuffer = new UInt32[3]; + GCHandle handle = GCHandle.Alloc(keyBuffer, GCHandleType.Pinned); + try { + InteropEmu.GetPressedKeysWrapper(handle.AddrOfPinnedObject()); + } finally { + handle.Free(); + } + + List keys = new List(); + for(int i = 0; i < 3; i++) { + if(keyBuffer[i] != 0) { + keys.Add(keyBuffer[i]); + } + } + return keys; + } + public static NsfHeader NsfGetHeader() { NsfHeader header = new NsfHeader(); @@ -702,11 +724,7 @@ namespace Mesen.GUI ConfigChanged = 14, DisconnectedFromServer = 15, PpuViewerDisplayFrame = 16, - RequestExit = 17, - ToggleCheats = 18, - ToggleAudio = 19, - RequestReset = 20, - RequestPowerCycle = 21, + ExecuteShortcut = 17, } public enum ControllerType @@ -802,11 +820,12 @@ namespace Mesen.GUI public class NotificationEventArgs { public ConsoleNotificationType NotificationType; + public IntPtr Parameter; } public class NotificationListener : IDisposable { - public delegate void NotificationCallback(int type); + public delegate void NotificationCallback(int type, IntPtr parameter); public delegate void NotificationEventHandler(NotificationEventArgs e); public event NotificationEventHandler OnNotification; @@ -816,8 +835,8 @@ namespace Mesen.GUI public NotificationListener() { - _callback = (int type) => { - this.ProcessNotification(type); + _callback = (int type, IntPtr parameter) => { + this.ProcessNotification(type, parameter); }; _notificationListener = InteropEmu.RegisterNotificationCallback(_callback); } @@ -827,10 +846,13 @@ namespace Mesen.GUI InteropEmu.UnregisterNotificationCallback(_notificationListener); } - public void ProcessNotification(int type) + public void ProcessNotification(int type, IntPtr parameter) { if(this.OnNotification != null) { - this.OnNotification(new NotificationEventArgs() { NotificationType = (ConsoleNotificationType)type }); + this.OnNotification(new NotificationEventArgs() { + NotificationType = (ConsoleNotificationType)type, + Parameter = parameter + }); } } } @@ -1288,46 +1310,141 @@ namespace Mesen.GUI } }; - public struct EmulatorKeyMappingSet + public struct KeyCombination { - public EmulatorKeyMappings KeySet1; - public EmulatorKeyMappings KeySet2; + public UInt32 Key1; + public UInt32 Key2; + public UInt32 Key3; + + public bool IsEmpty { get { return Key1 == 0 && Key2 == 0 && Key3 == 0; } } + + public override string ToString() + { + return GetKeyNames(); + } + + public KeyCombination(List scanCodes = null) + { + if(scanCodes != null) { + Key1 = scanCodes.Count > 0 ? scanCodes[0] : 0; + Key2 = scanCodes.Count > 1 ? scanCodes[1] : 0; + Key3 = scanCodes.Count > 2 ? scanCodes[2] : 0; + } else { + Key1 = 0; + Key2 = 0; + Key3 = 0; + } + } + + private string GetKeyNames() + { + List scanCodes = new List() { Key1, Key2, Key3 }; + List keyNames = scanCodes.Select((UInt32 scanCode) => InteropEmu.GetKeyName(scanCode)).Where((keyName) => !string.IsNullOrWhiteSpace(keyName)).ToList(); + keyNames.Sort((string a, string b) => { + if(a == b) { + return 0; + } + + if(a == "Ctrl") { + return -1; + } else if(b == "Ctrl") { + return 1; + } + + if(a == "Alt") { + return -1; + } else if(b == "Alt") { + return 1; + } + + if(a == "Shift") { + return -1; + } else if(b == "Shift") { + return 1; + } + + return a.CompareTo(b); + }); + + return string.Join("+", keyNames); + } } - public struct EmulatorKeyMappings + public enum EmulatorShortcut { - public UInt32 FastForward; + FastForward, + Rewind, + RewindTenSecs, + RewindOneMin, - public UInt32 Rewind; - public UInt32 RewindTenSecs; - public UInt32 RewindOneMin; + MoveToNextStateSlot, + MoveToPreviousStateSlot, + SaveState, + LoadState, - public UInt32 Pause; - public UInt32 Reset; - public UInt32 PowerCycle; - public UInt32 PowerOff; - public UInt32 Exit; + InsertNextDisk, + VsServiceButton, - public UInt32 MoveToNextStateSlot; - public UInt32 MoveToPreviousStateSlot; - public UInt32 SaveState; - public UInt32 LoadState; + ToggleCheats, + ToggleAudio, - public UInt32 SwitchDiskSide; - public UInt32 InsertNextDisk; + RunSingleFrame, - public UInt32 InsertCoin1; - public UInt32 InsertCoin2; - public UInt32 VsServiceButton; + // Everything below this is handled UI-side + SwitchDiskSide, + EjectDisk, - public UInt32 TakeScreenshot; - public UInt32 IncreaseSpeed; - public UInt32 DecreaseSpeed; + InsertCoin1, + InsertCoin2, - public UInt32 ToggleCheats; - public UInt32 ToggleAudio; + TakeScreenshot, - public UInt32 RunSingleFrame; + IncreaseSpeed, + DecreaseSpeed, + MaxSpeed, + + Pause, + Reset, + PowerCycle, + PowerOff, + Exit, + + SetScale1x, + SetScale2x, + SetScale3x, + SetScale4x, + SetScale5x, + SetScale6x, + ToggleFullscreen, + ToggleFps, + + LoadRandomGame, + SaveStateSlot1, + SaveStateSlot2, + SaveStateSlot3, + SaveStateSlot4, + SaveStateSlot5, + SaveStateSlot6, + SaveStateSlot7, + SaveStateToFile, + + LoadStateSlot1, + LoadStateSlot2, + LoadStateSlot3, + LoadStateSlot4, + LoadStateSlot5, + LoadStateSlot6, + LoadStateSlot7, + LoadStateSlot8, + LoadStateFromFile, + + OpenFile, + OpenDebugger, + OpenAssembler, + OpenPpuViewer, + OpenMemoryTools, + OpenScriptWindow, + OpenTraceLogger } public struct InteropCheatInfo diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index e1bba22e..7941353b 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -22,6 +22,7 @@ #include "../Core/MovieManager.h" #include "../Core/HdPackBuilder.h" #include "../Utilities/AviWriter.h" +#include "../Core/ShortcutKeyHandler.h" #ifdef WIN32 #include "../Windows/Renderer.h" @@ -36,13 +37,15 @@ IRenderingDevice *_renderer = nullptr; IAudioDevice *_soundManager = nullptr; IKeyManager *_keyManager = nullptr; +unique_ptr _shortcutKeyHandler; + void* _windowHandle = nullptr; void* _viewerHandle = nullptr; string _returnString; string _logString; RecordedRomTest *_recordedRomTest = nullptr; -typedef void (__stdcall *NotificationListenerCallback)(int); +typedef void (__stdcall *NotificationListenerCallback)(int, void*); namespace InteropEmu { class InteropNotificationListener : public INotificationListener @@ -56,7 +59,7 @@ namespace InteropEmu { void ProcessNotification(ConsoleNotificationType type, void* parameter) { - _callback((int)type); + _callback((int)type, parameter); } }; @@ -80,6 +83,7 @@ namespace InteropEmu { DllExport void __stdcall InitializeEmu(const char* homeFolder, void *windowHandle, void *viewerHandle, bool noAudio, bool noVideo, bool noInput) { FolderUtilities::SetHomeFolder(homeFolder); + _shortcutKeyHandler.reset(new ShortcutKeyHandler()); if(windowHandle != nullptr && viewerHandle != nullptr) { _windowHandle = windowHandle; @@ -137,7 +141,9 @@ namespace InteropEmu { DllExport void __stdcall SetZapperDetectionRadius(uint32_t detectionRadius) { EmulationSettings::SetZapperDetectionRadius(detectionRadius); } DllExport void __stdcall SetExpansionDevice(ExpansionPortDevice device) { EmulationSettings::SetExpansionDevice(device); } DllExport void __stdcall SetConsoleType(ConsoleType type) { EmulationSettings::SetConsoleType(type); } - DllExport void __stdcall SetEmulatorKeys(EmulatorKeyMappingSet mappings) { EmulationSettings::SetEmulatorKeys(mappings); } + + DllExport void __stdcall ClearShortcutKeys() { EmulationSettings::ClearShortcutKeys(); } + DllExport void __stdcall SetShortcutKey(EmulatorShortcut shortcut, KeyCombination keyCombination, int keySetIndex) { EmulationSettings::SetShortcutKey(shortcut, keyCombination, keySetIndex); } DllExport ControllerType __stdcall GetControllerType(uint32_t port) { return EmulationSettings::GetControllerType(port); } DllExport ExpansionPortDevice GetExpansionDevice() { return EmulationSettings::GetExpansionDevice(); } @@ -150,8 +156,23 @@ namespace InteropEmu { DllExport void __stdcall SetMousePosition(double x, double y) { ControlManager::SetMousePosition(x, y); } DllExport void __stdcall UpdateInputDevices() { if(_keyManager) { _keyManager->UpdateDevices(); } } - DllExport uint32_t __stdcall GetPressedKey() { return ControlManager::GetPressedKey(); } - DllExport void __stdcall SetKeyState(int32_t scanCode, bool state) { if(_keyManager) { _keyManager->SetKeyState(scanCode, state); } } + DllExport void __stdcall GetPressedKeys(uint32_t *keyBuffer) { + vector pressedKeys = ControlManager::GetPressedKeys(); + for(int i = 0; i < pressedKeys.size() && i < 3; i++) { + keyBuffer[i] = pressedKeys[i]; + } + } + DllExport void __stdcall DisableAllKeys(bool disabled) { + if(_keyManager) { + _keyManager->SetDisabled(disabled); + } + } + DllExport void __stdcall SetKeyState(int32_t scanCode, bool state) { + if(_keyManager) { + _keyManager->SetKeyState(scanCode, state); + _shortcutKeyHandler->ProcessKeys(); + } + } DllExport void __stdcall ResetKeyState() { if(_keyManager) { _keyManager->ResetKeyState(); } } DllExport const char* __stdcall GetKeyName(uint32_t keyCode) { @@ -276,6 +297,8 @@ namespace InteropEmu { DllExport void __stdcall Release() { + _shortcutKeyHandler.reset(); + Console::Release(); GameServer::StopServer(); GameClient::Disconnect(); diff --git a/Linux/LinuxKeyManager.cpp b/Linux/LinuxKeyManager.cpp index 2a7c8c19..86d60835 100755 --- a/Linux/LinuxKeyManager.cpp +++ b/Linux/LinuxKeyManager.cpp @@ -5,7 +5,7 @@ #include "../Core/Console.h" static vector _keyDefinitions = { - { "", 9, "Escape", "" }, + { "", 9, "Esc", "" }, { "", 10, "1", "" }, { "", 11, "2", "" }, { "", 12, "3", "" }, @@ -16,8 +16,8 @@ static vector _keyDefinitions = { { "", 17, "8", "" }, { "", 18, "9", "" }, { "", 19, "0", "" }, - { "", 20, "Minus", "" }, - { "", 21, "Equal", "" }, + { "", 20, "-", "" }, + { "", 21, "=", "" }, { "", 22, "BackSpace", "" }, { "", 23, "Tab", "" }, { "", 24, "Q", "" }, @@ -33,7 +33,7 @@ static vector _keyDefinitions = { { "", 34, "Left Bracket", "" }, { "", 35, "Right Bracket", "" }, { "", 36, "Return", "" }, - { "", 37, "Left Control", "" }, + { "", 37, "Ctrl", "" }, { "", 38, "A", "" }, { "", 39, "S", "" }, { "", 40, "D", "" }, @@ -46,7 +46,7 @@ static vector _keyDefinitions = { { "", 47, "Semicolor", "" }, { "", 48, "Apostrophe", "" }, { "", 49, "Grave", "" }, - { "", 50, "Left Shift", "" }, + { "", 50, "Shift", "" }, { "", 51, "\\", "" }, { "", 52, "Z", "" }, { "", 53, "X", "" }, @@ -60,7 +60,7 @@ static vector _keyDefinitions = { { "", 61, "/", "" }, { "", 62, "Right Shift", "" }, { "", 63, "KP Multiply", "" }, - { "", 64, "Left Alt", "" }, + { "", 64, "Alt", "" }, { "", 65, "Space", "" }, { "", 66, "Caps Lock", "" }, { "", 67, "F1", "" }, @@ -262,6 +262,7 @@ LinuxKeyManager::LinuxKeyManager() } } + _disableAllKeys = false; _stopUpdateDeviceThread = false; StartUpdateDeviceThread(); } @@ -280,6 +281,10 @@ void LinuxKeyManager::RefreshState() bool LinuxKeyManager::IsKeyPressed(uint32_t key) { + if(_disableAllKeys) { + return false; + } + if(key >= 0x10000) { uint8_t gamepadPort = (key - 0x10000) / 0x100; uint8_t gamepadButton = (key - 0x10000) % 0x100; @@ -303,22 +308,23 @@ bool LinuxKeyManager::IsMouseButtonPressed(MouseButton button) return false; } -uint32_t LinuxKeyManager::GetPressedKey() +vector LinuxKeyManager::GetPressedKeys() { + vector pressedKeys; for(size_t i = 0; i < _controllers.size(); i++) { for(int j = 0; j <= 54; j++) { if(_controllers[i]->IsButtonPressed(j)) { - return 0x10000 + i * 0x100 + j; + pressedKeys.push_back(0x10000 + i * 0x100 + j); } } } for(int i = 0; i < 0x200; i++) { if(_keyState[i]) { - return i; + pressedKeys.push_back(i); } } - return 0; + return pressedKeys; } string LinuxKeyManager::GetKeyName(uint32_t key) @@ -391,6 +397,17 @@ void LinuxKeyManager::SetKeyState(uint16_t scanCode, bool state) if(scanCode > 0x1FF) { _mouseState[scanCode & 0x03] = state; } else { + scanCode &= 0xFF; + if(scanCode == 105) { + //Left + Right Ctrl + scanCode = 37; + } else if(scanCode == 62) { + //Left + Right Shift + scanCode = 50; + } else if(scanCode == 108) { + //Left + Right Alt + scanCode = 64; + } _keyState[scanCode & 0xFF] = state; } } @@ -400,3 +417,8 @@ void LinuxKeyManager::ResetKeyState() memset(_mouseState, 0, sizeof(_mouseState)); memset(_keyState, 0, sizeof(_keyState)); } + +void WindowsKeyManager::SetDisabled(bool disabled) +{ + _disableAllKeys = disabled; +} diff --git a/Linux/LinuxKeyManager.h b/Linux/LinuxKeyManager.h index 0789c33c..dd86e501 100755 --- a/Linux/LinuxKeyManager.h +++ b/Linux/LinuxKeyManager.h @@ -24,6 +24,7 @@ private: std::thread _updateDeviceThread; atomic _stopUpdateDeviceThread; + bool _disableAllKeys; void StartUpdateDeviceThread(); @@ -34,11 +35,13 @@ public: void RefreshState(); bool IsKeyPressed(uint32_t key); bool IsMouseButtonPressed(MouseButton button); - uint32_t GetPressedKey(); + std::vector GetPressedKeys(); string GetKeyName(uint32_t key); uint32_t GetKeyCode(string keyName); void UpdateDevices(); void SetKeyState(uint16_t scanCode, bool state); void ResetKeyState(); + + void SetDisabled(bool disabled); }; diff --git a/Windows/WindowsKeyManager.cpp b/Windows/WindowsKeyManager.cpp index 4e6a6f90..c38dd917 100644 --- a/Windows/WindowsKeyManager.cpp +++ b/Windows/WindowsKeyManager.cpp @@ -165,7 +165,7 @@ static vector _keyDefinitions = { { "VK_LAUNCH_APP2", 0xB7, "Start Application 2", "" }, //{ "-", 0xB8 - B9, "Reserved", "" }, { "VK_OEM_1", 0xBA, ";", "" }, - { "VK_OEM_PLUS", 0xBB, "+", "" }, + { "VK_OEM_PLUS", 0xBB, "=", "" }, { "VK_OEM_COMMA", 0xBC, ",", "" }, { "VK_OEM_MINUS", 0xBD, "-", "" }, { "VK_OEM_PERIOD", 0xBE, ".", "" }, @@ -282,6 +282,10 @@ void WindowsKeyManager::RefreshState() bool WindowsKeyManager::IsKeyPressed(uint32_t key) { + if(_disableAllKeys) { + return false; + } + if(key >= 0x10000) { if(!_xInput || !_directInput) { return false; @@ -315,17 +319,18 @@ bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button) return false; } -uint32_t WindowsKeyManager::GetPressedKey() +vector WindowsKeyManager::GetPressedKeys() { + vector result; if(!_xInput || !_directInput) { - return 0; + return result; } _xInput->RefreshState(); for(int i = 0; i < XUSER_MAX_COUNT; i++) { for(int j = 1; j <= 26; j++) { if(_xInput->IsPressed(i, j)) { - return 0xFFFF + i * 0x100 + j; + result.push_back(0xFFFF + i * 0x100 + j); } } } @@ -334,17 +339,17 @@ uint32_t WindowsKeyManager::GetPressedKey() for(int i = _directInput->GetJoystickCount() - 1; i >= 0; i--) { for(int j = 0; j < 0x29; j++) { if(_directInput->IsPressed(i, j)) { - return 0x11000 + i * 0x100 + j; + result.push_back(0x11000 + i * 0x100 + j); } } } for(int i = 0; i < 0x200; i++) { if(_keyState[i]) { - return i; + result.push_back(i); } } - return 0; + return result; } string WindowsKeyManager::GetKeyName(uint32_t scanCode) @@ -384,10 +389,20 @@ void WindowsKeyManager::SetKeyState(uint16_t scanCode, bool state) if(scanCode > 0x1FF) { _mouseState[scanCode & 0x03] = state; } else { + uint32_t keyCode = MapVirtualKeyEx(scanCode & 0xFF, MAPVK_VSC_TO_VK, nullptr); + if(keyCode >= 0x10 && keyCode <= 0x12) { + //Ignore "ext" flag for alt, ctrl & shift + scanCode &= 0xFF; + } _keyState[scanCode & 0x1FF] = state; } } +void WindowsKeyManager::SetDisabled(bool disabled) +{ + _disableAllKeys = disabled; +} + void WindowsKeyManager::ResetKeyState() { memset(_mouseState, 0, sizeof(_mouseState)); diff --git a/Windows/WindowsKeyManager.h b/Windows/WindowsKeyManager.h index 5ec57f75..0516820e 100644 --- a/Windows/WindowsKeyManager.h +++ b/Windows/WindowsKeyManager.h @@ -28,6 +28,7 @@ class WindowsKeyManager : public IKeyManager std::thread _updateDeviceThread; atomic _stopUpdateDeviceThread = false; + bool _disableAllKeys = false; void StartUpdateDeviceThread(); @@ -38,12 +39,13 @@ class WindowsKeyManager : public IKeyManager void RefreshState(); bool IsKeyPressed(uint32_t key); bool IsMouseButtonPressed(MouseButton button); - uint32_t GetPressedKey(); + vector GetPressedKeys(); string GetKeyName(uint32_t key); uint32_t GetKeyCode(string keyName); void SetKeyState(uint16_t scanCode, bool state); void ResetKeyState(); + void SetDisabled(bool disabled); void UpdateDevices(); };