예제 #1
0
 public void KeyPress(KeyboardKey key = new KeyboardKey(), KeyboardModifier modikey = new KeyboardModifier(), int Intervals1 = 20, int Intervals2 = 20)
 {
     KeyDown(key, modikey);
     System.Threading.Thread.Sleep(Intervals1);
     KeyUp(key, modikey);
     System.Threading.Thread.Sleep(Intervals2);
 }
예제 #2
0
        /// <summary>
        /// Just use normal routine
        /// </summary>
        /// <param name="key"></param>
        public override void PerformKeyReleaseAlt(uint key)
        {
            //Console.WriteLine("PerformKeyReleaseAlt {0}", key);
            eventLock.EnterWriteLock();

            if (key < MODIFIER_MASK)
            {
                KeyboardKey temp = (KeyboardKey)key;
                if (pressedKeys.Contains(temp))
                {
                    keyReport.KeyUp(temp);
                    pressedKeys.Remove(temp);
                    syncKeyboard = true;
                }
            }
            else if (key < MODIFIER_ENHANCED)
            {
                KeyboardModifier modifier = (KeyboardModifier)(key & ~MODIFIER_MASK);
                if (modifiers.Contains(modifier))
                {
                    keyReport.KeyUp(modifier);
                    modifiers.Remove(modifier);
                    syncKeyboard = true;
                }
            }
            else
            {
                EnhancedKey temp = (EnhancedKey)(key & ~MODIFIER_ENHANCED);
                mediaKeyReport.KeyUp(temp);
                syncEnhancedKeyboard = true;
            }

            eventLock.ExitWriteLock();
        }
예제 #3
0
        public void Update(KeyboardState currentKeyboardState)
        {
            if (_requiresUpdate)
            {
                _lastKeyList = _newKeyList;
                _newKeyList  = currentKeyboardState.GetPressedKeys();

                StripUnmanagedKeys(ref _newKeyList);

                if (!TreatModifiersAsKeys)
                {
                    LastModifiers = NewModifiers;
                    NewModifiers  = _newKeyList.GetModifiers();
                    StripModifiers(ref _newKeyList);
                }

                NewKeyDelta = _newKeyList.Except(_lastKeyList).ToList();

                if (NewKeyDelta.Any())
                {
                    FocusKey = NewKeyDelta.First();
                }
                else if (_lastKeyList.Except(_newKeyList).Any())
                {
                    FocusKey = Keys.None;
                }
            }
        }
예제 #4
0
        /// <summary>
        ///     convert the current key into a printable string.  If users want to force upper case or lower case they can change
        ///     modifiers m (for example, to enable use of the caps lock key, test it outside the function, if its on pass in a
        ///     kbmodifiers with shift flag, if off pass KeyboardModifier.None)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="keyboardModifier"></param>
        /// <param name="selectspecials">filters so that specials are included in the string if true</param>
        /// <param name="selectAlphas">filters so that alphas are selected if true</param>
        /// <param name="selectNumerics">filters so that numerics are selected if true </param>
        /// <param name="suppressSpace">no spaces are output</param>
        /// <param name="treatNumpadAsNumeric">treat numpad as numeric keys</param>
        /// <returns></returns>
        public static string Display(this Keys key, KeyboardModifier keyboardModifier, bool selectspecials, bool selectAlphas,
                                     bool selectNumerics, bool suppressSpace, bool treatNumpadAsNumeric = true)
        {
            if (IsKeySpace(key) && !suppressSpace)
            {
                return(" ");
            }

            if ((IsKeyAlpha(key) && selectAlphas) ||
                (IsKeyNumber(key) && selectNumerics) ||
                (treatNumpadAsNumeric && IsKeyNumberpad(key) && selectNumerics) ||
                (selectspecials &&
                 ((!IsKeyAlpha(key) && !IsKeyNumeric(key)) ||
                  (IsKeyNumber(key) && IsShiftDown(keyboardModifier)))))
            {
                if (IsShiftDown(keyboardModifier))
                {
                    if (!(!selectspecials && IsKeyNumber(key)))
                    {
                        return(shiftedKeys[key.GetHashCode()]);
                    }
                }
                else
                {
                    return(unshiftedKeys[key.GetHashCode()]);
                }
            }

            return("");
        }
예제 #5
0
        public static void StartTrace()
        {
            Console.WriteLine("******************** ETW Keylogger ********************");

            if (TraceEventSession.IsElevated() != true)
            {
                Console.WriteLine("Must be Admin to run this utility.");
                Debugger.Break();
                return;
            }

            Console.WriteLine("Press Ctrl-C to stop monitoring.");

            using (var userSession = new TraceEventSession("ObserveEventSource"))
            {
                userSession.StopOnDispose = true;
                // Set up Ctrl-C to stop trace sessions
                SetupCtrlCHandler(() =>
                {
                    userSession?.Stop();
                });

                using (var source = new ETWTraceEventSource("ObserveEventSource", TraceEventSourceType.Session))
                {
                    var usb2EventParser = new DynamicTraceEventParser(source);

                    usb2EventParser.All += delegate(TraceEvent data)
                    {
                        byte[] usbPayload = null;
                        if (data.EventData().Length >= 243)
                        {
                            usbPayload = data.EventData().Skip(115).ToArray();
                            var message = new USBMessage(usbPayload);
                            if (message.Header.Length >= 128 && message.BulkOrInterrupt.Payload != null)
                            {
                                if (ValidatePayload(message.BulkOrInterrupt.Payload))
                                {
                                    try
                                    {
                                        KeyboardKeymap   key      = (KeyboardKeymap)message.BulkOrInterrupt.Payload[(byte)PayloadKeys.KeyCode];
                                        KeyboardModifier modifier = (KeyboardModifier)message.BulkOrInterrupt.Payload[(byte)PayloadKeys.Modifier];
                                        Console.WriteLine($"Key modifier: {modifier} - Key pressed: {key} ");
                                        Console.WriteLine(BitConverter.ToString(message.BulkOrInterrupt.Payload));
                                    }
                                    catch (Exception)
                                    {
                                        Console.WriteLine("Can't decode keypress");
                                    }
                                }
                            }
                        }
                    };

                    userSession.EnableProvider(USB2_PROVIDERNAME);
                    userSession.EnableProvider(USB3_PROVIDERNAME);

                    source.Process();
                }
            }
        }
예제 #6
0
        public static bool IsShiftDown(this KeyboardModifier keyboardModifier)
        {
            if ((KeyboardModifier.Shift & keyboardModifier) == KeyboardModifier.Shift)
            {
                return(true);
            }

            return(false);
        }
예제 #7
0
        public void WriteTextToTextbox(Keys focus, KeyboardModifier keyboardModifier)
        {
            _keyboardLabels[KeyboardLabelTypes.RunningKeys].Text += focus.Display(keyboardModifier);

            if ((focus == Keys.Back) && (_keyboardLabels[KeyboardLabelTypes.RunningKeys].Text.Length > 22))
            {
                _keyboardLabels[KeyboardLabelTypes.RunningKeys].Text = _keyboardLabels[KeyboardLabelTypes.RunningKeys].Text.Remove(_keyboardLabels[KeyboardLabelTypes.RunningKeys].Text.Length - 1, 1);
            }
        }
예제 #8
0
 public void KeyUp(KeyboardKey key = new KeyboardKey(), KeyboardModifier modikey = new KeyboardModifier())
 {
     if (key != 0)
     {
         report.keyUp(key);
     }
     if (modikey != 0)
     {
         report.keyUp(modikey);
     }
     Variable_Internal.vmulti.updateKeyboard(report);
 }
예제 #9
0
파일: Menu.cs 프로젝트: s520/OpenBVE
 //
 // SET CONTROL CUSTOM DATA
 //
 internal void SetControlKbdCustomData(Key key, KeyboardModifier keybMod)
 {
     //Check that we are customising a key, and that our key is NOT the menu back key
     if (isCustomisingControl && key != MenuBackKey && CustomControlIdx < Interface.CurrentControls.Length)
     {
         Interface.CurrentControls[CustomControlIdx].Method   = ControlMethod.Keyboard;
         Interface.CurrentControls[CustomControlIdx].Key      = key;
         Interface.CurrentControls[CustomControlIdx].Modifier = keybMod;
         Interface.SaveControls(null, Interface.CurrentControls);
     }
     PopMenu();
     isCustomisingControl = false;
 }
예제 #10
0
        //Press the specified modifier and key, and optionally leave them held down.
        public void SendKey(KeyboardModifier modifier, KeyboardKey key, bool sendClear)
        {
            var data = new byte[8];

            data[0] = (byte)modifier;
            data[2] = (byte)key;
            _SendKeypressData(data);

            if (sendClear)
            {
                ClearKeypresses();
            }
        }
예제 #11
0
        public bool setButtonUp(string key)
        {
            if (Enum.IsDefined(typeof(KeyboardKey), key.ToUpper()))
            {
                KeyboardKey theKeyCode = (KeyboardKey)Enum.Parse(typeof(KeyboardKey), key, true);
                report.keyUp(theKeyCode);
                return(true);
            }
            else if (Enum.IsDefined(typeof(KeyboardModifier), key.ToUpper()))
            {
                KeyboardModifier theKeyCode = (KeyboardModifier)Enum.Parse(typeof(KeyboardModifier), key, true);
                report.keyUp(theKeyCode);
                return(true);
            }
            else if (Enum.IsDefined(typeof(VirtualKeyCode), key.ToUpper()))
            {
                VirtualKeyCode theKeyCode = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), key, true);

                Enum vmultiKey = VmultiKeycodeAdapter.ConvertVirtualKeyCode(theKeyCode);

                if (vmultiKey == null)
                {
                    this.inputSimulator.Keyboard.KeyUp(theKeyCode);
                    return(true);
                }

                if (vmultiKey is KeyboardKey)
                {
                    KeyboardKey keyboardKey = (KeyboardKey)vmultiKey;
                    report.keyUp(keyboardKey);
                    return(true);
                }

                if (vmultiKey is KeyboardModifier)
                {
                    KeyboardModifier keyboardModifier = (KeyboardModifier)vmultiKey;
                    report.keyUp(keyboardModifier);
                    return(true);
                }
            }
            return(false);
        }
예제 #12
0
 public void WriteCurrentKeysToTextbox(Keys[] keyList, KeyboardModifier keyboardModifier)
 {
     // Note - sometimes more than 2 keys wont register.  See this for explanation of keyboard hardware limitations:
     // http://blogs.msdn.com/shawnhar/archive/2007/03/28/keyboards-suck.aspx
     _keyboardLabels[KeyboardLabelTypes.Example].Text = "Current Keys: ";
     foreach (var k in keyList)
     {
         _keyboardLabels[KeyboardLabelTypes.Example].Text += k.ToString();
     }
     if ((KeyboardModifier.Alt & keyboardModifier) == KeyboardModifier.Alt)
     {
         _keyboardLabels[KeyboardLabelTypes.Example].Text += " +Alt ";
     }
     if ((KeyboardModifier.Shift & keyboardModifier) == KeyboardModifier.Shift)
     {
         _keyboardLabels[KeyboardLabelTypes.Example].Text += " +Shift ";
     }
     if ((KeyboardModifier.Ctrl & keyboardModifier) == KeyboardModifier.Ctrl)
     {
         _keyboardLabels[KeyboardLabelTypes.Example].Text += " +Ctrl ";
     }
 }
예제 #13
0
 public void HandleKeyboardKeyRepeat(Keys repeatingKey, KeyboardModifier keyboardModifier)
 {
     _keyboardLabels[KeyboardLabelTypes.KeyRepeat].Activate();
     WriteTextToTextbox(repeatingKey, keyboardModifier);
 }
예제 #14
0
 //Press the specified modifier and key.
 public void SendKey(KeyboardModifier modifier, KeyboardKey key)
 {
     SendKey(modifier, key, true);
 }
예제 #15
0
 //Press the specified modifier key, and optionally leave it held down.
 public void SendModifier(KeyboardModifier modifier, bool sendClear)
 {
     SendKey(modifier, KeyboardKey.None, sendClear);
 }
예제 #16
0
 public void HandleKeyboardKeyLost(Keys[] keysDown, KeyboardModifier keyboardModifier)
 {
     _keyboardLabels[KeyboardLabelTypes.KeyLost].HighlightRed(_realTimer);
     WriteCurrentKeysToTextbox(keysDown, keyboardModifier);
 }
예제 #17
0
 /// <summary>
 ///     convert the current key into a printable string.  Defaults to alphanumerics on and and accounts for shift key
 /// </summary>
 /// <param name="key"></param>
 /// <param name="keyboardModifier"></param>
 /// <param name="selectspecials"></param>
 /// <returns></returns>
 public static string Display(this Keys key, KeyboardModifier keyboardModifier, bool selectspecials)
 {
     return(Display(key, keyboardModifier, selectspecials, true, true, false));
 }
예제 #18
0
 public static bool IsCtrlDown(this KeyboardModifier keyboardModifier)
 {
     return((KeyboardModifier.Ctrl & keyboardModifier) == KeyboardModifier.Ctrl);
 }
예제 #19
0
 //Press the specified modifier and key.
 public void SendKey(KeyboardModifier modifier, KeyboardKey key)
 {
     SendKey(modifier, key, true);
 }
예제 #20
0
 //Press the specified modifier key, and optionally leave it held down.
 public void SendModifier(KeyboardModifier modifier, bool sendClear)
 {
     SendKey(modifier, KeyboardKey.None, sendClear);
 }
예제 #21
0
 //Press the specified modifier key.
 public void SendModifier(KeyboardModifier modifier)
 {
     SendKey(modifier, KeyboardKey.None);
 }
예제 #22
0
 /// <summary>
 ///     convert the current key into a printable string.  Defaults to any kind of printable character and accounts for
 ///     shift key.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="keyboardModifier"></param>
 /// <returns></returns>
 public static string Display(this Keys key, KeyboardModifier keyboardModifier)
 {
     return(Display(key, keyboardModifier, true, true, true, false));
 }
예제 #23
0
        //Press the specified modifier and key, and optionally leave them held down.
        public void SendKey(KeyboardModifier modifier, KeyboardKey key, bool sendClear)
        {
            var data = new byte[8];
              data[0] = (byte)modifier;
              data[2] = (byte)key;
              _SendKeypressData(data);

              if (sendClear)
            ClearKeypresses();
        }
예제 #24
0
 /// <summary>
 ///     convert the current key into a printable string given filtering options. Defaults to spaces allowed
 /// </summary>
 /// <param name="key"></param>
 /// <param name="keyboardModifier"></param>
 /// <param name="selectspecials">filters so that specials are included in the string if true</param>
 /// <param name="selectAlphas">filters so that alphas are selected if true</param>
 /// <param name="selectNumerics">filters so that numerics are selected if true </param>
 /// <returns></returns>
 public static string Display(this Keys key, KeyboardModifier keyboardModifier, bool selectspecials, bool selectAlphas,
                              bool selectNumerics)
 {
     return(Display(key, keyboardModifier, selectspecials, selectAlphas, selectNumerics, false));
 }
예제 #25
0
 protected static extern IntPtr qt_keyevent_new(EventType type, int key, KeyboardModifier modifiers, string text, bool autorep, ushort count);
예제 #26
0
 protected static extern IntPtr qt_keyevent_native_new(EventType type, int key, KeyboardModifier modifiers, UInt32 nativeScanCode, UInt32 nativeVirtualKey, UInt32 nativeModifiers, string text, bool autorep, ushort count);
예제 #27
0
 //Press the specified modifier key.
 public void SendModifier(KeyboardModifier modifier)
 {
     SendKey(modifier, KeyboardKey.None);
 }
예제 #28
0
 public static bool IsAltDown(this KeyboardModifier keyboardModifier)
 {
     return((KeyboardModifier.Alt & keyboardModifier) == KeyboardModifier.Alt);
 }
예제 #29
0
 public void keyDown(KeyboardModifier modifier)
 {
     modifiers.Add(modifier);
 }
예제 #30
0
 protected static extern void qt_inputevent_modifiers_set(IntPtr raw, KeyboardModifier modifier);
예제 #31
0
 public void keyUp(KeyboardModifier modifier)
 {
     modifiers.Remove(modifier);
 }
예제 #32
0
 public KeyEvent(EventType type, int key, KeyboardModifier modifiers, string text = "", bool autorep = false, ushort count = 1)
     : base(IntPtr.Zero)
 {
     Handle = qt_keyevent_new(type, key, modifiers, text, autorep, count);
 }
예제 #33
0
 public void KeyDown(KeyboardModifier modifier)
 {
     modifiers.Add(modifier);
 }
예제 #34
0
 public KeyEvent(EventType type, int key, KeyboardModifier modifiers, UInt32 nativeScanCode, UInt32 nativeVirtualKey, UInt32 nativeModifiers, string text = "", bool autorep = false, ushort count = 1)
     : base(IntPtr.Zero)
 {
     Handle = qt_keyevent_native_new(type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
 }
예제 #35
0
 public void KeyUp(KeyboardModifier modifier)
 {
     modifiers.Remove(modifier);
 }