예제 #1
0
 // Let all observers know which keys are currently pressed
 // (after some activity happened).
 private void TriggerKeyActivityDetectedEvent(KeyActivity keyActivity)
 {
     EventHandler<KeyActivityEventArgs> temp = KeyActivityDetected;
      if (temp != null)
      {
     temp(this, new KeyActivityEventArgs(CurrentlyPressed, keyActivity));
      }
 }
 public KeyActivityEventArgs(IEnumerable<int> keys, KeyActivity keyActivity)
 {
     _keys = keys;
      _keyActivity = keyActivity;
 }
예제 #3
0
        /// <summary>
        /// Extracts the required key press information and triggers an event
        /// for KeyActivity.
        /// </summary>
        /// <returns>false if keyboard activity should be ignored,
        ///          true otherwise</returns>
        private bool ProcessKeyActivity(RAWKEYBOARD rawKeyboard)
        {
            ushort key = rawKeyboard.VirtualKey;

             // Skip the extra key messages for "extended keys"
             if (key >= EXTENDED_KEY_FLAG)
             {
            return false;
             }

             // Pack the correct left/right information into the key value for
             // modifier keys.
             FixModifierKeys(ref key, rawKeyboard.Flags, rawKeyboard.MakeCode);

             KeyActivity keyActivity = new KeyActivity(key, rawKeyboard.Message);

             // TODO: figure out which keyboard it came from??
             // http://www.codeproject.com/Articles/17123/
             // pass in some sort of id or whatnot into TriggerKeyActivity...
             // so that subscribers can distinguish keyboards

             // TODO: Handle the pause key better...
             if (rawKeyboard.Message == KEYINPUTTYPES.WM_KEYDOWN
             || rawKeyboard.Message == KEYINPUTTYPES.WM_SYSKEYDOWN)
             {
            // Only trigger activity for new keydown's
            if (CurrentlyPressed.Add(key))
            {
               History.Enqueue(key);
               TriggerKeyActivityDetectedEvent(keyActivity);
            }
             }
             else if (rawKeyboard.Message == KEYINPUTTYPES.WM_KEYUP
                  || rawKeyboard.Message == KEYINPUTTYPES.WM_SYSKEYUP)
             {
            CurrentlyPressed.Remove(key);

            // always trigger activity for keyup's
            TriggerKeyActivityDetectedEvent(keyActivity);
             }

             return true;
        }