Ejemplo n.º 1
0
        private void dataGridViewShortcuts_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1 || e.ColumnIndex == -1)
            {
                return;
            }

            Log.InfoFormat("Shortcuts grid click: row={0}, col={1}", e.RowIndex, e.ColumnIndex);
            DataGridViewColumn col = this.dataGridViewShortcuts.Columns[e.ColumnIndex];
            DataGridViewRow    row = this.dataGridViewShortcuts.Rows[e.RowIndex];
            KeyboardShortcut   ks  = (KeyboardShortcut)row.DataBoundItem;

            if (col == colEdit)
            {
                KeyboardShortcutEditor editor = new KeyboardShortcutEditor
                {
                    StartPosition = FormStartPosition.CenterParent
                };
                if (DialogResult.OK == editor.ShowDialog(this, ks))
                {
                    this.Shortcuts.ResetItem(this.Shortcuts.IndexOf(ks));
                    Log.InfoFormat("Edited shortcut: {0}", ks);
                }
            }
            else if (col == colClear)
            {
                ks.Clear();
                this.Shortcuts.ResetItem(this.Shortcuts.IndexOf(ks));
                Log.InfoFormat("Cleared shortcut: {0}", ks);
            }
        }
        public static void Update()
        {
            if (!Map.IsInstance() || Map.Instance.Player == null)
            {
                return;
            }

            KeyboardShortcut hotkey = ToggleKey.Value;

            if (UnityEngine.Input.GetKeyDown(hotkey.MainKey) &&
                hotkey.Modifiers.All(key => UnityEngine.Input.GetKey(key)))
            {
                run = !run;
            }

            if (!run)
            {
                return;
            }

            float mult = RunMultiplier.Value;

            if (mult <= 0f)
            {
                return;
            }

            PlayerActor player = Map.Instance.Player;

            player.Locomotor.Move(player.Forward * mult);
        }
Ejemplo n.º 3
0
        public void Load()
        {
            // Settings
            WindowListSingleClick = Settings.Default.WindowListSingleClick;

            // Shortcut
            var shortcut = KeyboardShortcut.FromString(Settings.Default.OpenShortcut);

            ShortcutControlKey        = Enum.IsDefined(typeof(ModifierVirtualKeys), shortcut.ControlVirtualKeyCode) ? (ModifierVirtualKeys)shortcut.ControlVirtualKeyCode : ModifierVirtualKeys.Undefined;
            ShortcutKey               = shortcut.VirtualKeyCode;
            ShortcutPressesBeforeOpen = shortcut.ShortcutPressesBeforeOpen;

            // Warnings
            NoElevatedPrivilegesWarning = !WindowsRuntimeHelper.GetHasElevatedPrivileges();

            // Plugins
            var disabledPlugins = Settings.Default.DisabledPlugins ?? new StringCollection();

            Plugins = _context.PluginsContainer.Plugins
                      .Select(plugin => new SettingsPluginViewModel
            {
                Id      = plugin.Id,
                Enabled = !disabledPlugins.Contains(plugin.Id),
                Name    = plugin.Title
            })
                      .OrderBy(plugin => plugin.Name)
                      .ToList();
            var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

            Version = String.Format("{0}.{1}.{2}", currentVersion.Major, currentVersion.Minor, currentVersion.Build);

            // Updates
            UpdateAvailable = CheckForUpdatesStatus.Checking;
            _updater.CheckForUpdates(CheckForUpdatesCallback, CheckForUpdatesError);
        }
Ejemplo n.º 4
0
        public GlobalHotkey(Form form, KeyboardShortcut shortcut, Keys key)
        {
            Form     = form;
            Shortcut = shortcut;
            Key      = key;

            // convert the Keys to modifiers
            Modifiers = NativeMethods.HotKeysConstants.NOMOD;
            if (IsControlSet)
            {
                Modifiers += NativeMethods.HotKeysConstants.CTRL;
            }
            if (IsAltSet)
            {
                Modifiers += NativeMethods.HotKeysConstants.ALT;
            }
            if (IsShiftSet)
            {
                Modifiers += NativeMethods.HotKeysConstants.SHIFT;
            }

            // make uid
            Id = Shortcut.GetHashCode() ^ Form.Handle.ToInt32();

            Register();
        }
Ejemplo n.º 5
0
        public KeyboardShortcut[] LoadShortcuts()
        {
            List <KeyboardShortcut> shortcuts = new List <KeyboardShortcut>();

            foreach (SuperPuttyAction action in Enum.GetValues(typeof(SuperPuttyAction)))
            {
                string name = string.Format("Action_{0}_Shortcut", action);

                // default
                KeyboardShortcut ks = new KeyboardShortcut {
                    Key = Keys.None
                };

                // try load froms settings, note that Ctrl/Strg have conflicts
                // http://blogs.msdn.com/b/michkap/archive/2010/06/05/10019465.aspx
                try
                {
                    Keys keys = (Keys)this[name];
                    ks = KeyboardShortcut.FromKeys(keys);
                }
                catch (ArgumentException ex)
                {
                    Log.Warn("Could not convert shortcut text to Keys, possible localization bug with Ctrl and Strg.  Setting to None: " + name, ex);
                }
                catch (SettingsPropertyNotFoundException)
                {
                    Log.Debug("Could not load shortcut for " + name + ", Setting to None.");
                }

                ks.Name = action.ToString();
                shortcuts.Add(ks);
            }

            return(shortcuts.ToArray());
        }
Ejemplo n.º 6
0
        public GlobalHotkey(Form form, KeyboardShortcut shortcut)
        {
            this.Form     = form;
            this.Shortcut = shortcut;

            // convert the Keys to modifiers
            this.Modifiers = NativeMethods.HotKeysConstants.NOMOD;
            if (IsControlSet)
            {
                this.Modifiers += NativeMethods.HotKeysConstants.CTRL;
            }
            if (IsAltSet)
            {
                this.Modifiers += NativeMethods.HotKeysConstants.ALT;
            }
            if (IsShiftSet)
            {
                this.Modifiers += NativeMethods.HotKeysConstants.SHIFT;
            }

            // make uid
            this.Id = this.Shortcut.GetHashCode() ^ this.Form.Handle.ToInt32();

            this.Register();
        }
Ejemplo n.º 7
0
        private void UpgradeKeyboardShortcuts()
        {
            Debug.Log("[SRDebugger] Upgrading Settings format");

            var newShortcuts = new List <KeyboardShortcut>();

            for (var i = 0; i < _keyboardShortcuts.Length; i++)
            {
                var s = _keyboardShortcuts[i];

                newShortcuts.Add(new KeyboardShortcut
                {
                    Action  = s.Action,
                    Key     = s.Key,
                    Alt     = _keyboardModifierAlt,
                    Shift   = _keyboardModifierShift,
                    Control = _keyboardModifierControl
                });
            }

            _keyboardShortcuts    = new KeyboardShortcut[0];
            _newKeyboardShortcuts = newShortcuts.ToArray();

#if UNITY_EDITOR
            EditorUtility.SetDirty(this);
#endif
        }
Ejemplo n.º 8
0
        public void KeyboardShortcutTest2()
        {
            Assert.AreEqual(KeyboardShortcut.Empty, new KeyboardShortcut());

            var c = MakeConfig();

            var w = c.Bind("Cat", "Key", KeyboardShortcut.Empty, new ConfigDescription("Test"));

            Assert.AreEqual("", w.GetSerializedValue());

            w.SetSerializedValue(w.GetSerializedValue());
            Assert.AreEqual(KeyboardShortcut.Empty, w.Value);

            var testShortcut = new KeyboardShortcut(KeyCode.A, KeyCode.B, KeyCode.C);

            w.Value = testShortcut;

            w.SetSerializedValue(w.GetSerializedValue());
            Assert.AreEqual(testShortcut, w.Value);

            c.Save();
            c.Reload();

            Assert.AreEqual(testShortcut, w.Value);
        }
Ejemplo n.º 9
0
 public void CanCreateHumanReadableString()
 {
     Assert.AreEqual("Left Alt + Tab", KeyboardShortcut.FromString("A4+09:1").ToHumanReadableString());
     Assert.AreEqual("Left Alt + Tab + Tab", KeyboardShortcut.FromString("A4+09:2").ToHumanReadableString());
     Assert.AreEqual("Left Win + Tab", KeyboardShortcut.FromString("5B+09:1").ToHumanReadableString());
     Assert.AreEqual("Left Win + Tab + Tab", KeyboardShortcut.FromString("5B+09:2").ToHumanReadableString());
 }
Ejemplo n.º 10
0
        public void FromStringContainsAllOptions()
        {
            var shortcut = KeyboardShortcut.FromString("A4+09:2");

            Assert.AreEqual(0x09, shortcut.VirtualKeyCode);
            Assert.AreEqual(0xA4, shortcut.ControlVirtualKeyCode);
            Assert.AreEqual(2, shortcut.ShortcutPressesBeforeOpen);
        }
Ejemplo n.º 11
0
        void SetupTotalHotkeys()
        {
            TotalHotkeys = Config.Bind(Convert.ToChar(0x356) + "*General*", "Amount Of Keybinds (Needs Menu Reload)", hotkeysToResetTo, new ConfigDescription("", null, new ConfigurationManagerAttributes {
                Order = 0
            }));

            ColorHydraulicPistons = Config.Bind(Convert.ToChar(0x356) + "*General*", "Color Hydraulic Pistons", false, new ConfigDescription("Toggles coloring the hydraulic piston.", null, new ConfigurationManagerAttributes {
                Order = 0
            }));
            ColorHydraulicSleeve = Config.Bind(Convert.ToChar(0x356) + "*General*", "Color Hydraulic Sleeve", true, new ConfigDescription("Toggles coloring the hydraulic sleeve.", null, new ConfigurationManagerAttributes {
                Order = 0
            }));

            GamingSpeedMultiplier = Config.Bind(Convert.ToChar(0x356) + "*General*", "RGB Speed Multiplier", 1f, new ConfigDescription("", null, new ConfigurationManagerAttributes {
                Order = 0
            }));
            GamingDistanceXMultiplier = Config.Bind(Convert.ToChar(0x356) + "*General*", "RGB X Distance Multiplier", 1f, new ConfigDescription("The difference between the colors of farther away materials (Use 0 to disable)", null, new ConfigurationManagerAttributes {
                Order = 0
            }));
            GamingDistanceYMultiplier = Config.Bind(Convert.ToChar(0x356) + "*General*", "RGB Y Distance Multiplier", 1f, new ConfigDescription("The difference between the colors of farther away materials (Use 0 to disable)", null, new ConfigurationManagerAttributes {
                Order = 0
            }));

            TotalHotkeys.SettingChanged += (o, e) =>
            {
                Logger.LogMessage("Resetting to " + TotalHotkeys.Value + " hotkeys");
                try
                {
                    hotkeysToResetTo = TotalHotkeys.Value; //Get around recursion

                    String[]           colorStrs         = new String[TotalHotkeys.Value];
                    KeyboardShortcut[] keyboardShortcuts = new KeyboardShortcut[TotalHotkeys.Value];

                    for (int i = 0; i < TotalHotkeys.Value; i++)
                    {
                        if (i < ColorHotkeys.Count())
                        {
                            colorStrs[i]         = ColorStrings[i].Value;
                            keyboardShortcuts[i] = ColorHotkeys[i].Value;
                        }
                    }

                    Config.Clear();
                    SetupTotalHotkeys();
                    SetupSettings();

                    for (int i = 0; i < TotalHotkeys.Value; i++)
                    {
                        ColorStrings[i].Value = colorStrs[i];
                        ColorHotkeys[i].Value = keyboardShortcuts[i];
                    }
                }
                catch (Exception f)
                {
                    Logger.LogError("An error has occured with resetting the hotkeys.");
                }
            };
        }
Ejemplo n.º 12
0
 public static bool BepInExGetKeyUp(KeyboardShortcut shortcut)
 {
     if (Input.GetKeyUp(shortcut.MainKey))
     {
         bool allModifiersPressed = shortcut.Modifiers.All(c => Input.GetKey(c));
         return(allModifiersPressed);
     }
     return(false);
 }
Ejemplo n.º 13
0
        private void LoadConfig()
        {
            var defaultShortcut = new KeyboardShortcut(KeyCode.LeftShift);

            Settings.keyboardShortcut = Config.Bind("General",
                                                    "Shortcut",
                                                    defaultShortcut,
                                                    "Keyboard shortcut that need to be pressed to skip AskWindow");
        }
        public SetShortcutDialog([NotNull] KeyboardShortcut shortcut, [NotNull] string text)
        {
            Shortcut = shortcut;
            InitializeComponent();
            this.InitializeDialog();

            KeyLabel.Content = "Select keyboard shortcut for \"" + text + "\":";
            KeysTextBox.Text = shortcut.FormattedKeys;
        }
Ejemplo n.º 15
0
        private static void AddShortcut(ref List <KeyboardShortcut> list, KeyboardCombination combination, Key key, string method, RoutedMethodRegistry mr)
        {
            try
            {
                var res = mr[method];

                KeyboardShortcut ks = new KeyboardShortcut(combination, key, res.handler, res.methodId, res.menuItem);
                list.Add(ks);
            }
            catch (KeyNotFoundException) { }
        }
Ejemplo n.º 16
0
        //public Func<string, RoutedEventHandler> GetMethodFunction { get; private set; }
        //public Func<string, MenuItem> GetMenuFunction { get; private set; }

        private void Master_ShortcutRegistered(object sender, KeyboardShortcutEventArgs e)
        {
            KeyboardShortcut kc = e.KeyboardShortcut;

            try
            {
                RegisterKeyShortcut(kc);
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }
		public void ToStringContainsAllKeys()
		{
			// ReSharper disable RedundantArgumentNameForLiteralExpression
			var shortcut = new KeyboardShortcut
			(
				controlVirtualKeyCode: 0xA4,
				virtualKeyCode: 0x09,
				shortcutPressesBeforeOpen: 2
			);
			// ReSharper restore RedundantArgumentNameForLiteralExpression
			Assert.AreEqual("A4+09:2", shortcut.ToString());
		}
Ejemplo n.º 18
0
        public Hotkey(KeyboardShortcut newKey, float newProcTime = 0f)
        {
            key = newKey;
            if (key.MainKey == KeyCode.None)
            {
                enabled = false;
            }

            if (newProcTime > 0f)
            {
                procTime = newProcTime;
            }
        }
Ejemplo n.º 19
0
        public void ToStringContainsAllKeys()
        {
            // ReSharper disable RedundantArgumentNameForLiteralExpression
            var shortcut = new KeyboardShortcut
                           (
                controlVirtualKeyCode: 0xA4,
                virtualKeyCode: 0x09,
                shortcutPressesBeforeOpen: 2
                           );

            // ReSharper restore RedundantArgumentNameForLiteralExpression
            Assert.AreEqual("A4+09:2", shortcut.ToString());
        }
Ejemplo n.º 20
0
 public void EnableKeyboardHook(KeyboardShortcut shortcut)
 {
     if (shortcut.Enabled)
     {
         _hooks?.Dispose();
         _hooks = KeyboardHook.Hook(shortcut, HandleShortcut);
     }
     else if (_hooks != null)
     {
         _hooks.Dispose();
         _hooks = null;
     }
 }
Ejemplo n.º 21
0
        public void CanInterceptAltTab()
        {
            var intercepted = false;
            var shortcut    = new KeyboardShortcut((int)ModifierVirtualKeys.LAlt, /* VK_TAB */ 0x09, 1);

            using (KeyboardHook.Hook(shortcut, () => intercepted = true))
            {
                KeyboardSend.KeyDown(KeyboardSend.LAlt);
                KeyboardSend.KeyPress(KeyboardSend.Tab);
                KeyboardSend.KeyUp(KeyboardSend.LAlt);
            }

            Assert.IsTrue(intercepted, "Alt + Tab was not intercepted by InterceptAltTab");
        }
Ejemplo n.º 22
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            e.Handled          = true;
            e.SuppressKeyPress = true;

            if (e.KeyData == Keys.Delete || e.KeyData == Keys.Back)
            {
                Shortcut = null;
            }
            else if (KeyboardUtils.IsValidShortcutKey(e.KeyCode))
            {
                Shortcut = KeyboardUtils.CreateShortcut(e);
            }
        }
		public void CanInterceptAltTab()
		{
			var intercepted = false;
			var shortcut = new KeyboardShortcut((int)ModifierVirtualKeys.LAlt, /* VK_TAB */ 0x09, 1);

			using (KeyboardHook.Hook(shortcut, () => intercepted = true))
			{
				KeyboardSend.KeyDown(KeyboardSend.LAlt);
				KeyboardSend.KeyPress(KeyboardSend.Tab);
				KeyboardSend.KeyUp(KeyboardSend.LAlt);
			}

			Assert.IsTrue(intercepted, "Alt + Tab was not intercepted by InterceptAltTab");
		}
Ejemplo n.º 24
0
        public static string GetDisplayText([NotNull] KeyboardShortcut keyboardShortcut)
        {
            Assert.ArgumentNotNull(keyboardShortcut, nameof(keyboardShortcut));

            // TODO interpret as char value, no key value
            var key = (Keys)keyboardShortcut.Key;

            var sb = new StringBuilder();

            AppendModifiers(keyboardShortcut, sb);

            sb.Append(GetDisplayText(key));

            return(sb.ToString());
        }
Ejemplo n.º 25
0
            public static string Hotkey_ToString(KeyboardShortcut KeyboardShortcut)
            {
                string result = "";

                if (KeyboardShortcut.Modifiers.Count() > 0)
                {
                    result  = string.Join(" + ", KeyboardShortcut.Modifiers.Select((KeyCode c) => c.ToString()).ToArray());
                    result += $" + {KeyboardShortcut.MainKey}";
                }
                else
                {
                    result = KeyboardShortcut.MainKey.ToString();
                }

                return(result);
            }
        public CombinedBox()
        {
            filterEntry = new SearchEntry();
            filterEntry.WidthRequest             = 180;
            filterEntry.Ready                    = true;
            filterEntry.ForceFilterButtonVisible = true;
            filterEntry.Entry.CanFocus           = true;
            filterEntry.RoundedShape             = true;
            filterEntry.HasFrame                 = true;
            filterEntry.Parent                   = this;
            filterEntry.Show();

            SearchKeyShortcut = new KeyboardShortcut(
                Gdk.Key.f, Platform.IsMac? Gdk.ModifierType.MetaMask : Gdk.ModifierType.ControlMask
                );
        }
Ejemplo n.º 27
0
        public void ToStringTest()
        {
            KeyboardShortcut ks = new KeyboardShortcut();

            Assert.AreEqual("", ks.ShortcutString);

            ks.Key = Keys.F11;
            Assert.AreEqual("F11", ks.ShortcutString);

            ks.Key       = Keys.PageUp;
            ks.Modifiers = Keys.Control;
            Assert.AreEqual("Ctrl+PageUp", ks.ShortcutString);

            ks.Modifiers |= Keys.Shift;
            Assert.AreEqual("Ctrl+Shift+PageUp", ks.ShortcutString);
        }
Ejemplo n.º 28
0
        public void KeyboardShortcutTest()
        {
            var shortcut = new KeyboardShortcut(KeyCode.H, KeyCode.O, KeyCode.R, KeyCode.S, KeyCode.E, KeyCode.Y);
            var s        = shortcut.Serialize();
            var d        = KeyboardShortcut.Deserialize(s);

            Assert.AreEqual(shortcut, d);

            var c = MakeConfig();
            var w = c.Bind("Cat", "Key", new KeyboardShortcut(KeyCode.A, KeyCode.LeftShift));

            Assert.AreEqual(new KeyboardShortcut(KeyCode.A, KeyCode.LeftShift), w.Value);

            w.Value = shortcut;
            c.Reload();
            Assert.AreEqual(shortcut, w.Value);
        }
Ejemplo n.º 29
0
        public void ShowStartupTooltip()
        {
            var shortcut = KeyboardShortcut.FromString(Properties.Settings.Default.OpenShortcut);
            var openShortcutDescription = shortcut.ToHumanReadableString();

            var tooltipMessage = $"Press {openShortcutDescription} and start typing to find a window.";

            if (!WindowsRuntimeHelper.GetHasElevatedPrivileges())
            {
                tooltipMessage += Environment.NewLine + Environment.NewLine + "NOTE: Not running with elevated privileges. Performance will be affected; Will not work in applications running as an administrator.";
            }

            _trayIcon.ShowBalloonTip(
                "Go To Window",
                tooltipMessage,
                BalloonIcon.None);
        }
        private static void SetShortcut([NotNull] MenuItem menuItem)
        {
            Debug.ArgumentNotNull(menuItem, nameof(menuItem));

            var command = menuItem.Tag;

            if (command == null)
            {
                return;
            }

            var stack = menuItem.Header as StackPanel;

            if (stack == null)
            {
                return;
            }

            var image = stack.Children[1] as Image;

            if (image == null)
            {
                return;
            }

            var tag = image.Tag as string ?? string.Empty;

            tag = tag.Mid(10);

            var parts = tag.Split('|');

            var shortcut = KeyboardManager.Shortcuts.FirstOrDefault(s => s.CommandName == parts[1]);

            if (shortcut == null)
            {
                shortcut = new KeyboardShortcut(parts[0], string.Empty);
                KeyboardManager.Shortcuts.Add(shortcut);
            }

            var dialog = new SetShortcutDialog(shortcut, parts[0]);

            if (AppHost.Shell.ShowDialog(dialog) == true)
            {
                KeyboardManager.SaveActiveScheme();
            }
        }
Ejemplo n.º 31
0
 public bool GetKeyboardShortcutDown(KeyboardShortcut shortcut)
 {
     KeyCode[] codes;
     if (!ActiveKeyMap.TryGetValue((int)shortcut, out codes))
     {
         return(false);
     }
     for (int i = 0; i < codes.Length; ++i)
     {
         KeyCode code = codes[i];
         if (Input.GetKeyDown(code))
         {
             return(true);
         }
     }
     return(false);
 }
 private static bool IsDown(KeyboardShortcut value)
 {
     if (Input.GetKeyDown(value.MainKey))
     {
         if (value.Modifiers != null)
         {
             foreach (var mod in value.Modifiers)
             {
                 if (!Input.GetKey(mod))
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 33
0
 /// <summary>
 /// 
 /// </summary>
 private void ResetShortcutButton()
 {
     if (!waitingForShortcut) return;
     waitingForShortcut = false;
     currentShortcutButton.Content = currentShortcut.Keys == "" ? U.T("ShortcutNotUsed") : currentShortcut.Keys;
     currentShortcutButton.FontStyle = currentShortcut.Keys == "" ? FontStyles.Italic : FontStyles.Normal;
     currentShortcut = null;
     currentShortcutButton = null;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ControlPanel_KeyDown(object sender, KeyEventArgs e)
        {
            if (!waitingForShortcut) return;

            switch (e.Key)
            {
                // convert right shift to left shift
                case Key.RightShift:
                    if (!currentPressedKeys.Contains(Key.LeftShift)) currentPressedKeys.Add(Key.LeftShift);
                    currentShortcutButton.Content = ParentWindow.GetModifiersAsText(currentPressedKeys);
                    return;
                // catch modifier keys
                case Key.LeftShift:
                case Key.LeftCtrl:
                case Key.LeftAlt:
                case Key.LWin:
                case Key.RightCtrl:
                case Key.RightAlt:
                case Key.RWin:
                    if (!currentPressedKeys.Contains(e.Key)) currentPressedKeys.Add(e.Key);
                    currentShortcutButton.Content = ParentWindow.GetModifiersAsText(currentPressedKeys);
                    return;

                // catch alt/left ctrl key when disguised as system key
                case Key.System:
                    if (e.SystemKey == Key.LeftAlt || e.SystemKey == Key.RightAlt || e.SystemKey == Key.LeftCtrl)
                    {
                        if (!currentPressedKeys.Contains(e.SystemKey)) currentPressedKeys.Add(e.SystemKey);
                        currentShortcutButton.Content = ParentWindow.GetModifiersAsText(currentPressedKeys);
                        return;
                    }
                    break;

                // ignore these keys
                case Key.None:
                case Key.DeadCharProcessed:
                    return;
                default:
                    break;
            }

            // TODO: Convert Oem keys to nice strings
            String currentKey = e.Key == Key.System ? ParentWindow.KeyToString(e.SystemKey) : ParentWindow.KeyToString(e.Key);
            String txt = ParentWindow.GetModifiersAsText(currentPressedKeys);
            if (txt.Length > 0) txt += "+" + currentKey;
            else txt = currentKey;

            KeyboardShortcutProfile profile = SettingsManager.GetCurrentShortcutProfile();

            // see if shortcut already exists
            bool createdNew = false;
            foreach (KeyboardShortcut sc in profile.Shortcuts)
            {
                if (sc.Keys == txt && sc != currentShortcut)
                {
                    string title = U.T("MessageShortcutClash", "Title");
                    string message = U.T("MessageShortcutClash", "Message");
                    string name = U.T("Shortcut_" + sc.Name.Replace(" ", "_"));
                    string category = U.T("Shortcut" + sc.Category);
                    message = message.Replace("%name", name);
                    message = message.Replace("%category", category);

                    if (MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        // if current profile is protected we create a copy of it
                        KeyboardShortcut _sc = sc;
                        if (profile.IsProtected)
                        {
                            profile = CreateShortcutProfile();
                            currentShortcut = SettingsManager.GetKeyboardShortcut(profile, currentShortcut.Keys);
                            _sc = SettingsManager.GetKeyboardShortcut(profile, sc.Keys);
                            createdNew = true;
                        }

                        Button b = (Button)shortcutButtons[sc.Category + "_" + sc.Name.Replace(" ", "_")];
                        if (b != null)
                        {
                            b.Content = U.T("ShortcutNotUsed");
                            b.FontStyle = FontStyles.Italic;
                        }
                        _sc.Keys = "";
                        break;
                    }
                    else
                    {
                        ResetShortcutButton();
                        e.Handled = true;
                        return;
                    }
                }
            }

            // if current profile is protected we create a copy of it (if we haven't already)
            if (profile.IsProtected && !createdNew)
            {
                profile = CreateShortcutProfile();
                currentShortcut = SettingsManager.GetKeyboardShortcut(profile, currentShortcut.Keys);
            }

            // set shortcut and button text
            currentShortcutButton.FontStyle = FontStyles.Normal;
            waitingForShortcut = false;
            currentShortcutButton.Content = txt;
            if (currentShortcut != null) currentShortcut.Keys = txt;
            currentShortcut = null;
            currentShortcutButton = null;
            e.Handled = true;
        }
Ejemplo n.º 35
0
		public CombinedBox ()
		{
			filterEntry = new SearchEntry ();
			filterEntry.WidthRequest = 180;
			filterEntry.Ready = true;
			filterEntry.ForceFilterButtonVisible = true;
			filterEntry.Entry.CanFocus = true;
			filterEntry.RoundedShape = true;
			filterEntry.HasFrame = true;
			filterEntry.Parent = this;
			filterEntry.Show ();

			SearchKeyShortcut = new KeyboardShortcut (
				Gdk.Key.f, Platform.IsMac? Gdk.ModifierType.MetaMask : Gdk.ModifierType.ControlMask
			);
		}
Ejemplo n.º 36
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="profile"></param>
 /// <param name="category"></param>
 /// <param name="name"></param>
 /// <param name="keysAsText"></param>
 /// <param name="isGlobal"></param>
 private static void SetKeyboardShortcut(KeyboardShortcutProfile profile, String category, String name, String keysAsText, bool isGlobal = false)
 {
     KeyboardShortcut sc = GetKeyboardShortcut(profile, category, name);
     if (sc == null)
     {
         sc = new KeyboardShortcut();
         sc.Category = category;
         sc.Name = name;
         profile.Shortcuts.Add(sc);
     }
     SetKeyboardShortcut(sc, keysAsText, isGlobal);
 }
Ejemplo n.º 37
0
		protected override bool OnKeyPressEvent (EventKey evnt)
		{
			Gdk.Key key;
			Gdk.ModifierType mod;
			KeyboardShortcut[] accels;
			GtkWorkarounds.MapKeys (evnt, out key, out mod, out accels);
			if (initialKey.IsEmpty)
				initialKey = new KeyboardShortcut (key, mod);

			if (accels [0].Key == initialKey.Key) {
				if ((accels [0].Modifier & ModifierType.ShiftMask) == 0)
					NextItem (true);
				else
					PrevItem (true);
			} else {
				switch (accels [0].Key) {
					case Gdk.Key.space:
					case Gdk.Key.KP_Space:
						RightItem (true);
						break;
					case Gdk.Key.Left:
					case Gdk.Key.KP_Left:
						LeftItem ();
						break;
					case Gdk.Key.Right:
					case Gdk.Key.KP_Right:
						RightItem ();
						break;
					case Gdk.Key.Up:
					case Gdk.Key.KP_Up:
						PrevItem (false);
						break;
					case Gdk.Key.Down:
					case Gdk.Key.KP_Down:
						NextItem (false);
						break;
					case Gdk.Key.Tab:
						if ((accels [0].Modifier & ModifierType.ShiftMask) == 0)
							NextItem (true);
						else
							PrevItem (true);
						break;
					case Gdk.Key.Return:
					case Gdk.Key.KP_Enter:
					case Gdk.Key.ISO_Enter:
						OnRequestClose (new RequestActionEventArgs (true));
						break;
					case Gdk.Key.Escape:
						OnRequestClose (new RequestActionEventArgs (false));
					break;
				}
			}
			return base.OnKeyPressEvent (evnt);
		}
Ejemplo n.º 38
0
		protected override bool OnKeyReleaseEvent (Gdk.EventKey evnt)
		{
			if (initialKey.IsEmpty) {
				Gdk.Key key;
				Gdk.ModifierType mod;
				KeyboardShortcut [] accels;
				GtkWorkarounds.MapKeys (evnt, out key, out mod, out accels);
				initialKey = new KeyboardShortcut (key, mod);
			}

			var releaseMods = GtkWorkarounds.KeysForMod (initialKey.Modifier);

			if ((releaseMods.Length == 0 && (evnt.Key == Gdk.Key.Control_L || evnt.Key == Gdk.Key.Control_R)) ||
			    releaseMods.Contains (evnt.Key)) {
				OnRequestClose (new RequestActionEventArgs (true));
			}
			return base.OnKeyReleaseEvent (evnt);
		}
Ejemplo n.º 39
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sc"></param>
 /// <param name="keysAsText"></param>
 /// <param name="isGlobal"></param>
 private static void SetKeyboardShortcut(KeyboardShortcut sc, String keysAsText, bool isGlobal = false)
 {
     sc.Keys = keysAsText;
     sc.IsGlobal = isGlobal;
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Invoked when the user clicks on a shortcut
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        private void PrefShortcutButton_Clicked(object sender, RoutedEventArgs e)
        {
            currentShortcutButton = sender as Button;
            string[] name = currentShortcutButton.Name.Split(new char[] { '_' }, 2);
            currentShortcut = SettingsManager.GetKeyboardShortcut(SettingsManager.GetCurrentShortcutProfile(), name[0], name[1].Replace("_", " "));

            waitingForShortcut = true;
            U.ListenForShortcut = false;
            currentShortcutButton.Content = U.T("ShortcutPress");
            currentShortcutButton.FontStyle = FontStyles.Italic;
            currentPressedKeys.Clear();
        }
Ejemplo n.º 41
0
		public override void SelectValidShortcut (KeyboardShortcut[] accels, out Gdk.Key key, out ModifierType mod)
		{
			foreach (var accel in accels) {
				int keyCode = GetKeyCode (accel.Key, accel.Modifier);
				if (keyBindings.ContainsKey (keyCode)) {
					key = accel.Key;
					mod = accel.Modifier;
					return;
				}
			}
			key = accels [0].Key;
			mod = accels [0].Modifier;
		}
Ejemplo n.º 42
0
		public virtual void SelectValidShortcut (KeyboardShortcut[] accels, out Gdk.Key key, out ModifierType mod)
		{
			key = accels [0].Key;
			mod = accels [0].Modifier;
		}
Ejemplo n.º 43
0
		bool CanUseBinding (KeyboardShortcut[] chords, KeyboardShortcut[] accels, out KeyBinding binding, out bool isChord)
		{
			if (chords != null) {
				foreach (var chord in chords) {
					foreach (var accel in accels) {
						binding = new KeyBinding (chord, accel);
						if (bindings.BindingExists (binding)) {
							isChord = false;
							return true;
						}
					}
				}
			} else {
				foreach (var accel in accels) {
					if (bindings.ChordExists (accel)) {
						// Chords take precedence over bindings with the same shortcut.
						binding = null;
						isChord = true;
						return false;
					}
					
					binding = new KeyBinding (accel);
					if (bindings.BindingExists (binding)) {
						isChord = false;
						return true;
					}
				}
			}
			
			isChord = false;
			binding = null;
			
			return false;
		}
Ejemplo n.º 44
0
        private void UpgradeKeyboardShortcuts()
        {
            Debug.Log("[SRDebugger] Upgrading Settings format");

            var newShortcuts = new List<KeyboardShortcut>();

            for (var i = 0; i < _keyboardShortcuts.Length; i++)
            {
                var s = _keyboardShortcuts[i];

                newShortcuts.Add(new KeyboardShortcut
                {
                    Action = s.Action,
                    Key = s.Key,
                    Alt = _keyboardModifierAlt,
                    Shift = _keyboardModifierShift,
                    Control = _keyboardModifierControl
                });
            }

            _keyboardShortcuts = new KeyboardShortcut[0];
            _newKeyboardShortcuts = newShortcuts.ToArray();

#if UNITY_EDITOR
            EditorUtility.SetDirty(this);
#endif
        }