예제 #1
0
        public bool OnKeyDown(ModKeys modKeys, Keys keyCode, string srcElementTagName)
        {
            var args = new HotKeyDownEventArgs(modKeys, keyCode, srcElementTagName);

            KeyDown?.Invoke(null, args);
            return(args.PreventDefault);
        }
예제 #2
0
        /// <summary>
        /// The method that will be invoked when KeyDown event of HotKeys service occurred.
        /// </summary>
        private async void HotKeys_KeyDown(object sender, HotKeyDownEventArgs e)
        {
            foreach (var entry in this.Keys)
            {
                if (entry.ModKeys != e.ModKeys)
                {
                    continue;
                }
                if (entry.Key != e.Key)
                {
                    continue;
                }
                if (e.SrcElementTagName == "INPUT" && (entry.AllowIn & AllowIn.Input) != AllowIn.Input)
                {
                    continue;
                }
                if (e.SrcElementTagName == "TEXTAREA" && (entry.AllowIn & AllowIn.TextArea) != AllowIn.TextArea)
                {
                    continue;
                }

                e.PreventDefault = true;

                await entry.Action?.Invoke(entry);
            }
        }
예제 #3
0
        private bool IsAllowedIn(HotKeyEntry entry, HotKeyDownEventArgs e)
        {
            if (e.SrcElementTagName == "TEXTAREA")
            {
                return((entry.AllowIn & AllowIn.TextArea) == AllowIn.TextArea);
            }

            if (e.SrcElementTagName == "INPUT")
            {
                if (NonTextInputTypes.Contains(e.SrcElementTypeAttribute) &&
                    (entry.AllowIn & AllowIn.NonTextInput) == AllowIn.NonTextInput)
                {
                    return(true);
                }

                return((entry.AllowIn & AllowIn.Input) == AllowIn.Input);
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// The method that will be invoked when KeyDown event of HotKeys service occurred.
        /// </summary>
        private async void HotKeys_KeyDown(object sender, HotKeyDownEventArgs e)
        {
            foreach (var entry in this.Keys)
            {
                if (entry.Key != e.Key)
                {
                    continue;
                }

                var modKeys = entry.ModKeys;
                if (entry.Key == Blazor.HotKeys.Keys.Shift)
                {
                    modKeys |= ModKeys.Shift;
                }
                if (entry.Key == Blazor.HotKeys.Keys.Ctrl)
                {
                    modKeys |= ModKeys.Ctrl;
                }
                if (entry.Key == Blazor.HotKeys.Keys.Alt)
                {
                    modKeys |= ModKeys.Alt;
                }
                if (modKeys != e.ModKeys)
                {
                    continue;
                }

                if (!IsAllowedIn(entry, e))
                {
                    continue;
                }

                e.PreventDefault = true;

                await entry.Action?.Invoke(entry);
            }
        }