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); }
/// <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(); }
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; } } }
/// <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(""); }
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(); } } }
public static bool IsShiftDown(this KeyboardModifier keyboardModifier) { if ((KeyboardModifier.Shift & keyboardModifier) == KeyboardModifier.Shift) { return(true); } return(false); }
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); } }
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); }
// // 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; }
//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(); } }
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); }
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 "; } }
public void HandleKeyboardKeyRepeat(Keys repeatingKey, KeyboardModifier keyboardModifier) { _keyboardLabels[KeyboardLabelTypes.KeyRepeat].Activate(); WriteTextToTextbox(repeatingKey, keyboardModifier); }
//Press the specified modifier and key. public void SendKey(KeyboardModifier modifier, KeyboardKey key) { SendKey(modifier, key, true); }
//Press the specified modifier key, and optionally leave it held down. public void SendModifier(KeyboardModifier modifier, bool sendClear) { SendKey(modifier, KeyboardKey.None, sendClear); }
public void HandleKeyboardKeyLost(Keys[] keysDown, KeyboardModifier keyboardModifier) { _keyboardLabels[KeyboardLabelTypes.KeyLost].HighlightRed(_realTimer); WriteCurrentKeysToTextbox(keysDown, keyboardModifier); }
/// <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)); }
public static bool IsCtrlDown(this KeyboardModifier keyboardModifier) { return((KeyboardModifier.Ctrl & keyboardModifier) == KeyboardModifier.Ctrl); }
//Press the specified modifier key. public void SendModifier(KeyboardModifier modifier) { SendKey(modifier, KeyboardKey.None); }
/// <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)); }
//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(); }
/// <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)); }
protected static extern IntPtr qt_keyevent_new(EventType type, int key, KeyboardModifier modifiers, string text, bool autorep, ushort count);
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);
public static bool IsAltDown(this KeyboardModifier keyboardModifier) { return((KeyboardModifier.Alt & keyboardModifier) == KeyboardModifier.Alt); }
public void keyDown(KeyboardModifier modifier) { modifiers.Add(modifier); }
protected static extern void qt_inputevent_modifiers_set(IntPtr raw, KeyboardModifier modifier);
public void keyUp(KeyboardModifier modifier) { modifiers.Remove(modifier); }
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); }
public void KeyDown(KeyboardModifier modifier) { modifiers.Add(modifier); }
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); }
public void KeyUp(KeyboardModifier modifier) { modifiers.Remove(modifier); }