diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs index 71367af1b5..b658ab1e87 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs @@ -1350,7 +1350,7 @@ namespace BizHawk.Client.EmuHawk { if (!SuspendHotkeys) { - if (e.Control && !e.Alt && e.Shift && e.KeyCode == Keys.F) // Ctrl+Shift+F + if (e.IsCtrlShift(Keys.F)) { if (Rotatable) { @@ -1358,7 +1358,7 @@ namespace BizHawk.Client.EmuHawk } } // Scroll - else if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.PageUp) // Page Up + else if (e.IsPressed(Keys.PageUp)) { if (ChangeSelectionWhenPaging) { @@ -1380,7 +1380,7 @@ namespace BizHawk.Client.EmuHawk LastVisibleRow = FirstVisibleRow; } } - else if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.PageDown) // Page Down + else if (e.IsPressed(Keys.PageDown)) { if (ChangeSelectionWhenPaging) { @@ -1402,21 +1402,21 @@ namespace BizHawk.Client.EmuHawk FirstVisibleRow = LastVisibleRow; } } - else if (AllowMassNavigationShortcuts && !e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.Home) // Home + else if (AllowMassNavigationShortcuts && e.IsPressed(Keys.Home)) { DeselectAll(); SelectRow(0, true); FirstVisibleRow = 0; Refresh(); } - else if (AllowMassNavigationShortcuts && !e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.End) // End + else if (AllowMassNavigationShortcuts && e.IsPressed(Keys.End)) { DeselectAll(); SelectRow(RowCount - 1, true); LastVisibleRow = RowCount; Refresh(); } - else if (!e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Up) // Up + else if (e.IsPressed(Keys.Up)) { if (SelectedRows.Any()) { @@ -1431,7 +1431,7 @@ namespace BizHawk.Client.EmuHawk } } } - else if (!e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Down) // Down + else if (e.IsPressed(Keys.Down)) { if (SelectedRows.Any()) { @@ -1446,7 +1446,7 @@ namespace BizHawk.Client.EmuHawk } } } - else if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Up) // Shift+Up + else if (e.IsShift(Keys.Up)) { if (MultiSelect && _lastSelectedRow > 0) { @@ -1463,7 +1463,7 @@ namespace BizHawk.Client.EmuHawk Refresh(); } } - else if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Down) // Shift+Down + else if (e.IsShift(Keys.Down)) { if (MultiSelect && _lastSelectedRow < RowCount - 1) { @@ -1486,7 +1486,7 @@ namespace BizHawk.Client.EmuHawk } } // Selection cursor - else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Up) // Ctrl + Up + else if (e.IsCtrl(Keys.Up)) { if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.First() > 0) { @@ -1497,7 +1497,7 @@ namespace BizHawk.Client.EmuHawk } } } - else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Down) // Ctrl + Down + else if (e.IsCtrl(Keys.Down)) { if (SelectedRows.Any() && LetKeysModifySelection) { @@ -1508,35 +1508,35 @@ namespace BizHawk.Client.EmuHawk } } } - else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Left) // Ctrl + Left + else if (e.IsCtrl(Keys.Left)) { if (SelectedRows.Any() && LetKeysModifySelection) { SelectRow(SelectedRows.Last(), false); } } - else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Right) // Ctrl + Right + else if (e.IsCtrl(Keys.Right)) { if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.Last() < _rowCount - 1) { SelectRow(SelectedRows.Last() + 1, true); } } - else if (e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Left) // Ctrl + Shift + Left + else if (e.IsCtrlShift(Keys.Left)) { if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.First() > 0) { SelectRow(SelectedRows.First() - 1, true); } } - else if (e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Right) // Ctrl + Shift + Right + else if (e.IsCtrlShift(Keys.Right)) { if (SelectedRows.Any() && LetKeysModifySelection) { SelectRow(SelectedRows.First(), false); } } - else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.PageUp) // Ctrl + Page Up + else if (e.IsCtrl(Keys.PageUp)) { //jump to above marker with selection courser if (LetKeysModifySelection) @@ -1544,7 +1544,7 @@ namespace BizHawk.Client.EmuHawk } } - else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.PageDown) // Ctrl + Page Down + else if (e.IsCtrl(Keys.PageDown)) { //jump to below marker with selection courser if (LetKeysModifySelection) diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputWidget.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputWidget.cs index bf851a008e..bb6c55531a 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputWidget.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputWidget.cs @@ -177,7 +177,7 @@ namespace BizHawk.Client.EmuHawk protected override void OnKeyUp(KeyEventArgs e) { - if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt) + if (e.IsAlt(Keys.F4)) { base.OnKeyUp(e); } @@ -185,7 +185,7 @@ namespace BizHawk.Client.EmuHawk protected override void OnKeyDown(KeyEventArgs e) { - if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt) + if (e.IsAlt(Keys.F4)) { base.OnKeyDown(e); return; diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index d8ad72b03f..01b0187b0f 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -319,5 +319,20 @@ namespace BizHawk.Client.EmuHawk } } } + + public static bool IsPressed(this KeyEventArgs e, Keys key) + => !e.Alt && !e.Control && !e.Shift && e.KeyCode == key; + + public static bool IsShift(this KeyEventArgs e, Keys key) + => !e.Alt && !e.Control && e.Shift && e.KeyCode == key; + + public static bool IsCtrl(this KeyEventArgs e, Keys key) + => !e.Alt && e.Control && !e.Shift && e.KeyCode == key; + + public static bool IsAlt(this KeyEventArgs e, Keys key) + => e.Alt && !e.Control && !e.Shift && e.KeyCode == key; + + public static bool IsCtrlShift(this KeyEventArgs e, Keys key) + => !e.Alt && e.Control && e.Shift && e.KeyCode == key; } } diff --git a/src/BizHawk.Client.EmuHawk/LogWindow.cs b/src/BizHawk.Client.EmuHawk/LogWindow.cs index afd1a9181d..231bcb422e 100644 --- a/src/BizHawk.Client.EmuHawk/LogWindow.cs +++ b/src/BizHawk.Client.EmuHawk/LogWindow.cs @@ -112,7 +112,7 @@ namespace BizHawk.Client.EmuHawk private void ListView_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) + if (e.IsCtrl(Keys.C)) { ButtonCopy_Click(null, null); } diff --git a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs index 0ed070f0b8..8f8f628f7e 100644 --- a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs @@ -392,13 +392,13 @@ namespace BizHawk.Client.EmuHawk private void lvFirmwares_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) + if (e.IsCtrl(Keys.C)) { PerformListCopy(); } } - void PerformListCopy() + private void PerformListCopy() { var str = lvFirmwares.CopyItemsAsText(); if (str.Length > 0) Clipboard.SetDataObject(str); diff --git a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfigInfo.cs b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfigInfo.cs index 479049dc3c..8eb0dda457 100644 --- a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfigInfo.cs +++ b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfigInfo.cs @@ -28,7 +28,7 @@ namespace BizHawk.Client.EmuHawk private void LvOptions_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) + if (e.IsCtrl(Keys.C)) { PerformListCopy(); } diff --git a/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs b/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs index f0046123a1..cb33dc9ace 100644 --- a/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs @@ -208,9 +208,7 @@ namespace BizHawk.Client.EmuHawk private void SearchBox_KeyDown(object sender, KeyEventArgs e) { - // Tab or Enter - if (!e.Control && !e.Alt && !e.Shift && - (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab)) + if (e.IsPressed(Keys.Enter) || e.IsPressed(Keys.Tab)) { var b = _config.HotkeyBindings.FirstOrDefault(x => string.Compare(x.DisplayName, SearchBox.Text, true) == 0); diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 5b800640ce..866b95242d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -608,11 +608,11 @@ namespace BizHawk.Client.EmuHawk private void CheatListView_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Delete && !e.Control && !e.Alt && !e.Shift) + if (e.IsPressed(Keys.Delete)) { RemoveCheatMenuItem_Click(sender, e); } - else if (e.KeyCode == Keys.A && e.Control && !e.Alt && !e.Shift) + else if (e.IsCtrl(Keys.A)) { SelectAllMenuItem_Click(null, null); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs index c06cbb91cd..ec66d54847 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs @@ -235,7 +235,7 @@ namespace BizHawk.Client.EmuHawk private void BreakpointView_KeyDown(object sender, KeyEventArgs e) { - if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.Delete) // Delete + if (e.IsPressed(Keys.Delete)) { RemoveBreakpointButton_Click(null, null); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs index 3f4840dc12..e34fd2cead 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.Disassembler.cs @@ -204,15 +204,15 @@ namespace BizHawk.Client.EmuHawk private void DisassemblerView_KeyDown(object sender, KeyEventArgs e) { - if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.C) // Ctrl + C + if (e.IsCtrl(Keys.C)) { CopySelectedDisassembler(); } - else if (!e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.PageDown) + else if (e.IsPressed(Keys.PageDown)) { SmallIncrement(); } - else if (!e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.PageUp) + else if (e.IsPressed(Keys.PageUp)) { SmallDecrement(); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index ac22549501..2e7f935ece 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -1350,15 +1350,15 @@ namespace BizHawk.Client.EmuHawk private void LuaListView_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Delete && !e.Control && !e.Alt && !e.Shift) + if (e.IsPressed(Keys.Delete)) { RemoveScriptMenuItem_Click(null, null); } - else if (e.KeyCode == Keys.A && e.Control && !e.Alt && !e.Shift) // Select All + else if (e.IsCtrl(Keys.A)) { SelectAllMenuItem_Click(null, null); } - else if (e.KeyCode == Keys.F12 && !e.Control && !e.Alt && !e.Shift) // F12 + else if (e.IsPressed(Keys.F12)) { RegisteredFunctionsMenuItem_Click(null, null); } @@ -1366,7 +1366,7 @@ namespace BizHawk.Client.EmuHawk private void OutputBox_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.F12 && !e.Control && !e.Alt && !e.Shift) // F12 + if (e.IsPressed(Keys.F12)) { RegisteredFunctionsMenuItem_Click(null, null); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs index ca652a3e52..d1c572eca7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs @@ -113,7 +113,7 @@ namespace BizHawk.Client.EmuHawk private void FunctionView_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) // Copy + if (e.IsCtrl(Keys.C)) { FunctionView_Copy(null, null); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs index 85497ae91f..d88a9f8558 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs @@ -122,15 +122,15 @@ namespace BizHawk.Client.EmuHawk private void FunctionView_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Delete && !e.Control && !e.Alt && !e.Shift) // Delete + if (e.IsPressed(Keys.Delete)) { RemoveFunctionButton(); } - else if (e.KeyCode == Keys.Space && !e.Control && !e.Alt && !e.Shift) // Space + else if (e.IsPressed(Keys.Space)) { CallFunction(); } - else if (e.KeyCode == Keys.Enter && !e.Control && !e.Alt && !e.Shift) // Enter + else if (e.IsPressed(Keys.Enter)) { CallFunction(); } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 11830667d9..6d6261e78d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -1437,19 +1437,19 @@ namespace BizHawk.Client.EmuHawk private void TasView_KeyDown(object sender, KeyEventArgs e) { // taseditor uses Ctrl for selection and Shift for frame cursor - if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.PageUp) // Shift + Page Up + if (e.IsShift(Keys.PageUp)) { GoToPreviousMarker(); } - else if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.PageDown) // Shift + Page Down + else if (e.IsShift(Keys.PageDown)) { GoToNextMarker(); } - else if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Home) // Shift + Home + else if (e.IsShift(Keys.Home)) { GoToFrame(0); } - else if (!e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.End) // Shift + End + else if (e.IsShift(Keys.End)) { GoToFrame(CurrentTasMovie.InputLogLength-1); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index bfbeed02a4..eb8d798bd6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -1675,17 +1675,17 @@ namespace BizHawk.Client.EmuHawk private void WatchListView_KeyDown(object sender, KeyEventArgs e) { - switch (e.KeyCode) + if (e.IsPressed(Keys.Delete)) { - case Keys.Delete when !e.Control && !e.Alt && !e.Shift: - RemoveAddresses(); - break; - case Keys.C when e.Control && !e.Alt && !e.Shift: - CopyWatchesToClipBoard(); - break; - case Keys.Escape when !e.Control && !e.Alt && !e.Shift: - WatchListView.DeselectAll(); - break; + RemoveAddresses(); + } + else if (e.IsCtrl(Keys.C)) + { + CopyWatchesToClipBoard(); + } + else if (e.IsPressed(Keys.Escape)) + { + WatchListView.DeselectAll(); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 3acf0a3030..b831a379bf 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -1191,19 +1191,19 @@ namespace BizHawk.Client.EmuHawk private void WatchListView_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Delete && !e.Control && !e.Alt && !e.Shift) + if (e.IsPressed(Keys.Delete)) { RemoveWatchMenuItem_Click(sender, e); } - else if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) // Ctrl+C + else if (e.IsCtrl(Keys.C)) { CopyWatchesToClipBoard(); } - else if (e.KeyCode == Keys.V && e.Control && !e.Alt && !e.Shift) // Ctrl+V + else if (e.IsCtrl(Keys.V)) { PasteWatchesToClipBoard(); } - else if (e.KeyCode == Keys.Enter && !e.Control && !e.Alt && !e.Shift) // Enter + else if (e.IsPressed(Keys.Enter)) { EditWatch(); }