コード例 #1
0
        /// <summary>
        /// Invokes <see cref="KeyPress"/>
        /// </summary>
        /// <param name="keyboard">The keyboard object which received the event</param>
        /// <param name="args">The key that was pressed</param>
        public virtual void OnKeyPressed(object keyboard, ConsoleKeyEventArgs args)
        {
            args.Handled = HandleKeyPress(keyboard, args);

            // handle priority key presses
            if (PriorityKeyPress != null)
            {
                foreach (EventHandler <ConsoleKeyEventArgs> handler in PriorityKeyPress.GetInvocationList())
                {
                    handler(keyboard, args);

                    if (args.Handled)
                    {
                        break;
                    }
                }
            }

            // handle normal key presses
            if (KeyPress != null && !args.Handled)
            {
                foreach (EventHandler <ConsoleKeyEventArgs> handler in KeyPress.GetInvocationList())
                {
                    handler(keyboard, args);

                    if (args.Handled)
                    {
                        break;
                    }
                }
            }
        }
コード例 #2
0
        private static void onUpdate(object sender, UpdateEventArgs e)
        {
            if (KeyPress != null)
            {
                RLKeyPress key = RootConsole.Keyboard.GetKeyPress();

                if (key != null)
                {
                    KeyPressEventArgs arg = new KeyPressEventArgs(key);

                    foreach (EventHandler <KeyPressEventArgs> func in KeyPress.GetInvocationList())
                    {
                        func(sender, arg);
                        if (arg.Cancel)
                        {
                            break;
                        }
                    }
                }
            }
        }