Exemple #1
0
        public void set_hotkey(string hotkey_string)
        {
            var cvt = new KeysConverter();
            var key = (Keys)cvt.ConvertFrom(hotkey_string);

            ModifierKeys mk = SkipDonation.ModifierKeys.None;

            if (key.HasFlag(Keys.Control))
            {
                mk |= SkipDonation.ModifierKeys.Control;
                key = key & (~Keys.Control);
            }

            if (key.HasFlag(Keys.Alt))
            {
                mk |= SkipDonation.ModifierKeys.Alt;
                key = key & (~Keys.Alt);
            }

            if (key.HasFlag(Keys.Shift))
            {
                mk |= SkipDonation.ModifierKeys.Shift;
                key = key & (~Keys.Shift);
            }

            hook.RegisterHotKey(mk, key);
            lbl_hotkey.Text = hotkey_string;
        }
Exemple #2
0
        public static void ParseShortcut(string text, string separator, out ModifierKeys modifier, out Keys key)
        {
            bool HasAlt = false; bool HasControl = false; bool HasShift = false; bool HasWin = false;

            modifier = ModifierKeys.None; //Variable to contain modifier.
            key      = 0;                 //The key to register.

            string[] result;
            string[] separators = new string[] { separator };
            result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            //Iterate through the keys and find the modifier.
            foreach (string entry in result)
            {
                string keyName = entry.Trim().ToLower();

                //Find the Control Key.
                if (keyName == Keys.Control.ToString().ToLower() || keyName == "ctrl")
                {
                    HasControl = true;
                }
                //Find the Alt key.
                if (keyName == Keys.Alt.ToString().ToLower())
                {
                    HasAlt = true;
                }
                //Find the Shift key.
                if (keyName == Keys.Shift.ToString().ToLower())
                {
                    HasShift = true;
                }
                //Find the Window key.
                if (keyName == Keys.LWin.ToString().ToLower())
                {
                    HasWin = true;
                }
            }

            if (HasControl)
            {
                modifier |= ModifierKeys.Control;
            }
            if (HasAlt)
            {
                modifier |= ModifierKeys.Alt;
            }
            if (HasShift)
            {
                modifier |= ModifierKeys.Shift;
            }
            if (HasWin)
            {
                modifier |= ModifierKeys.Win;
            }

            KeysConverter keyconverter = new KeysConverter();

            key = (Keys)keyconverter.ConvertFrom(result.GetValue(result.Length - 1));
        }
Exemple #3
0
        void UpdateCustomShortcut(string text)
        {
            LogEvents("Attempting to update custom shortcut to: " + text);

            //Will help determine if the shortcut has any modifier.
            bool HasAlt = false; bool HasControl = false; bool HasShift = false;

            Modifiers Modifier = Modifiers.None; //Variable to contain modifier.
            Keys      key      = 0;              //The key to register.

            string[] result;
            string[] separators = new string[] { " + " };
            result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            //Iterate through the keys and find the modifier.
            foreach (string entry in result)
            {
                //Find the Control Key.
                if (entry.Trim() == Keys.Control.ToString())
                {
                    HasControl = true;
                }
                //Find the Alt key.
                if (entry.Trim() == Keys.Alt.ToString())
                {
                    HasAlt = true;
                }
                //Find the Shift key.
                if (entry.Trim() == Keys.Shift.ToString())
                {
                    HasShift = true;
                }
            }

            if (HasControl)
            {
                Modifier |= Modifiers.Control;
            }
            if (HasAlt)
            {
                Modifier |= Modifiers.Alt;
            }
            if (HasShift)
            {
                Modifier |= Modifiers.Shift;
            }

            //Get the last key in the shortcut
            KeysConverter keyconverter = new KeysConverter();

            key = (Keys)keyconverter.ConvertFrom(result.GetValue(result.Length - 1));

            ghkCustom.Enabled  = chkCustomEnabled.Checked;
            ghkCustom.Key      = key;
            ghkCustom.Modifier = Modifier;

            LogEvents(string.Format("Custom shortcut updated. \n Key:{0}, Modifier:{1}", ghkCustom.Key, ghkCustom.Modifier));
        }
Exemple #4
0
        private void CreateKeyList()
        {
            //キーリストの作成
            KeysConverter kc = new KeysConverter();
            Keys          key;


            //AからZまでのキー追加
            for (char c = 'A'; c <= 'Z'; c++)
            {
                key = (Keys)kc.ConvertFrom(c.ToString());
                keyslist.Add(key);
            }

            //Functionキーの追加
            for (int i = 1; i <= 12; i++)
            {
                key = (Keys)kc.ConvertFrom("F" + i);
                keyslist.Add(key);
            }

            //数字キーの追加
            for (int i = 0; i <= 9; i++)
            {
                key = (Keys)kc.ConvertFrom(i.ToString());
                keyslist.Add(key);
            }

            /*
             * keyslist.Add(Keys.Tab);
             * keyslist.Add(Keys.CapsLock);
             * keyslist.Add(Keys.Enter);
             * keyslist.Add(Keys.Back);
             * keyslist.Add(Keys.Insert);
             * keyslist.Add(Keys.Delete);
             * keyslist.Add(Keys.Home);
             * keyslist.Add(Keys.End);
             * keyslist.Add(Keys.PageUp);
             * keyslist.Add(Keys.PageDown);
             * keyslist.Add(Keys.PrintScreen);
             * keyslist.Add(Keys.Scroll);
             *
             * keyslist.Sort();
             */
        }
Exemple #5
0
 private bool LyricCommandKey(BmpChatListener.Command cmd)
 {
     if (!string.IsNullOrEmpty(cmd.param))
     {
         KeysConverter kc  = new KeysConverter();
         Keys          key = (Keys)kc.ConvertFrom(cmd.param);
         FFXIV.hook.SendSyncKey(key);
     }
     return(true);
 }
        public PWBrowserKeyDownEventArgs(XDocument xMsg)
            : base(xMsg)
        {
            KeysConverter kc = new KeysConverter();

            KeyCode = (Keys)kc.ConvertFrom(xMsg.Descendants().Elements("keyCode").First().Value.ToString());
            Char    = kc.ConvertToString(KeyCode);

            ICtrlKey   = bool.Parse(xMsg.Descendants().Elements("ctrlKey").First().Value.ToString());
            IsShiftKey = bool.Parse(xMsg.Descendants().Elements("shiftKey").First().Value.ToString());
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return("");
            }

            var kc      = new KeysConverter();
            var keyCode = kc.ConvertFrom(value);

            return(keyCode);
        }
Exemple #8
0
        /// <summary>
        /// Registers the assign or remove hotkey for the specified category resource.
        /// </summary>
        private static void RegisterCategoryHotkey(IResource category, int propId, bool isAssign, Hashtable actions)
        {
            string hotkey = category.GetStringProp(propId);

            if (hotkey != null)
            {
                KeysConverter converter = new KeysConverter();
                Keys          key       = (Keys)converter.ConvertFrom(hotkey);
                IAction       action    = new CategoryAction(category, isAssign);
                Core.ActionManager.RegisterKeyboardAction(action, key, null, null);
                actions [category.Id] = action;
            }
        }
Exemple #9
0
        public Form1()
        {
            InitializeComponent();

            var keysConverter = new KeysConverter();

            foreach (var i in Controls)
            {
                if (i is Button)
                {
                    // Mặc định i là dạng Control vì vậy ta cần ép kiểu i về Button để dễ xử lý hơn
                    var button = i as Button;
                    // Thêm (Key, Value) vào Dictionary
                    KeysDict.Add((Keys)keysConverter.ConvertFrom(button.Text), button);
                }
            }
        }
Exemple #10
0
        private void LoadHotKey()
        {
            KeysConverter kc = new KeysConverter();

#if DEBUG
            Console.WriteLine("LoadHotKey");
            Console.WriteLine("RunModKeys:{0}", Properties.HotKey.Default.RunModKey);
            Console.WriteLine("RunKeys:{0}", Properties.HotKey.Default.RunKeys);
#endif

            uint   modkey = Properties.HotKey.Default.RunModKey;
            string runkey = Properties.HotKey.Default.RunKeys;

            if ((modkey != 0) && (runkey != "") && (runkey != null))
            {
                txtRunSetting.Text   = HotKey.GetHotkeyMessage(modkey, (Keys)kc.ConvertFrom(runkey));
                chkRunEnable.Enabled = true;
            }
            else
            {
                txtRunSetting.Text   = "設定なし";
                chkRunEnable.Enabled = false;
            }

#if DEBUG
            Console.WriteLine("RunNowModKeys:{0}", Properties.HotKey.Default.RunNowModKey);
            Console.WriteLine("RunNowKeys:{0}", Properties.HotKey.Default.RunNowKeys);
#endif

            modkey = Properties.HotKey.Default.RunNowModKey;
            runkey = Properties.HotKey.Default.RunNowKeys;

            if ((modkey != 0) && (runkey != "") && (runkey != null))
            {
                txtRunNowSetting.Text   = HotKey.GetHotkeyMessage(Properties.HotKey.Default.RunNowModKey, (Keys)kc.ConvertFrom(Properties.HotKey.Default.RunNowKeys));
                chkRunNowEnable.Enabled = true;
            }
            else
            {
                txtRunNowSetting.Text   = "設定なし";
                chkRunNowEnable.Enabled = false;
            }
        }
Exemple #11
0
        /// <summary>
        /// フォームの初期化用メソッド
        /// </summary>
        private void Initialize()
        {
            this.ShowInTaskbar = false;
            this.ControlBox    = false;

            this.AcceptButton = btnOK;
            this.CancelButton = btnCancel;

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximumSize     = this.Size;

            //コンボボックスの設定
            cmbKeys.DropDownStyle = ComboBoxStyle.DropDownList;
            cmbKeys.Enabled       = false;
            cmbKeys.BackColor     = Color.White;

            //ボタンの設定
            //btnOK.Enabled = false;


            //キーリストの作成
            KeysConverter kc = new KeysConverter();
            Keys          key;


            //AからZまでのキー追加
            for (char c = 'A'; c <= 'Z'; c++)
            {
                key = (Keys)kc.ConvertFrom(c.ToString());
                keyslist.Add(key);
            }

            //Functionキーの追加
            for (int i = 1; i <= 12; i++)
            {
                key = (Keys)kc.ConvertFrom("F" + i);
                keyslist.Add(key);
            }

            //数字キーの追加
            for (int i = 0; i <= 9; i++)
            {
                key = (Keys)kc.ConvertFrom(i.ToString());
                keyslist.Add(key);
            }

            /*	追加で使えそうなキーのリスト
             * keyslist.Add(Keys.Tab);
             * keyslist.Add(Keys.CapsLock);
             * keyslist.Add(Keys.Enter);
             * keyslist.Add(Keys.Back);
             * keyslist.Add(Keys.Insert);
             * keyslist.Add(Keys.Delete);
             * keyslist.Add(Keys.Home);
             * keyslist.Add(Keys.End);
             * keyslist.Add(Keys.PageUp);
             * keyslist.Add(Keys.PageDown);
             * keyslist.Add(Keys.PrintScreen);
             * keyslist.Add(Keys.Scroll);
             *
             * keyslist.Sort();
             */

            if (hotkey.ModKey != ModKeys.None)
            {
                ReverseConfig();
            }

            //イベントハンドラの登録
            chkAlt.Click   += new EventHandler(checkBox_Click);
            chkCtrl.Click  += new EventHandler(checkBox_Click);
            chkShift.Click += new EventHandler(checkBox_Click);
            chkWin.Click   += new EventHandler(checkBox_Click);

            btnOK.Click     += new EventHandler(btnOK_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);
        }
Exemple #12
0
        /// <summary>Parses a shortcut string like 'Control + Alt + Shift + V' and returns the key and modifiers.
        /// </summary>
        /// <param name="text">The shortcut string to parse.</param>
        /// <returns>The Modifier in the lower bound and the key in the upper bound.</returns>
        public static object[] ParseShortcut(string text)
        {
            var hasAlt     = false;
            var hasControl = false;
            var hasShift   = false;
            var hasWin     = false;

            var  modifier = HotKey.ModifierKeys.None; //Variable to contain modifier.
            Keys key      = 0;                        //The key to register.
            int  current  = 0;

            string[] result;
            var      separators = new[] { " + " };

            result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            //Iterate through the keys and find the modifier.
            foreach (string entry in result)
            {
                //Find the Control Key.
                if (entry.Trim() == Keys.Control.ToString())
                {
                    hasControl = true;
                }

                //Find the Alt key.
                if (entry.Trim() == Keys.Alt.ToString())
                {
                    hasAlt = true;
                }

                //Find the Shift key.
                if (entry.Trim() == Keys.Shift.ToString())
                {
                    hasShift = true;
                }

                if (entry.Trim() == "Win")
                {
                    hasWin = true;
                }

                //Find the Window key.
                if (entry.Trim() == Keys.LWin.ToString() && current != result.Length - 1)
                {
                    hasWin = true;
                }

                //Find the Window key.
                if (entry.Trim() == Keys.RWin.ToString() && current != result.Length - 1)
                {
                    hasWin = true;
                }

                current++;
            }

            if (hasControl)
            {
                modifier |= HotKey.ModifierKeys.Control;
            }

            if (hasAlt)
            {
                modifier |= HotKey.ModifierKeys.Alt;
            }

            if (hasShift)
            {
                modifier |= HotKey.ModifierKeys.Shift;
            }

            if (hasWin)
            {
                modifier |= HotKey.ModifierKeys.Win;
            }

            var keysConverter = new KeysConverter();

            key = (Keys)keysConverter.ConvertFrom(result.GetValue(result.Length - 1));

            return(new object[] { modifier, key });
        }
Exemple #13
0
        private void RegisterHotkey()
        {
            uint   modkey;
            string key;

            string mes = "";

            KeysConverter kc = new KeysConverter();


            if (Properties.HotKey.Default.isRunHotKey)
            {
                modkey = Properties.HotKey.Default.RunModKey;
                key    = Properties.HotKey.Default.RunKeys;

                if ((modkey == 0) || (key == "") || (key == null))
                {
#if DEBUG
                    Console.WriteLine("RunHotKey登録失敗");
#endif
                }
                else
                {
                    HotKey runHotKey = new HotKey(this.GetHashCode().ToString(), this.Handle, modkey, (Keys)kc.ConvertFrom(key));
                    mes           += String.Format("通常実行ホットキー:{0}\n", runHotKey.HotkeyString);
                    runHotKey.Name = "Run";
                    hotkeylist.Add(runHotKey);
                }
            }

            if (Properties.HotKey.Default.isRunNowHotKey)
            {
                modkey = Properties.HotKey.Default.RunNowModKey;
                key    = Properties.HotKey.Default.RunNowKeys;

                if ((modkey == 0) || (key == "") || (key == null))
                {
#if DEBUG
                    Console.WriteLine("RunNowHotKey登録失敗");
#endif
                }
                else
                {
                    HotKey runNowHotKey = new HotKey(this.GetHashCode().ToString(), this.Handle, modkey, (Keys)kc.ConvertFrom(key));
                    mes += String.Format("今すぐ実行ホットキー:{0}", runNowHotKey.HotkeyString);
                    runNowHotKey.Name = "RunNow";
                    hotkeylist.Add(runNowHotKey);
                }
            }

            if (mes != "")
            {
                noIcon.ShowBalloonTip(3000, "ホットキー登録完了", mes, ToolTipIcon.Info);
                noIcon.Text = "DisplayPowerOff\n" + mes;
            }
        }
Exemple #14
0
        // ###########################################################################################
        // Catch keyboard input to react on modifier KEY UP
        // ###########################################################################################

        private void History_KeyUp(object sender, KeyEventArgs e)
        {
            // Check if modifier keys are pressed
            bool isShift   = e.Shift;
            bool isAlt     = e.Alt;
            bool isControl = e.Control;

            // Proceed if no modifier keys are pressed down - this equals that we have selected the entry
            if (!isShift && !isAlt && !isControl)
            {
                // Insert log depending if list is empty or not
                if (entriesInList == 0)
                {
                    if (Settings.isTroubleshootEnabled)
                    {
                        Logging.Log("Selected history entry element [none, as list is empty]");
                    }
                }
                else
                {
                    if (Settings.isTroubleshootEnabled)
                    {
                        Logging.Log("Selected history entry list element [" + entryActiveList + "] of [" + entriesInList + "] with key [" + entryActive + "]");
                    }
                }

                // Reset some stuff
                Settings.entryIndex = entryActive; // set the new "entryIndex" variable as it is now selected
                ResetVariables();

                Settings.settings.SelectHistoryEntry();
                if (Settings.isEnabledPasteOnSelection)
                {
                    SendKeys.Send("^v");
                }

                // Show the "Settings" form again, if it was visible before the hotkey keypress
                if (Settings.isSettingsFormVisible)
                {
                    Settings.settings.Show();
                }

                ResetForm();
            }
            else
            {
                // Check for other key combinations

                // For conversion from text to keys
                KeysConverter cvt = new KeysConverter();
                Keys          key;

                // Proceed if we should toggle the list view
                string hotkey6 = Settings.GetRegistryKey(Settings.registryPath, "Hotkey6");
                if (Settings.isEnabledFavorites && hotkey6 != "Not set")
                {
                    key = (Keys)cvt.ConvertFrom(hotkey6);
                    if (e.KeyCode == key)
                    {
                        if (Settings.showFavoriteList)
                        {
                            Settings.showFavoriteList = false;
                            if (Settings.isTroubleshootEnabled)
                            {
                                Logging.Log("History list changed to [All]");
                            }
                        }
                        else
                        {
                            Settings.showFavoriteList = true;
                            if (Settings.isTroubleshootEnabled)
                            {
                                Logging.Log("History list changed to [Favorite]");
                            }
                        }

                        // Reset some stuff
                        ResetVariables();
                        ResetForm();
                        SetupForm();
                        UpdateHistory("down");
                    }
                }

                // Proceed if we should toggle a favorite entry
                string hotkey5 = Settings.GetRegistryKey(Settings.registryPath, "Hotkey5");
                if (Settings.isEnabledFavorites && hotkey5 != "Not set")
                {
                    key = (Keys)cvt.ConvertFrom(hotkey5);
                    if (e.KeyCode == key)
                    {
                        // Only relevant when we are in the "favorite" view
                        bool isFavoriteEmpty = false;
                        foreach (Control c in this.Controls.Find("uiNoFavorites", true))
                        {
                            isFavoriteEmpty = true; // if this label exists then we know the favorite is empty
                        }

                        // Proceed if there is at least one entry in the favorite list
                        if (!Settings.showFavoriteList || !isFavoriteEmpty)
                        {
                            // Procced if the entry already is marked as a favorite
                            if (Settings.entriesIsFavorite[entryActive])
                            {
                                Settings.entriesIsFavorite[entryActive] = false;
                                foreach (Control c in this.Controls.Find("historyPictureBoxFav" + entryActiveList, true))
                                {
                                    c.Visible = false;
                                }
                                if (Settings.isTroubleshootEnabled)
                                {
                                    Logging.Log("History favorite toggled [Off] on entry key [" + entryActive + "]");
                                }
                            }
                            else
                            {
                                // Get the background color for the active entry (this is either a "label" or a "pictureBox")
                                Color favoriteBackgroundColor = Color.Red;
                                foreach (Control c in this.Controls.Find("historyLabel" + entryActiveList, true))
                                {
                                    if (c.Visible)
                                    {
                                        favoriteBackgroundColor = c.BackColor;
                                    }
                                }
                                foreach (Control c in this.Controls.Find("historyPictureBox" + entryActiveList, true))
                                {
                                    if (c.Visible)
                                    {
                                        favoriteBackgroundColor = c.BackColor;
                                    }
                                }

                                // Show the entry with a favorite marking
                                Settings.entriesIsFavorite[entryActive] = true;
                                foreach (Control c in this.Controls.Find("historyPictureBoxFav" + entryActiveList, true))
                                {
                                    c.BackColor = favoriteBackgroundColor;
                                    c.BringToFront();
                                    c.Visible = true;
                                }
                                if (Settings.isTroubleshootEnabled)
                                {
                                    Logging.Log("History favorite toggled [On] on entry key [" + entryActive + "]");
                                }
                            }

                            if (Settings.showFavoriteList)
                            {
                                // Reset some stuff
                                ResetVariables();
                                ResetForm();
                                SetupForm();
                                UpdateHistory("down");
                            }
                        }
                    }
                }
            }
        }