public InputEventKeyboard(KeyboardEventType eventType, InputEventKeyboard parent) : base(parent) { m_eventType = eventType; m_keyCode = parent.m_keyCode; m_keyDataExtra = parent.m_keyDataExtra; }
/// <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); } }
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) { Key = e.KeyCode; //interesting :) } else { return; } IsChanged = true; }
/// <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); } }
/// <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); } }
protected override void OnKeyboardInput(InputEventKeyboard e) { switch (e.KeyCode) { case WinKeys.Tab: Parent.KeyboardTabToNextFocus(this); break; case WinKeys.Enter: Parent.ActivateByKeyboardReturn(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: if (NumericOnly && !char.IsNumber(e.KeyChar)) { return; } if (ReplaceDefaultTextOnFirstKeypress) { Text = string.Empty; ReplaceDefaultTextOnFirstKeypress = false; } if (e.IsChar) { string escapedCharacter; if (EscapeCharacters.TryMatchChar(e.KeyChar, out escapedCharacter)) { Text += escapedCharacter; } else { Text += e.KeyChar; } } break; } }
protected internal override void KeyDown(InputEventKeyboard e) { lock (RenderRule) { if (RenderRule.Length != 0) { switch (e.KeyCode) { case WinKeys.Left: RenderRule.TextCursor--; RenderRule.SelectedChar = null; break; case WinKeys.Right: RenderRule.TextCursor++; RenderRule.SelectedChar = null; break; case WinKeys.Up: RenderRule.CursorUp(); RenderRule.SelectedChar = null; break; case WinKeys.Down: RenderRule.CursorDown(); RenderRule.SelectedChar = null; break; case WinKeys.Home: RenderRule.CursorHome(); RenderRule.SelectedChar = null; break; case WinKeys.End: RenderRule.CursorEnd(); RenderRule.SelectedChar = null; break; case WinKeys.PageUp: RenderRule.TextCursor = 0; RenderRule.SelectedChar = null; break; case WinKeys.PageDown: RenderRule.TextCursor = RenderRule.Length; RenderRule.SelectedChar = null; break; case WinKeys.Delete: RenderRule.Delete(); RenderRule.BakeText(); RenderRule.SelectedChar = null; break; } } } ResetTimer(); }
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)); } }
public bool HandleKeyboardEvent(KeyboardEvent type, WinKeys key, bool shift, bool alt, bool ctrl) { foreach (InputEvent e in m_EventsThisFrame) { if (e.Handled || !(e is InputEventKeyboard)) { continue; } InputEventKeyboard ek = (InputEventKeyboard)e; if (ek.EventType != type || ek.KeyCode != key || ek.Shift != shift || ek.Alt != alt || ek.Control != ctrl) { continue; } e.Handled = true; return(true); } return(false); }
/// <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;// (char)((ushort)((long)message.WParam)); 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); } } }
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) { throw new Exception("No corresponding KeyPress event for this WM_CHAR message. Please report this error to [email protected]"); } else { pressEvent.OverrideKeyChar(e.KeyCode); } }
protected override void keyboardInput(InputEventKeyboard e) { switch (e.KeyCode) { case WinKeys.Back: if (Text.Length > 0) { int escapedLength; if (HTML.EscapeCharacters.TryFindEscapeCharacterBackwards(Text, Text.Length - 1, out escapedLength)) { Text = Text.Substring(0, Text.Length - escapedLength); } else { Text = Text.Substring(0, Text.Length - 1); } } break; case WinKeys.Tab: m_owner.KeyboardTabToNextFocus(this); break; case WinKeys.Enter: m_owner.ActivateByKeyboardReturn(EntryID, Text); break; default: if (e.IsChar) { string escapedCharacter; if (HTML.EscapeCharacters.TryMatchChar(e.KeyChar, out escapedCharacter)) { Text += escapedCharacter; } else { Text += e.KeyChar; } } break; } }
public bool TryGetKeyboardEvent(bool translateASCII, out ushort eventCode) { eventCode = 0; for (int i = 0; i < m_EventsThisFrame.Count; i++) { if (m_EventsThisFrame[i].Handled || !(m_EventsThisFrame[i] is InputEventKeyboard)) { continue; } InputEventKeyboard e = (InputEventKeyboard)m_EventsThisFrame[i]; m_EventsThisFrame.RemoveAt(i); bool translated = false; ushort bitsKeycode = (byte)e.KeyCode; ushort bitsKeyChar = (byte)e.KeyChar; if (translateASCII && (bitsKeyChar != 0)) { translated = true; bitsKeycode = bitsKeyChar; } ushort bitsEvent; switch (e.EventType) { case KeyboardEvent.Up: bitsEvent = EventUp; break; case KeyboardEvent.Down: bitsEvent = EventDown; break; case KeyboardEvent.Press: bitsEvent = EventPress; break; default: throw new ArgumentOutOfRangeException(); } eventCode = (ushort)(bitsKeycode | bitsEvent | (e.Shift ? ShiftDown : 0) | (e.Alt ? AltDown : 0) | (e.Control ? CtrlDown : 0) | (translated ? TranslatedKey : 0)); return(true); } return(false); }
protected virtual void OnKeyboardInput(InputEventKeyboard e) { }
// ============================================================================================================ // Input // ============================================================================================================ 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 (!string.IsNullOrEmpty(Text)) { 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 char count limit. if (MaxCharCount != 0 && Text.Length >= MaxCharCount) { 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; } }
protected internal virtual void CharEntered(InputEventKeyboard e) { }
internal override void OnKeyboardPress(InputEventKeyboard args) { }
internal override void OnKeyboardPress(InputEventKeyboard args) { // Ctrl-X: Cut if (args.KeyCode == WinKeys.X && args.Control) { byte[] data = new byte[64]; for (int i = 0; i < 64; i++) { data[i] = State.Data.TileGfx.GetPixel(State.SelectedPage, State.SelectedTile, i); State.SetPixel(State.SelectedPage, State.SelectedTile, i, 0); } State.Clipboard.Cut(ClipboardData.Tile, data); } // Ctrl-C: Copy if (args.KeyCode == WinKeys.C && args.Control) { byte[] data = new byte[64]; for (int i = 0; i < 64; i++) { data[i] = State.Data.TileGfx.GetPixel(State.SelectedPage, State.SelectedTile, i); } State.Clipboard.Copy(ClipboardData.Tile, data); } // Ctrl-V: Paste if (args.KeyCode == WinKeys.V && args.Control) { if (!State.Clipboard.HasData || State.Clipboard.DataType != ClipboardData.Tile) { return; } byte[] data = State.Clipboard.Paste(); for (int i = 0; i < 64; i++) { State.SetPixel(State.SelectedPage, State.SelectedTile, i, data[i]); } } // Ctrl-H: Horizontal Mirror if (args.KeyCode == WinKeys.H && args.Control) { byte[] data = new byte[64]; for (int i = 0; i < 64; i++) { data[i] = State.Data.TileGfx.GetPixel(State.SelectedPage, State.SelectedTile, i); } for (int i = 0; i < 64; i++) { State.SetPixel(State.SelectedPage, State.SelectedTile, (7 - i % 8) + (i / 8) * 8, data[i]); } } // Ctrl-F: Vertical Mirror if (args.KeyCode == WinKeys.F && args.Control) { byte[] data = new byte[64]; for (int i = 0; i < 64; i++) { data[i] = State.Data.TileGfx.GetPixel(State.SelectedPage, State.SelectedTile, i); } for (int i = 0; i < 64; i++) { State.SetPixel(State.SelectedPage, State.SelectedTile, (i % 8) + (7 - (i / 8)) * 8, data[i]); } } }
private void onKeyUp(InputEventKeyboard e) { addEvent(new InputEventKeyboard(KeyboardEvent.Up, e)); }
/// <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); }
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); } }
protected internal virtual void KeyUp(InputEventKeyboard e) { }
internal virtual void OnKeyboardPress(InputEventKeyboard args) { }
/// <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); }
public void KeyboardInput(InputEventKeyboard e) { OnKeyboardInput(e); }
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)); } }
// ============================================================================================================ // Input // ============================================================================================================ protected override void OnKeyboardInput(InputEventKeyboard e) { if (e.KeyCode == WinKeys.Up || e.KeyCode == WinKeys.Down) { var current = _renderedText.Document.GetCaratPositionByIndex(CaratAt); if (_caratKeyUpDownX == null) { _caratKeyUpDownX = current.X; } var next = new Vector2Int(_caratKeyUpDownX.Value, current.Y + (e.KeyCode == WinKeys.Up ? -18 : 18)); var carat = _renderedText.Document.GetCaratIndexByPosition(next); if (carat != -1) { CaratAt = carat; } } else { _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) { _onPageUnderflow.Invoke(PageIndex); } else { RemoveCharacter(CaratAt); } break; case WinKeys.Left: if (CaratAt == 0) { _onPreviousPage?.Invoke(PageIndex); } else { CaratAt = CaratAt - 1; } break; case WinKeys.Right: if (CaratAt == Text.Length) { _onNextPage?.Invoke(PageIndex); } else { CaratAt = CaratAt + 1; } break; default: if (e.IsChar && e.KeyChar >= 32) { InsertCharacter(CaratAt, e.KeyChar); } break; } } SetBlinkOn(); }
/// <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); }
protected internal override void CharEntered(InputEventKeyboard e) { lock (RenderRule) { switch (e.KeyChar) { case '\b': { //Backspace <= remove selected or remove before cursor if (RenderRule.HasSelected) { RenderRule.RemoveSelected(); } else { RenderRule.BackSpace(); } break; } case '\n': case '\r': { //New Line <= Insert character after cursor if (RenderRule.HasSelected) { RenderRule.RemoveSelected(); } RenderRule.Insert(e.KeyChar); break; } case '\t': { //Tabs currently not supported return; } case (char)3: { //Copy Clipboard.SetDataObject(RenderRule.GetSelected(), true); break; } case (char)22: { //Paste if (RenderRule.HasSelected) { RenderRule.RemoveSelected(); } var dataObject = Clipboard.GetDataObject(); if (dataObject != null) { var text = dataObject.GetData(DataFormats.Text).ToString(); RenderRule.Insert(text); } break; } case (char)24: { //Cut if (RenderRule.HasSelected) { Clipboard.SetDataObject(RenderRule.GetSelected(), true); RenderRule.RemoveSelected(); } break; } default: { //Add the character if (RenderRule.HasSelected) { RenderRule.RemoveSelected(); } RenderRule.Insert(e.KeyChar); RenderRule.SelectedChar = null; break; } } RenderRule.BakeText(); if (OnValueChanged != null) { OnValueChanged(this); } } ResetTimer(); }