예제 #1
0
        private void OnHidEvent(object sender, HidEvent e)
        {
            if (this.HidDataReceived == null ||
                this.window == null ||
                this.window.Dispatcher == null)
            {
                return;
            }

            this.window.Dispatcher.BeginInvoke((Action) delegate
            {
                this.HidDataReceived(sender, e);
            });
        }
예제 #2
0
 public void OnHidEventRepeat(HidEvent hidEvent)
 {
     /// Generic HID repeats generated using timer go through here.
     /// Broadcast our events
     this.OnHidEvent(this, hidEvent);
 }
예제 #3
0
        /// <summary>
        /// Process a WM_INPUT message.
        /// </summary>
        /// <param name="message"></param>
        public void ProcessInput(ref Message message)
        {
            if (message.Msg != Contants.WM_INPUT)
            {
                // We only process WM_INPUT messages
                return;
            }

            var hidEvent = new HidEvent(message);

            hidEvent.DebugWrite();

            if (!hidEvent.IsValid)
            {
                Debug.WriteLine("Skipping HID message.");
                return;
            }

            /// We want to repeat only a single event at a time.
            /// Any other event will interrupt the current repeat.
            if (this.ManageRepeats && hidEvent.IsGeneric)
            {
                // Discard all outstanding repeats, though we should only ever have only one
                for (int i = this.hidEvents.Count - 1; i >= 0; i--)
                {
                    this.hidEvents[i].Dispose();
                    this.hidEvents.RemoveAt(i);
                }

                /// Add our newly created event to our repeat list
                /// TODO: instead of a list we could now have a single event since we only support one repeat at a time
                this.hidEvents.Add(hidEvent);
            }
            else if (hidEvent.IsKeyboard)
            {
                hidEvent.HasModifierShift   = !hidEvent.IsModifier && this.HasModifierShift;
                hidEvent.HasModifierControl = !hidEvent.IsModifier && this.HasModifierControl;
                hidEvent.HasModifierAlt     = !hidEvent.IsModifier && this.HasModifierAlt;
                hidEvent.HasModifierWindows = !hidEvent.IsModifier && this.HasModifierWindows;

                // We are dealing with a keyboard event
                if (hidEvent.IsButtonDown)
                {
                    HidEvent previous;
                    if (this.keyDownEvents.TryGetValue(hidEvent.KeyId, out previous))
                    {
                        /// This key is already pushed down
                        /// Increment our repeat count
                        hidEvent.RepeatCount = previous.RepeatCount + 1;

                        /// Discard our previous instance
                        previous.Dispose();
                    }

                    // Add or update our key in our dictionary
                    this.keyDownEvents[hidEvent.KeyId] = hidEvent;
                }
                else if (hidEvent.IsButtonUp)
                {
                    HidEvent previous;
                    if (this.keyDownEvents.TryGetValue(hidEvent.KeyId, out previous))
                    {
                        // Key was released just make sure we track that by removing it
                        previous.Dispose();
                        this.keyDownEvents.Remove(hidEvent.KeyId);
                    }
                }
            }

            // Broadcast our events
            // Filter out keyboard repeats unless otherwise specified.
            // Only keyboard repeats coming from drivers come through here.
            if (this.ManageRepeats || !hidEvent.IsRepeat)
            {
                this.OnHidEvent(this, hidEvent);
            }
        }