Exemplo n.º 1
0
 void DoKeyPress(Keys key)
 {
     if (OnKeyPressed != null)
     {
         Delegate[] delegates = OnKeyPressed.GetInvocationList();
         var        args      = new KeyPressEventArgs(key);
         for (int i = 0; i < delegates.Length; i++)
         {
             delegates[i].DynamicInvoke(this, args);
             if (args.Handled)
             {
                 return;
             }
         }
     }
 }
Exemplo n.º 2
0
        internal static bool DoKeyPressed(Keys k)
        {
            if (DoOnKeyRepeat(k, true))
            {
                return(true);
            }

            if (OnKeyPressed != null)
            {
                Delegate[] dels = OnKeyPressed.GetInvocationList();

                //ctrl+shift is considered a universal override.
                //it will reverse the order of event handling to allow global-level UI to handle keys/mouse before others.
                if (KeyboardHandler.ControlPressed && KeyboardHandler.ShiftPressed)
                {
                    List <Delegate> temp = new List <Delegate>(dels);
                    temp.Reverse();
                    dels = temp.ToArray();
                }

                if (dels.Length == 0)
                {
                    return(false);
                }

                for (int i = dels.Length - 1; i >= 0; i--)
                {
                    KeyEventHandler d = dels[i] as KeyEventHandler;
                    if (d == null) // cast error. should never happen.
                    {
                        continue;
                    }

                    if ((bool)d.DynamicInvoke(null, k))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Unsubscribes all observers or the given observer from tracking events of this handler.
        /// </summary>
        /// <param name="target">The unsubscribing object.</param>
        private void UnsubscribeAllOrTarget(object target = null)
        {
            if (OnKeyPressed != null)
            {
                foreach (Action action in OnKeyPressed.GetInvocationList())
                {
                    if (target == null || action.Target == target)
                    {
                        OnKeyPressed -= action;
                    }
                }
            }

            if (OnKeyDown != null)
            {
                foreach (Action action in OnKeyDown.GetInvocationList())
                {
                    if (target == null || action.Target == target)
                    {
                        OnKeyDown -= action;
                    }
                }
            }
        }