public void Should_Handle_OneChord(KeyEventDto[] events, string expected) { // Act _kc.Handle(_removal, events); // Assert _kc.ToString().Should().Be(expected); }
private void tmrCheckKey_Tick(object sender, EventArgs e) { List <UInt32> scanCodes = InputApi.GetPressedKeys(); if (_singleKeyMode) { if (scanCodes.Count >= 1) { //Always use the largest scancode (when multiple buttons are pressed at once) scanCodes = new List <UInt32> { scanCodes.OrderBy(code => - code).First() }; this.SelectKeyCombination(new KeyCombination(scanCodes)); } } else { KeyCombination key = new KeyCombination(_prevScanCodes); lblCurrentKeys.Text = key.ToString(); if (scanCodes.Count < _prevScanCodes.Count) { //Confirm key selection when the user releases a key this.SelectKeyCombination(key); } _prevScanCodes = scanCodes; } }
private void SelectKeyCombination(KeyCombination key) { if (!string.IsNullOrWhiteSpace(key.ToString())) { ShortcutKey = key; this.Close(); } }
private void tmrCheckKey_Tick(object sender, EventArgs e) { List <UInt32> 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; }
private void butHotKey_Click(object sender, EventArgs e) { HotKeyInputForm hkForm = new HotKeyInputForm(); hkForm.TopMost = this.TopMost; if (hkForm.ShowDialog() == DialogResult.OK) { selectedKeys = (KeyCombination)hkForm.SelectedKeys; txtHotKey.Text = selectedKeys.ToString(); } }
private void butHotKey_Click(object sender, EventArgs e) { // remove current shortcut during key selection main.SetHotKey(KeyCombination.None); HotKeyInputForm hkForm = new HotKeyInputForm((Keys)selectedKeys); if (hkForm.ShowDialog(this) == DialogResult.OK) { selectedKeys = (KeyCombination)hkForm.SelectedKeys; txtHotKey.Text = selectedKeys.ToString(); } // restores previous shortcut main.SetHotKey(selectedKeys); }
public OptionsForm(MainApplicationContext main) { this.main = main; this.selectedKeys = main.HotKey?.KeyCombination ?? KeyCombination.None; InitializeComponent(); // --- General section --- chkTruncateTitle.Checked = Settings.Default.TitleLengthLimit < int.MaxValue; numLimit.Value = Settings.Default.TitleLengthLimit; chkHotKey.Checked = main.HotKey != null; panHotKey.Enabled = chkHotKey.Checked; txtHotKey.Text = selectedKeys.ToString(); // --- Application section --- chkUpdates.Checked = Settings.Default.AlwaysCheckForUpdates; }
public XElement ToXElement() { return(new XElement("TableTile", new XElement("Name", Name), new XElement("IsEnabled", IsEnabled.ToString()), new XElement("Hotkey", KeyCombination.ToString()), new XElement("SortByStartingHand", SortByStartingHand.ToString()), new XElement("BringToFront", BringToFront), new XElement("AutoTile", AutoTile.ToString()), new XElement("AutoTileMethod", AutoTileMethod.ToString()), new XElement("RegexWindowTitle", RegexWindowTitle.ToString()), new XElement("RegexWindowClass", RegexWindowClass.ToString()), new XElement("XYWHs", XYWHs.Select(o => new XElement("XYWH", string.Format("{0} {1} {2} {3}", o.X, o.Y, o.Width, o.Height)))), new XElement("TableCountEqualOrGreaterThan", TableCountEqualOrGreaterThan), new XElement("TableCountEqualOrLessThan", TableCountEqualOrLessThan) )); }
private void CheckConflicts() { HashSet <string> keyCombinations = new HashSet <string>(); 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; }
/// <summary> /// Sets a new key combination as global shortcut for grabbing the current position. /// </summary> private void setNewHotKey(Keys keys) { hotKey?.Dispose(); Settings.ShortcutKey = keys; if (keys == Keys.None) { return; } KeyCombination combination = (KeyCombination)keys; try { hotKey = new GlobalHotKey(combination, (k) => addPositionToLog()); hotKey.Register(); lblHelp.Text = String.Format("Press {0} to capture a position.", combination); conLog.ShortcutKeyDisplayString = combination.ToString(); } catch (InvalidOperationException) { MessageBox.Show( "Registering global keyboard shortcut failed.\nThis could be caused by another app using the same global shortcut.", "MPos - Error"); } }
public void InitializeGrid(PreferencesConfig config) { _config = config; EmulatorShortcut[] displayOrder = new EmulatorShortcut[] { EmulatorShortcut.FastForward, EmulatorShortcut.ToggleFastForward, EmulatorShortcut.Rewind, EmulatorShortcut.ToggleRewind, EmulatorShortcut.RewindTenSecs, EmulatorShortcut.RewindOneMin, EmulatorShortcut.Pause, EmulatorShortcut.Reset, EmulatorShortcut.PowerCycle, EmulatorShortcut.PowerOff, EmulatorShortcut.Exit, EmulatorShortcut.TakeScreenshot, EmulatorShortcut.RunSingleFrame, EmulatorShortcut.SetScale1x, EmulatorShortcut.SetScale2x, EmulatorShortcut.SetScale3x, EmulatorShortcut.SetScale4x, EmulatorShortcut.SetScale5x, EmulatorShortcut.SetScale6x, EmulatorShortcut.ToggleFullscreen, EmulatorShortcut.ToggleDebugInfo, EmulatorShortcut.ToggleFps, EmulatorShortcut.ToggleGameTimer, EmulatorShortcut.ToggleFrameCounter, EmulatorShortcut.ToggleOsd, EmulatorShortcut.ToggleAlwaysOnTop, EmulatorShortcut.ToggleAudio, EmulatorShortcut.ToggleCheats, EmulatorShortcut.ToggleBgLayer0, EmulatorShortcut.ToggleBgLayer1, EmulatorShortcut.ToggleBgLayer2, EmulatorShortcut.ToggleBgLayer3, EmulatorShortcut.ToggleSprites, EmulatorShortcut.EnableAllLayers, EmulatorShortcut.MaxSpeed, EmulatorShortcut.IncreaseSpeed, EmulatorShortcut.DecreaseSpeed, EmulatorShortcut.OpenFile, EmulatorShortcut.LoadRandomGame, EmulatorShortcut.MoveToNextStateSlot, EmulatorShortcut.MoveToPreviousStateSlot, EmulatorShortcut.SaveState, EmulatorShortcut.LoadState, EmulatorShortcut.SaveStateSlot1, EmulatorShortcut.SaveStateSlot2, EmulatorShortcut.SaveStateSlot3, EmulatorShortcut.SaveStateSlot4, EmulatorShortcut.SaveStateSlot5, EmulatorShortcut.SaveStateSlot6, EmulatorShortcut.SaveStateSlot7, EmulatorShortcut.SaveStateSlot8, EmulatorShortcut.SaveStateSlot9, EmulatorShortcut.SaveStateSlot10, EmulatorShortcut.SaveStateToFile, EmulatorShortcut.LoadStateSlot1, EmulatorShortcut.LoadStateSlot2, EmulatorShortcut.LoadStateSlot3, EmulatorShortcut.LoadStateSlot4, EmulatorShortcut.LoadStateSlot5, EmulatorShortcut.LoadStateSlot6, EmulatorShortcut.LoadStateSlot7, EmulatorShortcut.LoadStateSlot8, EmulatorShortcut.LoadStateSlot9, EmulatorShortcut.LoadStateSlot10, EmulatorShortcut.LoadStateFromFile, }; HashSet <string> keyCombinations = new HashSet <string>(); 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 = config.ShortcutKeys1.FindIndex((ShortcutKeyInfo shortcutInfo) => shortcutInfo.Shortcut == shortcut); if (keyIndex >= 0) { KeyCombination keyComb = config.ShortcutKeys1[keyIndex].KeyCombination; keyCombinations.Add(keyComb.ToString()); gridShortcuts.Rows[i].Cells[1].Value = keyComb.ToString(); gridShortcuts.Rows[i].Cells[1].Tag = keyComb; } keyIndex = config.ShortcutKeys2.FindIndex((ShortcutKeyInfo shortcutInfo) => shortcutInfo.Shortcut == shortcut); if (keyIndex >= 0) { KeyCombination keyComb = config.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 InitializeGrid() { EmulatorShortcut[] displayOrder = new EmulatorShortcut[] { EmulatorShortcut.FastForward, EmulatorShortcut.ToggleFastForward, EmulatorShortcut.Rewind, EmulatorShortcut.ToggleRewind, EmulatorShortcut.RewindTenSecs, EmulatorShortcut.RewindOneMin, EmulatorShortcut.Pause, EmulatorShortcut.Reset, EmulatorShortcut.PowerCycle, EmulatorShortcut.PowerOff, EmulatorShortcut.Exit, EmulatorShortcut.InsertNextDisk, EmulatorShortcut.SwitchDiskSide, EmulatorShortcut.EjectDisk, EmulatorShortcut.InsertCoin1, EmulatorShortcut.InsertCoin2, EmulatorShortcut.InsertCoin3, EmulatorShortcut.InsertCoin4, EmulatorShortcut.VsServiceButton, EmulatorShortcut.VsServiceButton2, EmulatorShortcut.InputBarcode, EmulatorShortcut.TakeScreenshot, EmulatorShortcut.LoadRandomGame, EmulatorShortcut.RunSingleFrame, EmulatorShortcut.SetScale1x, EmulatorShortcut.SetScale2x, EmulatorShortcut.SetScale3x, EmulatorShortcut.SetScale4x, EmulatorShortcut.SetScale5x, EmulatorShortcut.SetScale6x, EmulatorShortcut.ToggleFullscreen, EmulatorShortcut.ToggleDebugInfo, EmulatorShortcut.ToggleFps, EmulatorShortcut.ToggleGameTimer, EmulatorShortcut.ToggleFrameCounter, EmulatorShortcut.ToggleLagCounter, EmulatorShortcut.ToggleOsd, EmulatorShortcut.ToggleAlwaysOnTop, EmulatorShortcut.ToggleBackground, EmulatorShortcut.ToggleSprites, EmulatorShortcut.ToggleCheats, EmulatorShortcut.ToggleAudio, EmulatorShortcut.ToggleKeyboardMode, EmulatorShortcut.MaxSpeed, EmulatorShortcut.IncreaseSpeed, EmulatorShortcut.DecreaseSpeed, EmulatorShortcut.OpenFile, EmulatorShortcut.MoveToNextStateSlot, EmulatorShortcut.MoveToPreviousStateSlot, EmulatorShortcut.SaveState, EmulatorShortcut.LoadState, EmulatorShortcut.SaveStateSlot1, EmulatorShortcut.SaveStateSlot2, EmulatorShortcut.SaveStateSlot3, EmulatorShortcut.SaveStateSlot4, EmulatorShortcut.SaveStateSlot5, EmulatorShortcut.SaveStateSlot6, EmulatorShortcut.SaveStateSlot7, EmulatorShortcut.SaveStateSlot8, EmulatorShortcut.SaveStateSlot9, EmulatorShortcut.SaveStateSlot10, EmulatorShortcut.SaveStateToFile, EmulatorShortcut.LoadStateSlot1, EmulatorShortcut.LoadStateSlot2, EmulatorShortcut.LoadStateSlot3, EmulatorShortcut.LoadStateSlot4, EmulatorShortcut.LoadStateSlot5, EmulatorShortcut.LoadStateSlot6, EmulatorShortcut.LoadStateSlot7, EmulatorShortcut.LoadStateSlot8, EmulatorShortcut.LoadStateSlot9, EmulatorShortcut.LoadStateSlot10, EmulatorShortcut.LoadStateSlotAuto, EmulatorShortcut.LoadStateFromFile, EmulatorShortcut.LoadLastSession, }; HashSet <string> keyCombinations = new HashSet <string>(); 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 SetKeyText() { textBoxKeyCode.Text = shortCutValue.Key == Keys.None && shortCutValue.Modifiers == Modifiers.None ? None : shortCutValue.ToString(); }
public override string ToString() { return(KeyCombination == Keys.None ? "New Shortcut" : KeyCombination.ToString()); }