Example #1
0
        internal HotkeyTrigger(ActionTriggers triggers, Action <HotkeyTriggerArgs> action, KMod mod, KMod modAny, TKFlags flags, string paramsString) : base(triggers, action, true)
        {
            const KMod csaw = KMod.Ctrl | KMod.Shift | KMod.Alt | KMod.Win;

            modMask       = ~modAny & csaw;
            modMasked     = mod & modMask;
            this.flags    = flags;
            _paramsString = flags == 0 ? paramsString : paramsString + " (" + flags.ToString() + ")";             //AOutput.Write(_paramsString);
        }
Example #2
0
 /// <summary>
 /// Adds a hotkey trigger.
 /// </summary>
 /// <param name="hotkey">
 /// A hotkey, like with the <see cref="AKeys.Key"/> function.
 /// Can contain 0 to 4 modifier keys (Ctrl, Shift, Alt, Win) and 1 non-modifier key.
 /// Examples: "F11", "Ctrl+K", "Ctrl+Shift+Alt+Win+A".
 /// To ignore modifiers: "?+K". Then the trigger works with any combination of modifiers.
 /// To ignore a modifier: "Ctrl?+K". Then the trigger works with or without the modifier. More examples: "Ctrl?+Shift?+K", "Ctrl+Shift?+K".
 /// </param>
 /// <param name="flags"></param>
 /// <exception cref="ArgumentException">Invalid hotkey string or flags.</exception>
 /// <exception cref="InvalidOperationException">Cannot add triggers after <c>Triggers.Run</c> was called, until it returns.</exception>
 /// <example>See <see cref="ActionTriggers"/>.</example>
 public Action <HotkeyTriggerArgs> this[string hotkey, TKFlags flags = 0] {
     set {
         if (!AKeys.More.ParseHotkeyTriggerString_(hotkey, out var mod, out var modAny, out var key, false))
         {
             throw new ArgumentException("Invalid hotkey string.");
         }
         _Add(value, key, mod, modAny, flags, hotkey);
     }
 }
Example #3
0
        /// <summary>
        /// Adds a hotkey trigger.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="modKeys">
        /// Modifier keys, like with the <see cref="AKeys.Key"/> function.
        /// Examples: "Ctrl", "Ctrl+Shift+Alt+Win".
        /// To ignore modifiers: "?". Then the trigger works with any combination of modifiers.
        /// To ignore a modifier: "Ctrl?". Then the trigger works with or without the modifier. More examples: "Ctrl?+Shift?", "Ctrl+Shift?".
        /// </param>
        /// <param name="flags"></param>
        /// <exception cref="ArgumentException">Invalid modKeys string or flags.</exception>
        /// <exception cref="InvalidOperationException">Cannot add triggers after <c>Triggers.Run</c> was called, until it returns.</exception>
        public Action <HotkeyTriggerArgs> this[KKey key, string modKeys, TKFlags flags = 0] {
            set {
                var ps = key.ToString(); if (AChar.IsAsciiDigit(ps[0]))
                {
                    ps = "VK" + ps;
                }
                if (!modKeys.NE())
                {
                    ps = modKeys + "+" + ps;
                }

                if (!AKeys.More.ParseHotkeyTriggerString_(modKeys, out var mod, out var modAny, out _, true))
                {
                    throw new ArgumentException("Invalid modKeys string.");
                }
                _Add(value, key, mod, modAny, flags, ps);
            }
        }
Example #4
0
        void _Add(Action <HotkeyTriggerArgs> action, KKey key, KMod mod, KMod modAny, TKFlags flags, string paramsString)
        {
            if (mod == 0 && flags.HasAny((TKFlags.LeftMod | TKFlags.RightMod)))
            {
                throw new ArgumentException("Invalid flags.");
            }
            _triggers.ThrowIfRunning_();
            //actually could safely add triggers while running.
            //	Currently would need just lock(_d) in several places. Also some triggers of this type must be added before starting, else we would not have the hook etc.
            //	But probably not so useful. Makes programming more difficult. If need, can Stop, add triggers, then Run again.

            //AOutput.Write($"key={key}, mod={mod}, modAny={modAny}");
            var t = new HotkeyTrigger(_triggers, action, mod, modAny, flags, paramsString);

            t.DictAdd(_d, (int)key);
            _lastAdded = t;
        }
Example #5
0
 internal HotkeyTrigger(ActionTriggers triggers, Action <HotkeyTriggerArgs> action, KMod mod, KMod modAny, TKFlags flags, string paramsString, (string, int) source)