private bool findCollision(Utils.KeyCombination shortcut) { string collision; if (!knownShortcuts.TryGetValue(shortcut, out collision) && this.allSettableShortcuts != null) { var collisionRecorder = this.allSettableShortcuts .FirstOrDefault(r => r != this && r.Shortcut == shortcut); if (collisionRecorder != null) { collision = collisionRecorder.ShortcutName; } } if (collision == null) { return(false); } this.errorText.Text = string.Format( "{0} already taken by: {1}", keyEventToString(shortcut), collision ); return(true); }
private static string keyEventToString(Utils.KeyCombination shortcut) { var modifiers = shortcut.Modifiers; var res = ""; if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Win)) { res += "Win + "; } if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Control)) { res += "Ctrl + "; } if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Shift)) { res += "Shift + "; } if (modifiers.HasFlag(TogglDesktop.ModifierKeys.Alt)) { res += "Alt + "; } res += shortcut.KeyCode; return(res); }
private void setShortcut(Utils.KeyCombination shortcut) { this.Shortcut = shortcut; this.HasChanged = true; this.button.Content = keyEventToString(shortcut); this.errorText.Text = ""; }
private void onKeyUp(object sender, KeyEventArgs e) { if (!this.recording) { return; } var key = (e.Key == Key.System ? e.SystemKey : e.Key); // ignore modifier key releases if (this.checkModifiers(key)) { return; } var mods = this.activatedModifiers; if ((mods & requiredModifiersUnion) == ModifierKeys.None) { if (key == Key.Enter || key == Key.Space) { // this happens when user starts recoding with keyboard return; } this.errorText.Text = "Shortcut must contain Alt, Ctrl, or Windows key."; this.cancelRecording(); return; } this.cancelRecording(); if (key == Key.None) { this.errorText.Text = "Something went wrong. Please try again."; return; } e.Handled = true; var keyString = key.ToString(); var shortcut = new Utils.KeyCombination(mods, keyString); if (this.findCollision(shortcut)) { return; } this.setShortcut(shortcut); }
private void onKeyUp(object sender, KeyEventArgs e) { if (!this.recording) return; var key = (e.Key == Key.System ? e.SystemKey : e.Key); // ignore modifier key releases if (this.checkModifiers(key)) return; var mods = this.activatedModifiers; if ((mods & requiredModifiersUnion) == ModifierKeys.None) { if (key == Key.Enter || key == Key.Space) { // this happens when user starts recoding with keyboard return; } this.errorText.Text = "Shortcut must contain Alt, Ctrl, or Windows key."; this.cancelRecording(); return; } this.cancelRecording(); if (key == Key.None) { this.errorText.Text = "Something went wrong. Please try again."; return; } e.Handled = true; var keyString = key.ToString(); var shortcut = new Utils.KeyCombination(mods, keyString); if (this.findCollision(shortcut)) return; this.setShortcut(shortcut); }