Beispiel #1
0
        private string GetGestureString()
        {
            if (ShortcutKey == AlephKey.None)
            {
                return("None");
            }
            if (ShortcutModifiers == AlephModifierKeys.None)
            {
                return(ShortcutKey.ToString());
            }

            List <string> elements = new List <string>(4);

            if (ShortcutModifiers.HasFlag(AlephModifierKeys.Control))
            {
                elements.Add("Ctrl");
            }
            if (ShortcutModifiers.HasFlag(AlephModifierKeys.Alt))
            {
                elements.Add("Alt");
            }
            if (ShortcutModifiers.HasFlag(AlephModifierKeys.Shift))
            {
                elements.Add("Shift");
            }
            if (ShortcutModifiers.HasFlag(AlephModifierKeys.Windows))
            {
                elements.Add("Win");
            }
            elements.Add(ShortcutKey.ToString());

            return(string.Join(" + ", elements));
        }
Beispiel #2
0
        public ShortcutKeyPicker(string title, ShortcutKey shortcutKey)
        {
            this._oldShortcutKey = shortcutKey;

            chkUseAlt.CheckedBinding.Bind(shortcutKey, s => s.UseAlt);
            chkUseControl.CheckedBinding.Bind(shortcutKey, s => s.UseControl);
            txtShortcutKey.TextBinding.Bind(shortcutKey, s => s.Key);

            txtShortcutKey.KeyDown += TxtShortcutKey_KeyDown;

            this.Add(new Label()
            {
                Text = title
            });
            this.Add(new Label()
            {
                Text = "Control"
            });
            this.Add(chkUseControl);
            this.Add(new Label()
            {
                Text = "Alt"
            });
            this.Add(chkUseAlt);
            this.Add(new Label()
            {
                Text = "Shortcut Key"
            });
            this.Add(txtShortcutKey);
            this.Add(new Label());
        }
Beispiel #3
0
        public ShortcutKey[] GetConflictedKeys(Keys prefix, Keys key)
        {
            var ret = new List <ShortcutKey>();

            var bothKey = new ShortcutKey(prefix, key);

            if (_keyToId.ContainsKey(bothKey))
            {
                ret.Add(bothKey);
            }

            if (prefix == Keys.None)
            {
                var prefixKey = new ShortcutKey(key, Keys.KeyCode);
                foreach (var k in _keyToId.Keys)
                {
                    if (k.Prefix == key)
                    {
                        ret.Add(k);
                    }
                }
            }
            else
            {
                var keyKey = new ShortcutKey(Keys.None, prefix);
                if (_keyToId.ContainsKey(keyKey))
                {
                    ret.Add(keyKey);
                }
            }

            return(ret.ToArray());
        }
 private async void GlobalEventService_KeyUpEvent(object sender, KeyboardInfo e)
 {
     if (ShortcutKey.HasValue && ShortcutKey.IsMatch(e.Key, e.AltKey, e.CtrlKey, e.ShiftKey))
     {
         await InvokeAsync(async() => await Click.InvokeAsync(new MouseEventArgs()).ConfigureAwait(true)).ConfigureAwait(true);
     }
 }
Beispiel #5
0
        public ShortcutKeyPicker(string title, ShortcutKey shortcutKey)
        {
            this._oldShortcutKey = shortcutKey;

            chkUseAlt.CheckedBinding.Bind(shortcutKey, s => s.UseAlt);
            chkUseControl.CheckedBinding.Bind(shortcutKey, s => s.UseControl);
            txtShortcutKey.TextBinding.Bind(shortcutKey, s => s.Key);

            txtShortcutKey.KeyDown += TxtShortcutKey_KeyDown;

            Cells = new System.Collections.ObjectModel.Collection <TableCell>();
            Cells.Add(new Label()
            {
                Text = title
            });
            Cells.Add(new Label()
            {
                Text = "Control"
            });
            Cells.Add(chkUseControl);
            Cells.Add(new Label()
            {
                Text = "Alt"
            });
            Cells.Add(chkUseAlt);
            Cells.Add(new Label()
            {
                Text = "Shortcut Key"
            });
            Cells.Add(txtShortcutKey);
            Cells.Add(new Label());
        }
Beispiel #6
0
 /// <summary>
 /// アクションを登録します。
 /// </summary>
 /// <param name="shortcutKey">登録するショートカットキー</param>
 /// <param name="action">登録するアクション</param>
 /// <param name="name">登録するショートカット名</param>
 /// <returns>登録成功の場合は空文字、登録失敗の場合はエラー文字列</returns>
 private string RegisterAction(ShortcutKey shortcutKey, Action action, string name)
 {
     if (!this.application.HookService.Register(shortcutKey, action))
     {
         return($"{name} {shortcutKey.ToString()}\n");
     }
     return("");
 }
 /// <summary>
 /// Appends the shortcut keys to the given text.
 /// </summary>
 /// <param name="text">The text to be appended.</param>
 /// <param name="shortcutKey">The shortcut key combination.</param>
 /// <returns>A new string contain the given text with the shortcut text appended.</returns>
 public static string AppendShortcut(this string text, ShortcutKey shortcutKey)
 {
     if (string.IsNullOrEmpty(text) || !shortcutKey.HasValue)
     {
         return(text);
     }
     return($"{text.Replace("&&", "")} ({shortcutKey})");
 }
Beispiel #8
0
        private static Keys GetEtoShortcut(ShortcutKey key)
        {
            Keys mainKey = Keys.None;

            Enum.TryParse <Keys>(key.Key, out mainKey);
            Keys alt     = key.UseAlt ? Application.Instance.AlternateModifier : Keys.None;
            Keys control = key.UseControl ? Application.Instance.CommonModifier : Keys.None;

            return(alt | control | mainKey);
        }
Beispiel #9
0
        public MenuItem(AppliMenu menuToRegisterTo, string name, Image img, Action action, string itemId, string defaultKey, List <MenuItem> children)
        {
            ItemName  = name;
            ItemImage = img;

            // children?
            if (children != null)
            {
                ChildrenList = children;
                Children     = children.Select(item => (YamuiMenuItem)item).ToList();
            }

            // shortcut?
            if (!string.IsNullOrEmpty(itemId))
            {
                ItemId   = itemId;
                ItemSpec = defaultKey;

                if (Config.Instance.ShortCuts.ContainsKey(ItemId))
                {
                    ItemSpec = Config.Instance.ShortCuts[ItemId];
                    Config.Instance.ShortCuts.Remove(ItemId);
                }

                if (!string.IsNullOrEmpty(ItemSpec))
                {
                    Config.Instance.ShortCuts.Add(ItemId, ItemSpec);
                    Shortcut = new ShortcutKey(ItemSpec);
                    SubText  = ItemSpec;
                }

                // we set up a list of items to use in the shortcut page
                if (menuToRegisterTo != null)
                {
                    menuToRegisterTo.ShortcutableItemList.Add(this);
                }
            }

            // action?
            if (action != null)
            {
                OnClic = action;
                // We set the Do() action, which is the "go through" action when the OnClic action is activated
                Do = () => {
                    if (OnClic != null)
                    {
                        try {
                            OnClic();
                        } catch (Exception e) {
                            ErrorHandler.ShowErrors(e, "Error in : " + ItemName);
                        }
                    }
                };
            }
        }
 internal static void SetCommand(int index, string commandName, NppFuncItemDelegate functionPointer, ShortcutKey shortcut, bool checkOnInit)
 {
     FuncItem funcItem = new FuncItem();
     funcItem._cmdID = index;
     funcItem._itemName = commandName;
     if (functionPointer != null)
         funcItem._pFunc = new NppFuncItemDelegate(functionPointer);
     if (shortcut._key != 0)
         funcItem._pShKey = shortcut;
     funcItem._init2Check = checkOnInit;
     _funcItems.Add(funcItem);
 }
Beispiel #11
0
 private void MenuClear_Click(object sender, System.EventArgs e)
 {
     foreach (ListViewItem lvi in listView1.SelectedItems)
     {
         if (lvi.Tag is ShortcutKey)
         {
             ShortcutKey key = (ShortcutKey)lvi.Tag;
             TryChange(key, Keys.None);
             lvi.SubItems[1].Text = string.Empty;
         }
     }
 }
Beispiel #12
0
 private void MenuReset_Click(object sender, System.EventArgs e)
 {
     foreach (ListViewItem lvi in listView1.SelectedItems)
     {
         if (lvi.Tag is ShortcutKey)
         {
             ShortcutKey key = (ShortcutKey)lvi.Tag;
             TryChange(key, key.DefaultKeys);
             lvi.SubItems[1].Text = ST.ToString(key.DefaultKeys);
         }
     }
 }
Beispiel #13
0
        internal static bool CompareShortcuts(KeyEventArgs e, ShortcutKey configuredShortcutKey)
        {
            if (configuredShortcutKey == null || string.IsNullOrWhiteSpace(configuredShortcutKey.Key))
            {
                return(false);
            }
            bool matching = true;

            matching &= e.Control == configuredShortcutKey.UseControl;
            matching &= e.Alt == configuredShortcutKey.UseAlt;
            matching &= e.Key.ToString() == configuredShortcutKey.Key;
            return(matching);
        }
Beispiel #14
0
        public string GetActionId(ShortcutKey key)
        {
            var ret = default(string);

            if (_keyToId.TryGetValue(key, out ret))
            {
                return(ret);
            }
            else
            {
                return(null);
            }
        }
Beispiel #15
0
        /// <summary>
        /// 仮想キー配列をショートカットキーに変換します。
        /// </summary>
        /// <param name="keyCodes">仮想キー配列</param>
        /// <returns>ショートカットキー</returns>
        public static ShortcutKey ToShortcutKey(this int[] keyCodes)
        {
            if (keyCodes == null)
            {
                return(ShortcutKey.None);
            }

            var key          = keyCodes.Length >= 1 ? (Key)keyCodes[0] : Key.None;
            var modifierKeys = keyCodes.Length >= 2 ? (ModifierKeys)keyCodes[1] : ModifierKeys.None;
            var result       = new ShortcutKey(key, modifierKeys);

            return(result);
        }
Beispiel #16
0
        static void AddInternalShortcuts(string shortcutSpec, string displayName, Action handler, Dictionary <Keys, int> uniqueKeys)
        {
            ShortcutKey shortcut = shortcutSpec.ParseAsShortcutKey(displayName);

            internalShortcuts.Add(shortcut, new Tuple <string, Action>(displayName, handler));

            var key = (Keys)shortcut._key;

            if (!uniqueKeys.ContainsKey(key))
            {
                uniqueKeys.Add(key, 0);
            }
        }
        public static ShortcutKey ToShortcutKey(this int[] keyCodes)
        {
            if (keyCodes == null)
            {
                return(ShortcutKey.None);
            }

            var key       = keyCodes.Length >= 1 ? (VirtualKey)keyCodes[0] : VirtualKey.None;
            var modifiers = keyCodes.Length >= 2 ? keyCodes.Skip(1).Select(x => (VirtualKey)x).ToArray() : Array.Empty <VirtualKey>();
            var result    = new ShortcutKey(key, modifiers);

            return(result);
        }
        public static int[] ToSerializable(this ShortcutKey shortcutKey)
        {
            if (shortcutKey.Key == VirtualKey.None)
            {
                return(Array.Empty <int>());
            }

            var key = new[] { (int)shortcutKey.Key, };

            return(shortcutKey.Modifiers.Length == 0
                                ? key
                                : key.Concat(shortcutKey.Modifiers.Select(x => (int)x)).ToArray());
        }
Beispiel #19
0
        /// <summary>
        /// ショートカットキーを仮想キー配列に変換します。
        /// </summary>
        /// <param name="shortcutKey">ショートカットキー</param>
        /// <returns>仮想キー配列</returns>
        public static int[] ToSerializable(this ShortcutKey shortcutKey)
        {
            if (shortcutKey.Key == Key.None)
            {
                return(Array.Empty <int>());
            }

            var key = new[] { (int)shortcutKey.Key, };

            return(shortcutKey.ModifierKeys == ModifierKeys.None
                ? key
                : key.Concat(new int[] { (int)shortcutKey.ModifierKeys }).ToArray());
        }
Beispiel #20
0
 private void MenuModify_Click(object sender, System.EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         ShortcutKey           key    = (ShortcutKey)listView1.SelectedItems[0].Tag;
         ModifyShortcutsDialog dialog = new ModifyShortcutsDialog();
         dialog.ShortcutKeys = key;
         if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             TryChange(key, dialog.NewValue);
             listView1.SelectedItems[0].SubItems[1].Text = ST.ToString(dialog.NewValue);
         }
     }
 }
        public static void SetCommand(int index, string commandName, Action functionPointer, string shortcutSpec)
        {
            ShortcutKey shortcutKey;

            if (string.IsNullOrEmpty(shortcutSpec))
            {
                shortcutKey = new ShortcutKey(false, false, false, Keys.None);
            }
            else
            {
                shortcutKey = shortcutSpec.ParseAsShortcutKey(commandName);
            }

            SetCommand(index, commandName, functionPointer, shortcutKey, false);
        }
Beispiel #22
0
        // public static void SetCommand(int index, string commandName, Action functionPointer, ShortcutKey shortcut)
        // {
        //     SetCommand(index, commandName, functionPointer, shortcut, false);
        // }

        public static void SetCommand(int index, string commandName, Action functionPointer, string shortcutSpec)
        {
            ShortcutKey shortcutKey;

            if (string.IsNullOrEmpty(shortcutSpec))
            {
                shortcutKey = new ShortcutKey(false, false, false, Keys.None);
            }
            else
            {
                shortcutKey = shortcutSpec.ParseAsShortcutKey(commandName);
            }

            PluginBase.SetCommand(index, commandName, new NppFuncItemDelegate(functionPointer), shortcutKey, false);
        }
Beispiel #23
0
        private void TryChange(ShortcutKey key, Keys keys)
        {
            if (key.Keys == keys)
            {
                if (Changes.ContainsKey(key.Name))
                {
                    Changes.Remove(key.Name);
                }
            }
            else
            {
                Changes[key.Name] = keys;
            }

            BtnReset.Enabled = Changes.Count > 0;
            OKButton.Enabled = Changes.Count > 0;
        }
Beispiel #24
0
        public MenuItem(AppliMenu menuToRegisterTo, string name, Image img, Action <YamuiMenuItem> action, string itemId, string defaultKey, List <MenuItem> children)
        {
            DisplayText = name;
            ItemImage   = img;

            // children?
            if (children != null)
            {
                ChildrenList = children;
                Children     = children.Cast <FilteredTypeTreeListItem>().ToList();
            }

            // shortcut?
            if (!string.IsNullOrEmpty(itemId))
            {
                ItemId   = itemId;
                ItemSpec = defaultKey;

                if (Config.Instance.ShortCuts.ContainsKey(ItemId))
                {
                    ItemSpec = Config.Instance.ShortCuts[ItemId];
                    Config.Instance.ShortCuts.Remove(ItemId);
                }

                Config.Instance.ShortCuts.Add(ItemId, ItemSpec);

                if (!string.IsNullOrEmpty(ItemSpec))
                {
                    Shortcut = new ShortcutKey(ItemSpec);
                    SubText  = ItemSpec;
                }

                // we set up a list of items to use in the shortcut page
                if (menuToRegisterTo != null)
                {
                    menuToRegisterTo.ShortcutableItemList.Add(this);
                }
            }

            // action?
            OnClic = action;

            // default is not expanded
            IsExpanded = false;
        }
Beispiel #25
0
        internal static void SetCommand(int index, string commandName, NppFuncItemDelegate functionPointer,
                                        ShortcutKey shortcut, bool checkOnInit)
        {
            FuncItem funcItem = new FuncItem();

            funcItem._cmdID    = index;
            funcItem._itemName = commandName;
            if (functionPointer != null)
            {
                funcItem._pFunc = new NppFuncItemDelegate(functionPointer);
            }
            if (shortcut._key != 0)
            {
                funcItem._pShKey = shortcut;
            }
            funcItem._init2Check = checkOnInit;
            _funcItems.Add(funcItem);
        }
Beispiel #26
0
        /// <summary>
        /// HotKeyを登録します。
        /// </summary>
        /// <param name="shortcutKey">ショートカットキー</param>
        /// <param name="action">アクション</param>
        /// <returns>成功の場合はtrue、それ以外はfalseを返します。</returns>
        public bool Register(ShortcutKey shortcutKey, Action action)
        {
            var modifier = (int)shortcutKey.ModifierKeys;
            var trigger  = (int)shortcutKey.Key.ToVirtualKey();

            // HotKey登録時に指定するIDを決定する
            // 0x0000~0xbfff はIDとして使用可能
            if (this.nextHotkeyId < HotkeyIdMax && User32.RegisterHotKey(this.windowHandle, this.nextHotkeyId, modifier, trigger))
            {
                this.hotkeyActions.Add(this.nextHotkeyId, action);
                nextHotkeyId++;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #27
0
 // Start is called before the first frame update
 void Start()
 {
     player = PlayerData.GetInstance();
     tile   = TileManager.GetInstance();
     field  = FieldManager.GetInstance();
     map    = MapEventManager.GetInstance();
     time   = TimeManager.GetInstance();
     view   = new HeaderDataView();
     sl     = new SaveAndLoad();
     pm     = GetComponent <ParticleMaker>();
     tile.Start();
     field.Start();
     map.Start();
     time.Start();
     player.Start();
     key = GetComponent <ShortcutKey>();
     //sl.Save(0, new SaveData());
 }
Beispiel #28
0
        public static Command GetCommand(string title, Image Icon = null, ShortcutKey Keys = null, object Tag = null)
        {
            var command = new Command();

            command.MenuText = title;
            if (Icon != null)
            {
                command.Image = Icon;
            }
            if (Keys != null && !string.IsNullOrWhiteSpace(Keys.Key))
            {
                command.Shortcut = GetEtoShortcut(Keys);
            }
            if (Tag != null)
            {
                command.Tag = Tag;
            }
            return(command);
        }
 public bool IsDefaultRight(ShortcutKey key)
 {
     if (key.Key != VirtualKey.Right)
     {
         return(false);
     }
     if (key.ModifiersInternal == null || key.ModifiersInternal.Count != 2)
     {
         return(false);
     }
     if (key.ModifiersInternal.Contains(VirtualKey.RControlKey) || key.ModifiersInternal.Contains(VirtualKey.LControlKey))
     {
         if (key.ModifiersInternal.Contains(VirtualKey.LWin) || key.ModifiersInternal.Contains(VirtualKey.RWin))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #30
0
        protected virtual ToggleToolButton CreateToolButton()
        {
            Gtk.Image i2 = new Gtk.Image(PintaCore.Resources.GetIcon(Icon));
            i2.Show();

            ToggleToolButton tool_item = new ToggleToolButton();

            tool_item.IconWidget = i2;
            tool_item.Show();
            tool_item.Label = Name;

            if (ShortcutKey != (Gdk.Key) 0)
            {
                tool_item.TooltipText = string.Format("{0}\n{2}: {1}\n\n{3}", Name, ShortcutKey.ToString().ToUpperInvariant(), Catalog.GetString("Shortcut key"), StatusBarText);
            }
            else
            {
                tool_item.TooltipText = Name;
            }

            return(tool_item);
        }
Beispiel #31
0
        protected void SetShortcut(TextBox txt, KeyEventArgs e)
        {
            e.SuppressKeyPress = true;
            txt.Text           = "";
            keyIsSet           = false;
            if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Tab)
            {
                return;
            }

            if (e.Modifiers != Keys.None)
            {
                foreach (string modifier in e.Modifiers.ToString().Split(','))
                {
                    txt.Text += modifier + " + ";
                }
            }

            if (e.KeyCode == Keys.ShiftKey | e.KeyCode == Keys.ControlKey | e.KeyCode == Keys.Menu)
            {
                keyIsSet = false;
            }
            else
            {
                string code   = e.KeyCode.ToString();
                bool   isfind = ShortcutKey.GetSingleInstance().FindKeys(e.KeyCode, out code);
                if (isfind)
                {
                    txt.Text += code.ToUpper().Trim();
                    keyIsSet  = true;
                }
                else
                {
                    MessageBox.Show("该热键不支持!");
                }
            }

            txt.SelectionStart = txt.TextLength;
        }
Beispiel #32
0
            private static Command GetCommand(string name, string title, ShortcutKey shortcutKey)
            {
                var command = Command.Register(name);

                command.Title = title;
                command.ShortcutKey = shortcutKey;

                return command;
            }
 /// <summary>
 /// Set macro associated with a keyboard shortcut
 /// </summary>
 /// <param name="key"></param>
 /// <param name="macro"></param>
 public static void SetMacro(ShortcutKey key, string macro)
 {
   UnsafeNativeMethods.CRhinoAppShortcutKeys_SetMacro((int)key, macro);
 }
 /// <summary>
 /// Get macro associated with a given keyboard shortcut
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static string GetMacro(ShortcutKey key)
 {
   using (Rhino.Runtime.StringHolder sh = new Runtime.StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.CRhinoAppShortcutKeys_Macro((int)key, pString);
     return sh.ToString();
   }
 }
 public ShortcutKeyPressedEventArgs(ShortcutKey shortcutKey)
 {
     this.ShortcutKey = shortcutKey;
 }
 internal static void SetCommand(int index, string commandName, NppFuncItemDelegate functionPointer, ShortcutKey shortcut)
 {
     SetCommand(index, commandName, functionPointer, shortcut, false);
 }