Ejemplo n.º 1
0
 public KeyboardHookEventArgs(KeyboardEventType type, Keys key, int wParam, Native.keyboardHookStruct lParam)
 {
     Type        = type;
     this.wParam = wParam;
     this.lParam = lParam;
     this.key    = key;
 }
Ejemplo n.º 2
0
 public InputEventKeyboard(KeyboardEventType eventType, WinKeys wParam_VirtKeyCode, int lParam_KeyData, WinKeys modifiers)
     : base(modifiers)
 {
     m_eventType = eventType;
     m_keyCode = wParam_VirtKeyCode;
     m_keyDataExtra = lParam_KeyData;
 }
Ejemplo n.º 3
0
 public InputEventKeyboard(KeyboardEventType eventType, InputEventKeyboard parent)
     : base(parent)
 {
     m_eventType = eventType;
     m_keyCode = parent.m_keyCode;
     m_keyDataExtra = parent.m_keyDataExtra;
 }
Ejemplo n.º 4
0
 public InputEventKeyboard(KeyboardEventType eventType, InputEventKeyboard parent)
     : base(parent)
 {
     m_eventType    = eventType;
     m_keyCode      = parent.m_keyCode;
     m_keyDataExtra = parent.m_keyDataExtra;
 }
Ejemplo n.º 5
0
 public KeyboardEvent(KeyboardEventType type, bool shift, bool alt, bool ctrl)
 {
     this.type  = type;
     this.shift = shift;
     this.alt   = alt;
     this.ctrl  = ctrl;
 }
Ejemplo n.º 6
0
        protected override int HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode != 0)
            {
                return(HookExtern.CallNextHookEx(this.HookType, nCode, wParam, lParam));
            }

            KeyboardEventType eventType = (KeyboardEventType)(((uint)wParam % 2) + 256); // filter out SysKeyDown & SysKeyUp
            Keys key = (Keys)Marshal.ReadInt32(lParam);

            KeyboardEventArgs KeyboardEventArgs = new KeyboardEventArgs(eventType, key);
            bool isHandled = false;

            lock (((IList)this.Handlers).SyncRoot) {
                foreach (HandleKeyboardInputDelegate handler in this.Handlers)
                {
                    isHandled = handler(KeyboardEventArgs);
                    if (isHandled)
                    {
                        break;
                    }
                }
            }

            if (isHandled)
            {
                return(1);
            }
            else
            {
                return(HookExtern.CallNextHookEx(this.HookType, nCode, wParam, lParam));
            }
        }
Ejemplo n.º 7
0
 public InputEventKeyboard(KeyboardEventType eventType, WinKeys wParam_VirtKeyCode, int lParam_KeyData, WinKeys modifiers)
     : base(modifiers)
 {
     m_eventType    = eventType;
     m_keyCode      = wParam_VirtKeyCode;
     m_keyDataExtra = lParam_KeyData;
 }
        public override void KeyboardEvent(KeyboardEventType down, KeyEventArgs args)
        {
            var fr = Elements.FirstOrDefault(z => z.IsFocused);

            if (fr != null)
            {
                fr.KeyboardEvent(down, args);
            }
        }
Ejemplo n.º 9
0
 protected void DispatchKeyboradEvent(KeyboardEventType keyboradEventType, VirtualKeys virtualKey)
 {
     if (!virtualKeyToKeyCodeMap.ContainsKey(virtualKey))
     {
         Debug.LogWarningFormat("Unknown virtual key detected: {0}", virtualKey);
         return;
     }
     this.KeyboradEvent?.Invoke(new KeyboardEvent(keyboradEventType, virtualKeyToKeyCodeMap[virtualKey]));
 }
Ejemplo n.º 10
0
 private IntPtr OnKeyboard(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_KEYUP))
     {
         KeyboardEventType type = wParam == (IntPtr)WM_KEYDOWN ? KeyboardEventType.KeyDown : KeyboardEventType.KeyUp;
         Keys key = (Keys)Marshal.ReadInt32(lParam);
         this.KeyEvent?.Invoke(this, type, key);
     }
     return(CallNextHookEx(_hookID, nCode, wParam, lParam));
 }
Ejemplo n.º 11
0
 public KeyboardEventData(KeyboardEventType eventType, bool alt, bool control, Key keyCode, Key keyData, int keyValue, bool shift, char keyChar, DateTime timestamp)
     : base(timestamp)
 {
     EventType = eventType;
     Alt       = alt;
     Control   = control;
     KeyCode   = keyCode;
     KeyData   = keyData;
     KeyValue  = keyValue;
     KeyChar   = keyChar;
     Shift     = shift;
 }
Ejemplo n.º 12
0
        public static KeyEventF ToWindowsKeyEvent(this KeyboardEventType src)
        {
            switch (src)
            {
            case KeyboardEventType.KEY_DOWN:
                return(KeyEventF.KeyDown);

            case KeyboardEventType.KEY_UP:
                return(KeyEventF.KeyUp);
            }
            return(KeyEventF.ExtendedKey);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Converts the keyboard event type, the key, and the modifier keys' information
        /// to an array of bytes so that it can be sent over the network.
        /// </summary>
        /// <param name="type">Press, Release, or Type</param>
        /// <param name="key">The key</param>
        /// <param name="modifier">A struct that indicates whether any of the modifier
        /// keys are held down</param>
        /// <returns></returns>
        public byte[] GetNetworkData(KeyboardEventType type, Keys key, KeyModifier modifier)
        {
            // 1 byte for type, 1 byte for key, and 1 (bool) * 3 bytes for modifier
            byte[] data = new byte[5];

            data[0] = (byte)type;
            data[1] = (byte)key;
            data[2] = BitConverter.GetBytes(modifier.AltKeyPressed)[0];
            data[3] = BitConverter.GetBytes(modifier.CtrlKeyPressed)[0];
            data[4] = BitConverter.GetBytes(modifier.ShiftKeyPressed)[0];

            return(data);
        }
Ejemplo n.º 14
0
        public override void KeyboardEvent(KeyboardEventType down, KeyEventArgs args)
        {
            var a = (int)args.KeyCode;

            if (down == KeyboardEventType.Down)
            {
                press((byte)a);
            }

            if (down == KeyboardEventType.Up)
            {
                release((byte)a);
            }
        }
Ejemplo n.º 15
0
        private void FireRawInputEvent(ref RawInput ri)
        {
            try
            {
                TraceLogger.Instance.WriteLineVerbos("FireRawInputEvent: " + ri.Header.dwType);
                switch (ri.Header.dwType)
                {
                case (int)RawInputType.Mouse:
                    if (RawInputMouseEvent != null)
                    {
                        //if (Enum.IsDefined(typeof(MouseEventType), (short)(ri.Data.Mouse.ulButtons & ushort.MaxValue)))
                        {
                            MouseEventType evt = (MouseEventType)ri.Data.Mouse.ulButtons;
                            int            x   = Cursor.Position.X;
                            int            y   = Cursor.Position.Y;
                            RawInputMouseEvent(evt, x, y);
                        }
                        //else
                        {
                            //TraceLogger.Instance.WriteLineInfo(string.Format("Undefined MouseEventType: {0:X}", ri.Data.Mouse.ulButtons));
                        }
                    }
                    break;

                case (int)RawInputType.KeyBoard:
                    if (RawInputKeyboardEvent != null)
                    {
                        //if (Enum.IsDefined(typeof(KeyboardEventType), (short)ri.Data.Keyboard.Message))
                        {
                            KeyboardEventType evt = (KeyboardEventType)ri.Data.Keyboard.Message;
                            Keys key = (Keys)ri.Data.Keyboard.VKey;
                            RawInputKeyboardEvent(evt, key);
                        }
                        //else
                        {
                            //TraceLogger.Instance.WriteLineInfo(string.Format("Undefined KeyboardEventType: {0:X}", ri.Data.Keyboard.Message));
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                TraceLogger.Instance.WriteException(ex);
            }
        }
Ejemplo n.º 16
0
 void sendEvent(KeyCode keycode, KeyboardEventType evType)
 {
     if (evType == KeyboardEventType.keyDown)
     {
         OnKey.Invoke(keycode);
     }
     if (evType == KeyboardEventType.KeyUp)
     {
         OnKeyUp.Invoke(keycode);
     }
     if (evType == KeyboardEventType.down)
     {
         OnKeyDown.Invoke(keycode);
     }
 }
Ejemplo n.º 17
0
        private bool ProcessInput(KeyboardEventType eventType, Keys key)
        {
            _inputBuffer.Enqueue(new KeyboardEventArgs(eventType, key));

            if (_textInputDelegate != null)
            {
                string chars = TypedInputUtil.VkCodeToString((uint)key, eventType == KeyboardEventType.KeyDown);
                _textInputDelegate?.BeginInvoke(chars, EndTextInputAsyncInvoke, null);
                return(ShouldBlockKeyEvent(key));
            }

            // TODO: Implement blocking based on the key that is pressed (for example: Key binding blocking the last pressed key)

            return(false);
        }
Ejemplo n.º 18
0
        private bool ProcessInput(KeyboardEventType eventType, Keys key)
        {
            _inputBuffer.Enqueue(new KeyboardEventArgs(eventType, key));

            if (_textInputDelegate != null)
            {
                string chars = TypedInputUtil.VkCodeToString((uint)key, eventType == KeyboardEventType.KeyDown);
                _textInputDelegate?.BeginInvoke(chars, EndTextInputAsyncInvoke, null);
                return(true /* key != Keys.LeftShift && key != Keys.RightShift */); // "SHIFT" support temporarily disabled
            }

            // TODO: Implement blocking based on the key that is pressed (for example: Key binding blocking the last pressed key)

            return(false);
        }
Ejemplo n.º 19
0
 internal void ReceiveKeyboardEvent(KeyboardEventType ke)
 {
     switch (ke)
     {
         case KeyboardEventType.Down:
             m_InInitialRepeatPeriod = true;
             m_State = ActionState.Press;
             m_SecondsSincePress = 0f;
             break;
         case KeyboardEventType.Up:
             m_State = ActionState.Release;
             break;
         // ignore press events - we handle our own presses.
     }
 }
Ejemplo n.º 20
0
        public void SendCharEvent(int character, KeyboardEventType type)
        {
            if (Initialized)
            {
                KeyboardEvent keyboardEvent = new KeyboardEvent {
                    Type = type,
                    Key  = character
                };
                EventPacket ep = new EventPacket {
                    Event = keyboardEvent,
                    Type  = BrowserEventType.Keyboard
                };

                _outCommServer.TrySend(ep, 100);
            }
        }
Ejemplo n.º 21
0
        public void SendCharEvent(int character, KeyboardEventType type)
        {
            if (Initialized)
            {
                KeyboardEvent keyboardEvent = new KeyboardEvent()
                {
                    Type = type,
                    Key  = character
                };
                EventPacket ep = new EventPacket()
                {
                    Event = keyboardEvent,
                    Type  = MessageLibrary.BrowserEventType.Keyboard
                };

                _outCommServer.WriteMessage(ep);
            }
        }
Ejemplo n.º 22
0
        public static void MakeKeyEvent(int vkCode, KeyboardEventType type)
        {
            switch (type)
            {
            case KeyboardEventType.KEYDOWN:
                keybd_event((byte)vkCode, 0x00, 0x00, 0);
                break;

            case KeyboardEventType.KEYUP:
                keybd_event((byte)vkCode, 0x00, 0x02, 0);
                break;

            case KeyboardEventType.KEYCLICK:
                keybd_event((byte)vkCode, 0x00, 0x00, 0);
                keybd_event((byte)vkCode, 0x00, 0x02, 0);
                break;
            }
        }
Ejemplo n.º 23
0
        public static void MakeKeyEvent(Keys vkCode, KeyboardEventType type)
        {
            switch (type)
            {
            case KeyboardEventType.KEYDOWN:
                WinAPI.Keybd_event((byte)vkCode, 0x00, 0x00, 0);
                break;

            case KeyboardEventType.KEYUP:
                WinAPI.Keybd_event((byte)vkCode, 0x00, 0x02, 0);
                break;

            case KeyboardEventType.KEYCLICK:
                WinAPI.Keybd_event((byte)vkCode, 0x00, 0x00, 0);
                WinAPI.Keybd_event((byte)vkCode, 0x00, 0x02, 0);
                break;
            }
        }
Ejemplo n.º 24
0
        private void OnKeyUpDownEvent(KeyboardEventType eventType, KeyEventArgs args)
        {
            DateTime timestamp;

            if (args is KeyEventArgsExt)
            {
                var argsExt = (KeyEventArgsExt)args;

                timestamp = _ticksConverter.Convert(argsExt.Timestamp);
            }
            else
            {
                timestamp = DateTime.Now;
            }

            var eventData = new KeyboardEventData(eventType, args.Alt, args.Control, (Key)args.KeyCode, (Key)args.KeyData, args.KeyValue, args.Shift, (char)0, timestamp);

            Data?.Invoke(this, eventData);
        }
Ejemplo n.º 25
0
        public void KeyboardEvent(int character, KeyboardEventType type)
        {
            CefKeyEvent keyEvent = new CefKeyEvent()
            {
                EventType      = CefKeyEventType.Char,
                WindowsKeyCode = character
            };

            if (type == KeyboardEventType.Down)
            {
                keyEvent.EventType = CefKeyEventType.KeyDown;
            }
            if (type == KeyboardEventType.Up)
            {
                keyEvent.EventType = CefKeyEventType.KeyUp;
            }

            _lifespanHandler.MainBrowser.GetHost().SendKeyEvent(keyEvent);
        }
Ejemplo n.º 26
0
        public override void KeyboardEvent(KeyboardEventType down, KeyEventArgs args)
        {
            if (down != KeyboardEventType.Up)
            {
                return;
            }
            if (args.KeyCode == Keys.Back)
            {
                if (Text.Length > 0)
                {
                    Text = Text.Substring(0, Text.Length - 1);
                }
            }
            else
            {
                Text += args.KeyCode;
            }

            base.KeyboardEvent(down, args);
        }
Ejemplo n.º 27
0
 public bool HandleKeyboardEvent(KeyboardEventType type, WinKeys key, bool shift, bool alt, bool ctrl)
 {
     foreach (InputEvent e in m_EventsThisFrame)
     {
         if (!e.Handled && e is InputEventKeyboard)
         {
             InputEventKeyboard ek = (InputEventKeyboard)e;
             if (ek.EventType == type &&
                 ek.KeyCode == key &&
                 ek.Shift == shift &&
                 ek.Alt == alt &&
                 ek.Control == ctrl)
             {
                 e.Handled = true;
                 return(true);
             }
         }
     }
     return(false);
 }
        /// <summary> Adds an action that should occur when the key is down. </summary>
        /// <param name="type"> The type of keyboard event that causes the action to be invoked. </param>
        /// <param name="key"> The key that should be checked. </param>
        /// <param name="action"> The action to perform if the key is down. </param>
        public void Add(KeyboardEventType type, KeyCode key, Action action)
        {
            switch (type)
            {
            case KeyboardEventType.Down:
                _actions.Add(new KeyDownAction(key, action));
                break;

            case KeyboardEventType.ToggleDown:
                _actions.Add(new KeyPressAction(key, action));
                break;

            case KeyboardEventType.ToggleUp:
                _actions.Add(new KeyReleaseAction(key, action));
                break;

            default:
                throw new ArgumentOutOfRangeException("type", type, null);
            }
        }
Ejemplo n.º 29
0
        void ProcessKeyEvent(KeyboardEventType state, bool repeat, byte keyCode, char character)
        {
            switch (state)
            {
            case KeyboardEventType.KeyDown:
                if (!repeat)
                {
                    InputSystem.QueueStateEvent(RemoteKeyboard, new KeyboardState((Key)keyCode));
                }
                if (character != 0)
                {
                    InputSystem.QueueTextEvent(RemoteKeyboard, character);
                }
                break;

            case KeyboardEventType.KeyUp:
                InputSystem.QueueStateEvent(RemoteKeyboard, new KeyboardState());
                break;
            }
        }
Ejemplo n.º 30
0
        public bool SnapshotOnKeyboardEvent(KeyboardEventType evt, Keys key)
        {
            bool snap = false;

            if (evt == KeyboardEventType.KeyDown)
            {
                if (key == Keys.Enter || key == Keys.Delete)
                {
                    if (DateTime.Now.Subtract(_lastKeyTime).Milliseconds > 1000)
                    {
                        snap = true;
                    }
                    else
                    {
                        if (!_isLastEventFromKeyboard || key != _lastKeyValue)
                        {
                            snap = true;
                        }
                    }
                }
                else                 // General Key
                {
                    if (!_isLastEventFromKeyboard && DateTime.Now.Subtract(_prevGeneralKeyTime).TotalMilliseconds > 1000)
                    {
                        snap = true;
                        _prevGeneralKeyTime = DateTime.Now;
                    }
                    if (DateTime.Now.Subtract(_prevGeneralKeyTime).TotalMilliseconds > 10 * 1000)
                    {
                        snap = true;
                        _prevGeneralKeyTime = DateTime.Now;
                    }
                }
                _isLastEventFromKeyboard = true;
                _lastKeyTime             = DateTime.Now;
                _lastKeyValue            = key;
            }
            TraceLogger.Instance.WriteLineInfo("SnapshotOnKeyboardEvent: " + snap.ToString());
            return(snap);
        }
Ejemplo n.º 31
0
        void ProcessKeyEvent(KeyboardEventType state, bool repeat, byte keyCode, char character)
        {
            switch (state)
            {
            case KeyboardEventType.KeyDown:
                if (!repeat)
                {
                    m_keyboardState.Set((Key)keyCode, true);
                    UnityInputSystem.QueueStateEvent(RemoteKeyboard, m_keyboardState);
                }
                if (character != 0)
                {
                    UnityInputSystem.QueueTextEvent(RemoteKeyboard, character);
                }
                break;

            case KeyboardEventType.KeyUp:
                m_keyboardState.Set((Key)keyCode, false);
                UnityInputSystem.QueueStateEvent(RemoteKeyboard, m_keyboardState);
                break;
            }
        }
Ejemplo n.º 32
0
        public static void SendKey(KeyboardEventType type, KeyCode key)
        {
#if WINDOWS_OS
            WindowInput[] inputs = new WindowInput[]
            {
                new WindowInput()
                {
                    type = (int)WindowInputType.Keyboard,
                    u    = new WindowInputMessage()
                    {
                        ki = new WindowKeyboardInput()
                        {
                            wVk         = 0,
                            wScan       = (ushort)key.ToScanCode(),
                            dwFlags     = (uint)(type.ToWindowsKeyEvent() | KeyEventF.Scancode),
                            dwExtraInfo = GetMessageExtraInfo()
                        }
                    }
                }
            };
            SendInput(1, inputs, Marshal.SizeOf <WindowInput>());
#endif
        }
Ejemplo n.º 33
0
 internal KeyboardEvent(KeyboardEventType eventType, Key key, int platformKeyCode)
 {
     Key = key;
     PlatformKeyCode = platformKeyCode;
     EventType = eventType;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Converts the keyboard event type, the key, and the modifier keys' information 
        /// to an array of bytes so that it can be sent over the network.
        /// </summary>
        /// <param name="type">Press, Release, or Type</param>
        /// <param name="key">The key</param>
        /// <param name="modifier">A struct that indicates whether any of the modifier 
        /// keys are held down</param>
        /// <returns></returns>
        public byte[] GetNetworkData(KeyboardEventType type, Keys key, KeyModifier modifier)
        {
            // 1 byte for type, 1 byte for key, and 1 (bool) * 3 bytes for modifier
            byte[] data = new byte[5];

            data[0] = (byte)type;
            data[1] = (byte)key;
            data[2] = BitConverter.GetBytes(modifier.AltKeyPressed)[0];
            data[3] = BitConverter.GetBytes(modifier.CtrlKeyPressed)[0];
            data[4] = BitConverter.GetBytes(modifier.ShiftKeyPressed)[0];

            return data;
        }
Ejemplo n.º 35
0
 internal void ReceiveKeyboardEvent(KeyboardEventType ke)
 {
     switch (ke)
     {
         case KeyboardEventType.Down:
             m_InInitialRepeatPeriod = true;
             m_State = ActionState.Press;
             m_SecondsSincePress = 0f;
             break;
         case KeyboardEventType.Up:
             m_State = ActionState.Release;
             break;
         // ignore press events - we handle our own presses.
     }
 }
Ejemplo n.º 36
0
 public bool HandleKeyboardEvent(KeyboardEventType type, WinKeys key, bool shift, bool alt, bool ctrl)
 {
     foreach(InputEvent e in m_EventsThisFrame)
     {
         if(!e.Handled && e is InputEventKeyboard)
         {
             InputEventKeyboard ek = (InputEventKeyboard)e;
             if(ek.EventType == type &&
                ek.KeyCode == key &&
                ek.Shift == shift &&
                ek.Alt == alt &&
                ek.Control == ctrl)
             {
                 e.Handled = true;
                 return true;
             }
         }
     }
     return false;
 }