Exemplo n.º 1
0
        protected override void OnKeyboardInput(InputEventKeyboard e)
        {
            if (e.Alt || e.Shift || e.Control || IsChanged)
                return;

            if (((int)e.KeyCode >= (int)WinKeys.A && (int)e.KeyCode <= (int)WinKeys.Z) ||
                ((int)e.KeyCode >= (int)WinKeys.F1 && (int)e.KeyCode <= (int)WinKeys.F12))
            {
                Key = e.KeyCode;
            }
            else if ((int)e.KeyCode >= (int)WinKeys.A + 32 && (int)e.KeyCode <= (int)WinKeys.Z + 32) // lower case?
            {
                if (e.KeyCode.ToString().StartsWith("NumPad"))
                    Key = e.KeyCode;
                else if (e.KeyCode.ToString().Length == 1)
                    Key = e.KeyCode;
            }
            else if (e.KeyCode >= WinKeys.D0 && e.KeyCode <= WinKeys.D9)
            {
                Key = e.KeyCode;
            }
            else if (e.KeyCode == WinKeys.NumPad0)//interesting :)
            {
                Key = e.KeyCode;
            }
            else
            {
                return;
            }
            IsChanged = true;
        }
Exemplo n.º 2
0
 public InputEventKeyboard(KeyboardEvent eventType, InputEventKeyboard parent)
     : base(parent)
 {
     EventType = eventType;
     KeyCode = parent.KeyCode;
     m_KeyDataExtra = parent.m_KeyDataExtra;
 }
Exemplo n.º 3
0
 public InputEventKeyboard(KeyboardEvent eventType, InputEventKeyboard parent)
     : base(parent)
 {
     EventType      = eventType;
     KeyCode        = parent.KeyCode;
     m_KeyDataExtra = parent.m_KeyDataExtra;
 }
Exemplo n.º 4
0
 void OnKeyDown(InputEventKeyboard e)
 {
     if (e.DataPreviousState == 0)
     {
         AddEvent(new InputEventKeyboard(KeyboardEvent.Down, e));
     }
     for (int i = 0; i < e.DataRepeatCount; i++)
     {
         AddEvent(new InputEventKeyboard(KeyboardEvent.Press, e));
     }
 }
Exemplo n.º 5
0
 private void onKeyDown(InputEventKeyboard e)
 {
     // handle the initial key down
     if (e.Data_PreviousState == 0)
     {
         addEvent(new InputEventKeyboard(KeyboardEvent.Down, e));
     }
     // handle the key presses. Possibly multiple per keydown message.
     for (int i = 0; i < e.Data_RepeatCount; i++)
     {
         addEvent(new InputEventKeyboard(KeyboardEvent.Press, e));
     }
 }
Exemplo n.º 6
0
 public bool HandleKeyboardEvent(KeyboardEvent type, WinKeys key, bool shift, bool alt, bool ctrl)
 {
     foreach (InputEvent e in m_Events)
     {
         if (!e.Handled && e is InputEventKeyboard)
         {
             InputEventKeyboard ek = e as InputEventKeyboard;
             if (ek.EventType == type && ek.KeyCode == key &&
                 ek.Shift == shift && ek.Alt == alt && ek.Control == ctrl)
             {
                 e.Handled = true;
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        void OnKeyChar(InputEventKeyboard e)
        {
            // Control key sends a strange wm_char message ...
            if (e.Control && !e.Alt)
            {
                return;
            }
            InputEventKeyboard ek = LastKeyPressEvent;

            if (ek == null)
            {
                Tracer.Warn("No corresponding KeyPress event for a WM_CHAR message.");
            }
            else
            {
                ek.OverrideKeyChar(e.KeyCode);
            }
        }
Exemplo n.º 8
0
        private void onKeyChar(InputEventKeyboard e)
        {
            // Control key sends a strange wm_char message ...
            if(e.Control && !e.Alt)
            {
                return;
            }

            InputEventKeyboard pressEvent = LastKeyPressEvent;
            if(pressEvent == null)
            {
                Tracer.Critical("No corresponding KeyPress event for this WM_CHAR message.");
            }
            else
            {
                pressEvent.OverrideKeyChar(e.KeyCode);
            }
        }
Exemplo n.º 9
0
 void OnKeyChar(InputEventKeyboard e)
 {
     // Control key sends a strange wm_char message ...
     if (e.Control && !e.Alt)
     {
         return;
     }
     InputEventKeyboard ek = LastKeyPressEvent;
     if (ek == null)
     {
         Tracer.Warn("No corresponding KeyPress event for a WM_CHAR message.");
     }
     else
     {
         ek.OverrideKeyChar(e.KeyCode);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Raises the KeyDown event. Override this method to add code to handle when a key is pressed
 /// </summary>
 /// <param name="e">InputEventCKB for the KeyDown event</param>
 private void invokeKeyDown(InputEventKeyboard e)
 {
     if (KeyDown != null)
         KeyDown(e);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Raises the OnChar event. Override this method to add code to handle when a WM_CHAR message is received
 /// </summary>
 /// <param name="e">InputEventCKB for the OnChar event</param>
 private void invokeChar(InputEventKeyboard e)
 {
     if (KeyChar != null)
         KeyChar(e);
 }
Exemplo n.º 12
0
 void OnKeyUp(InputEventKeyboard e)
 {
     AddEvent(new InputEventKeyboard(KeyboardEvent.Up, e));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Raises the KeyUp event. Override this method to add code to handle when a key is released
 /// </summary>
 /// <param name="e">KeyboardPressEventArgs for the KeyUp event</param>
 private void invokeKeyUp(InputEventKeyboard e)
 {
     if (KeyUp != null)
         KeyUp(e);
 }
Exemplo n.º 14
0
 private void onKeyDown(InputEventKeyboard e)
 {
     // handle the initial key down
     if(e.Data_PreviousState == 0)
     {
         addEvent(new InputEventKeyboard(KeyboardEvent.Down, e));
     }
     // handle the key presses. Possibly multiple per keydown message.
     for(int i = 0; i < e.Data_RepeatCount; i++)
     {
         addEvent(new InputEventKeyboard(KeyboardEvent.Press, e));
     }
 }
Exemplo n.º 15
0
        public void Update(double totalTime, double frameTime)
        {
            m_MouseEvents.Clear();
            m_KeyboardEvents.Clear();

            var mouseState = Mouse.GetState();
            var keyState   = Keyboard.GetState();

            if (mouseState.X != m_MouseState.X || mouseState.Y != m_MouseState.Y)
            {
                m_LastMouseMove = totalTime;
            }

            if (mouseState.LeftButton != m_MouseState.LeftButton)
            {
                var buttonState = mouseState.LeftButton == ButtonState.Pressed ? MouseEvent.Down : MouseEvent.Up;
                m_MouseEvents.Add(new InputEventMouse(buttonState, WinMouseButtons.Left, 0, m_MouseState.X, m_MouseState.Y, 0, 0));
            }

            if (mouseState.RightButton != m_MouseState.RightButton)
            {
                var buttonState = mouseState.RightButton == ButtonState.Pressed ? MouseEvent.Down : MouseEvent.Up;
                m_MouseEvents.Add(new InputEventMouse(buttonState, WinMouseButtons.Right, 0, m_MouseState.X, m_MouseState.Y, 0, 0));
            }

            if (mouseState.MiddleButton != m_MouseState.RightButton)
            {
                var buttonState = mouseState.MiddleButton == ButtonState.Pressed ? MouseEvent.Down : MouseEvent.Up;
                m_MouseEvents.Add(new InputEventMouse(buttonState, WinMouseButtons.Middle, 0, m_MouseState.X, m_MouseState.Y, 0, 0));
            }

            var oldKeys = new List <Keys>(m_KeyboardState.GetPressedKeys());
            var newKeys = new List <Keys>(keyState.GetPressedKeys());

            m_Modifiers = 0;

            if (keyState.IsKeyDown(Keys.LeftShift) || keyState.IsKeyDown(Keys.RightShift))
            {
                m_Modifiers |= (int)WinKeys.Shift;
            }

            if (keyState.IsKeyDown(Keys.LeftAlt) || keyState.IsKeyDown(Keys.RightAlt))
            {
                m_Modifiers |= (int)WinKeys.Alt;
            }

            if (keyState.IsKeyDown(Keys.LeftControl) || keyState.IsKeyDown(Keys.RightControl))
            {
                m_Modifiers |= (int)WinKeys.Control;
            }

            foreach (var k in oldKeys)
            {
                if (!newKeys.Contains(k))
                {
                    m_KeyboardEvents.Add(new InputEventKeyboard(KeyboardEvent.Up, TranslateToWinKey(k), m_Modifiers));
                }
            }

            foreach (var k in newKeys)
            {
                if (!oldKeys.Contains(k))
                {
                    m_KeyboardEvents.Add(new InputEventKeyboard(KeyboardEvent.Down, TranslateToWinKey(k), m_Modifiers));
                    var press = new InputEventKeyboard(KeyboardEvent.Press, TranslateToWinKey(k), m_Modifiers);
                    press.OverrideKeyChar(TranslateToPrintableChar(k, keyState));
                    m_KeyboardEvents.Add(press);
                }
            }

            m_MouseState     = mouseState;
            m_KeyboardState  = keyState;
            m_LastUpdateTime = totalTime;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Reads the supplied message and executes any Keyboard events required.
        /// </summary>
        /// <param name="message">The Message to parse</param>
        /// <returns>A Boolean value indicating wether the Key events were handled or not</returns>
        private void WmKeyEvent(ref Message message)
        {
            // HandleKeyBindings();
            // KeyPressEventArgs keyPressEventArgs = null;

            if ((message.Id == NativeConstants.WM_CHAR) || (message.Id == NativeConstants.WM_SYSCHAR))
            {
                // Is this extra information necessary?
                // wm_(sys)char: http://msdn.microsoft.com/en-us/library/ms646276(VS.85).aspx

                InputEventKeyboard e = new InputEventKeyboard(KeyboardEvent.Press,
                    (WinKeys)(int)(long)message.WParam,
                    (int)(long)message.LParam,
                    ModifierKeys
                    );
                IntPtr zero = (IntPtr)0;
                invokeChar(e);
            }
            else
            {
                // wm_(sys)keydown: http://msdn.microsoft.com/en-us/library/ms912654.aspx
                // wm_(sys)keyup: http://msdn.microsoft.com/en-us/library/ms646281(VS.85).aspx

                if ((message.Id == NativeConstants.WM_KEYDOWN) || (message.Id == NativeConstants.WM_SYSKEYDOWN))
                {
                    InputEventKeyboard e = new InputEventKeyboard(KeyboardEvent.Down,
                        (WinKeys)(int)(long)message.WParam,
                        (int)(long)message.LParam,
                        ModifierKeys
                        );
                    invokeKeyDown(e);
                }
                else if ((message.Id == NativeConstants.WM_KEYUP) || (message.Id == NativeConstants.WM_SYSKEYUP))
                {
                    InputEventKeyboard e = new InputEventKeyboard(KeyboardEvent.Up,
                        (WinKeys)(int)(long)message.WParam,
                        (int)(long)message.LParam,
                        ModifierKeys
                        );
                    invokeKeyUp(e);
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Raises the KeyDown event. Override this method to add code to handle when a key is pressed
 /// </summary>
 /// <param name="e">InputEventCKB for the KeyDown event</param>
 private void invokeKeyDown(InputEventKeyboard e)
 {
     KeyDown?.Invoke(e);
 }
Exemplo n.º 18
0
 private void onKeyUp(InputEventKeyboard e)
 {
     addEvent(new InputEventKeyboard(KeyboardEvent.Up, e));
 }
Exemplo n.º 19
0
 void OnKeyUp(InputEventKeyboard e)
 {
     AddEvent(new InputEventKeyboard(KeyboardEvent.Up, e));
 }
Exemplo n.º 20
0
 void OnKeyDown(InputEventKeyboard e)
 {
     if (e.DataPreviousState == 0)
     {
         AddEvent(new InputEventKeyboard(KeyboardEvent.Down, e));
     }
     for (int i = 0; i < e.DataRepeatCount; i++)
     {
         AddEvent(new InputEventKeyboard(KeyboardEvent.Press, e));
     }
 }
Exemplo n.º 21
0
 /// <summary>
 /// Raises the OnChar event. Override this method to add code to handle when a WM_CHAR message is received
 /// </summary>
 /// <param name="e">InputEventCKB for the OnChar event</param>
 private void invokeChar(InputEventKeyboard e)
 {
     KeyChar?.Invoke(e);
 }
Exemplo n.º 22
0
        protected override void OnKeyboardInput(InputEventKeyboard e)
        {
            switch (e.KeyCode)
            {
                case WinKeys.Tab:
                    Parent.KeyboardTabToNextFocus(this);
                    break;

                case WinKeys.Enter:
                    Parent.OnKeyboardReturn(EntryID, Text);
                    break;

                case WinKeys.Back:
                    if (ReplaceDefaultTextOnFirstKeypress)
                    {
                        Text = string.Empty;
                        ReplaceDefaultTextOnFirstKeypress = false;
                    }
                    else if (Text.Length > 0)
                    {
                        int escapedLength;
                        if (EscapeCharacters.TryFindEscapeCharacterBackwards(Text, Text.Length - 1, out escapedLength))
                        {
                            Text = Text.Substring(0, Text.Length - escapedLength);
                        }
                        else
                        {
                            Text = Text.Substring(0, Text.Length - 1);
                        }
                    }
                    break;

                default:
                    // place a char, so long as it's within the widths limit.
                    if (LimitSize != 0 && Text.Length >= LimitSize)
                        return;

                    if (NumericOnly && !char.IsNumber(e.KeyChar))
                        return;

                    if (ReplaceDefaultTextOnFirstKeypress)
                    {
                        Text = string.Empty;
                        ReplaceDefaultTextOnFirstKeypress = false;
                    }

                    if (e.IsChar && e.KeyChar >= 32)
                    {
                        string escapedCharacter;
                        if (EscapeCharacters.TryMatchChar(e.KeyChar, out escapedCharacter))
                        {
                            Text += escapedCharacter;
                        }
                        else
                        {
                            Text += e.KeyChar;
                        }
                    }
                    break;
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Raises the KeyUp event. Override this method to add code to handle when a key is released
 /// </summary>
 /// <param name="e">KeyboardPressEventArgs for the KeyUp event</param>
 private void invokeKeyUp(InputEventKeyboard e)
 {
     KeyUp?.Invoke(e);
 }
Exemplo n.º 24
0
        protected virtual void OnKeyboardInput(InputEventKeyboard e)
        {

        }
Exemplo n.º 25
0
        private void onKeyChar(InputEventKeyboard e)
        {
            // Control key sends a strange wm_char message ...
            if(e.Control && !e.Alt)
            {
                return;
            }

            InputEventKeyboard pressEvent = LastKeyPressEvent;
            if(pressEvent == null)
            {
                Tracer.Critical("No corresponding KeyPress event for this WM_CHAR message.");
            }
            else
            {
                pressEvent.OverrideKeyChar(e.KeyCode);
            }
        }
Exemplo n.º 26
0
 public void KeyboardInput(InputEventKeyboard e)
 {
     OnKeyboardInput(e);
 }
Exemplo n.º 27
0
 private void onKeyUp(InputEventKeyboard e)
 {
     addEvent(new InputEventKeyboard(KeyboardEvent.Up, e));
 }
Exemplo n.º 28
0
 // ============================================================================================================
 // Input
 // ============================================================================================================
 protected override void OnKeyboardInput(InputEventKeyboard e)
 {
     if (e.KeyCode == WinKeys.Up || e.KeyCode == WinKeys.Down)
     {
         Point current = m_RenderedText.Document.GetCaratPositionByIndex(CaratAt);
         if (m_CaratKeyUpDownX == null)
         {
             m_CaratKeyUpDownX = current.X;
         }
         Point next = new Point(m_CaratKeyUpDownX.Value, current.Y + (e.KeyCode == WinKeys.Up ? -18 : 18));
         int carat = m_RenderedText.Document.GetCaratIndexByPosition(next);
         if (carat != -1)
         {
             CaratAt = carat;
         }
     }
     else
     {
         m_CaratKeyUpDownX = null;
         switch (e.KeyCode)
         {
             case WinKeys.Tab:
                 Parent.KeyboardTabToNextFocus(this);
                 break;
             case WinKeys.Enter:
                 InsertCharacter(CaratAt, '\n');
                 break;
             case WinKeys.Back:
                 if (CaratAt == 0)
                 {
                     m_OnPageUnderflow.Invoke(PageIndex);
                 }
                 else
                 {
                     RemoveCharacter(CaratAt);
                 }
                 break;
             case WinKeys.Left:
                 if (CaratAt == 0)
                 {
                     m_OnPreviousPage?.Invoke(PageIndex);
                 }
                 else
                 {
                     CaratAt = CaratAt - 1;
                 }
                 break;
             case WinKeys.Right:
                 if (CaratAt == Text.Length)
                 {
                     m_OnNextPage?.Invoke(PageIndex);
                 }
                 else
                 {
                     CaratAt = CaratAt + 1;
                 }
                 break;
             default:
                 if (e.IsChar && e.KeyChar >= 32)
                 {
                     InsertCharacter(CaratAt, e.KeyChar);
                 }
                 break;
         }
     }
     SetBlinkOn();
 }