private void DriverCallback() { InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode); Stroke stroke = new Stroke(); int deviceId = 0; while (InterceptionDriver.Receive(context, deviceId = InterceptionDriver.Wait(context), ref stroke, 1) > 0) { if (InterceptionDriver.IsMouse(deviceId) > 0) { mouseDeviceId = deviceId; if (OnMousePressed != null) { Log.Debug(TAG, "Mouse Device Detected:[" + deviceId + "] x:" + stroke.Mouse.X + ",y:" + stroke.Mouse.Y + " tag:" + stroke.Mouse.Flags + " state:" + stroke.Mouse.State); var args = new MousePressedEventArgs() { X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling }; OnMousePressed(this, args); if (args.Handled) { continue; } stroke.Mouse.X = args.X; stroke.Mouse.Y = args.Y; stroke.Mouse.State = args.State; stroke.Mouse.Rolling = args.Rolling; } } if (InterceptionDriver.IsKeyboard(deviceId) > 0) { keyboardDeviceId = deviceId; if (OnKeyPressed != null) { Log.Debug(TAG, "Keyboard Device Detected:[" + deviceId + "]"); var args = new KeyPressedEventArgs() { Key = stroke.Key.Code, State = stroke.Key.State }; OnKeyPressed(this, args); if (args.Handled) { continue; } stroke.Key.Code = args.Key; stroke.Key.State = args.State; } } InterceptionDriver.Send(context, deviceId, ref stroke, 1); } Unload(); throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded."); }
private void DriverCallback() { InterceptionDriver.SetFilter(Context, InterceptionDriver.IsKeyboard, (int)KeyboardFilterMode); InterceptionDriver.SetFilter(Context, InterceptionDriver.IsMouse, (int)MouseFilterMode); Stroke stroke = new Stroke(); while (InterceptionDriver.Receive(Context, DeviceID = InterceptionDriver.Wait(Context), ref stroke, 1) > 0) { if (InterceptionDriver.IsMouse(DeviceID) > 0 && OnMousePressed != null) { MousePressedEventArgs args = new MousePressedEventArgs() { X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling }; OnMousePressed(this, args); if (args.Handled) { continue; } stroke.Mouse.X = args.X; stroke.Mouse.Y = args.Y; stroke.Mouse.State = args.State; stroke.Mouse.Rolling = args.Rolling; } else if (InterceptionDriver.IsKeyboard(DeviceID) > 0 && OnKeyPressed != null) { KeyPressedEventArgs args = new KeyPressedEventArgs() { DeviceID = DeviceID, Key = stroke.Key.Code, State = stroke.Key.State }; OnKeyPressed(this, args); if (args.Handled) { continue; } stroke.Key.Code = args.Key; stroke.Key.State = args.State; InterceptionDriver.Send(Context, args.DeviceID, ref stroke, 1); } else { InterceptionDriver.Send(Context, DeviceID, ref stroke, 1); } } Unload(); throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded."); }
private void DriverCallback() { InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32) KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32) MouseFilterMode); Stroke stroke = new Stroke(); while (InterceptionDriver.Receive(context, deviceId = InterceptionDriver.Wait(context), ref stroke, 1) > 0) { if (InterceptionDriver.IsMouse(deviceId) > 0) { if (OnMousePressed != null) { var args = new MousePressedEventArgs() { X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling }; OnMousePressed(this, args); if (args.Handled) { continue; } stroke.Mouse.X = args.X; stroke.Mouse.Y = args.Y; stroke.Mouse.State = args.State; stroke.Mouse.Rolling = args.Rolling; } } if (InterceptionDriver.IsKeyboard(deviceId) > 0) { if (OnKeyPressed != null) { var args = new KeyPressedEventArgs() { Key = stroke.Key.Code, State = stroke.Key.State}; OnKeyPressed(this, args); if (args.Handled) { continue; } stroke.Key.Code = args.Key; stroke.Key.State = args.State; } } InterceptionDriver.Send(context, deviceId, ref stroke, 1); } Unload(); throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded."); }
private void DriverCallback() { InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32) KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32) MouseFilterMode); Stroke stroke = new Stroke(); var isShiftPressed = false; while (InterceptionDriver.Receive(context, deviceId = InterceptionDriver.Wait(context), ref stroke, 1) > 0) { if (InterceptionDriver.IsMouse(deviceId) > 0) { if (OnMousePressed != null) { var args = new MousePressedEventArgs() { X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling }; OnMousePressed(this, args); if (args.Handled) { continue; } stroke.Mouse.X = args.X; stroke.Mouse.Y = args.Y; stroke.Mouse.State = args.State; stroke.Mouse.Rolling = args.Rolling; } } if (InterceptionDriver.IsKeyboard(deviceId) > 0) { if (OnKeyPressed != null) { var hardwareIdBuffer = new byte[500]; var length = InterceptionDriver.GetHardwareId(context, deviceId, hardwareIdBuffer, 500); var hardwareId = ""; var nullCount = 0; for (var i = 0; i < length; i++) { if (hardwareIdBuffer[i] == 0) { nullCount++; continue; } if (nullCount > 2) { hardwareId += "; "; } nullCount = 0; hardwareId += (char)hardwareIdBuffer[i]; } //If you need to get capital letters then be sure to have KeyboardFilterMode.All set and only get KeyState.Down codes var isCapsLockOn = Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock); if (stroke.Key.Code == Keys.LeftShift || stroke.Key.Code == Keys.RightShift) isShiftPressed = stroke.Key.State == KeyState.Down; var asciiKeyCode = (int)KeyEnumToCharacter(stroke.Key.Code, isCapsLockOn, isShiftPressed); var args = new KeyPressedEventArgs() { Key = stroke.Key.Code, State = stroke.Key.State, HardwareId = hardwareId, AsciiKeyCode = asciiKeyCode }; OnKeyPressed?.Invoke(this, args); if (args.Handled) { continue; } stroke.Key.Code = args.Key; stroke.Key.State = args.State; } } InterceptionDriver.Send(context, deviceId, ref stroke, 1); } Unload(); throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded."); }
private void DriverCallback() { #if OLD_API InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode); #else switch (FilterType) { case FilterType.Whitelist: InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboardWhitelist, (Int32)KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouseWhitelist, (Int32)MouseFilterMode); break; case FilterType.Blacklist: InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboardBlacklist, (Int32)KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouseBlacklist, (Int32)MouseFilterMode); break; default: InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode); break; } #endif Stroke stroke = new Stroke(); while (InterceptionDriver.Receive(context, deviceId = InterceptionDriver.Wait(context), ref stroke, 1) > 0) { if (InterceptionDriver.IsMouse(deviceId) > 0) { if (OnMouseAction != null) { var args = new MousePressedEventArgs(deviceId) { X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling, DeviceId = deviceId, DeviceName = GetDeviceName(deviceId) }; OnMouseAction(this, args); if (args.Handled) { continue; } stroke.Mouse.X = args.X; stroke.Mouse.Y = args.Y; stroke.Mouse.State = args.State; stroke.Mouse.Rolling = args.Rolling; } } if (InterceptionDriver.IsKeyboard(deviceId) > 0) { if (OnKeyPressed != null) { var virtualKey = (VirtualKeys)MapVirtualKey((uint)stroke.Key.Code, 1); if (virtualKey > VirtualKeys.Left && virtualKey < VirtualKeys.Down && !stroke.Key.State.HasFlag(KeyState.E0)) { switch (virtualKey) { case VirtualKeys.Left: virtualKey = VirtualKeys.N4; break; case VirtualKeys.Right: virtualKey = VirtualKeys.N6; break; case VirtualKeys.Up: virtualKey = VirtualKeys.N8; break; case VirtualKeys.Down: virtualKey = VirtualKeys.N2; break; } } var args = new KeyPressedEventArgs() { Key = virtualKey, State = stroke.Key.State, DeviceId = deviceId, DeviceName = GetDeviceName(deviceId) }; OnKeyPressed(this, args); if (args.Handled) { continue; } stroke.Key.State = args.State; } } InterceptionDriver.Send(context, deviceId, ref stroke, 1); } Unload(); throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded."); }
private void DriverCallback() { InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode); InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode); Stroke stroke = new Stroke(); int deviceId = -1; while (InterceptionDriver.Receive(context, deviceId = InterceptionDriver.Wait(context), ref stroke, 1) > 0) { if (InterceptionDriver.IsMouse(deviceId) > 0) { if (deviceId != mouseDeviceId) { mouseDeviceId = deviceId; this.debug("Mouse device detected. Id updated to " + mouseDeviceId); } if (OnMousePressed != null) { var args = new MousePressedEventArgs() { DeviceId = deviceId, X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling }; OnMousePressed(this, args); if (args.Handled) { continue; } stroke.Mouse.X = args.X; stroke.Mouse.Y = args.Y; stroke.Mouse.State = args.State; stroke.Mouse.Rolling = args.Rolling; } } if (InterceptionDriver.IsKeyboard(deviceId) > 0) { if (deviceId != keyboardDeviceId) { keyboardDeviceId = deviceId; this.debug("Keyboard device detected. Id updated to " + keyboardDeviceId); } if (OnKeyPressed != null) { var args = new KeyPressedEventArgs() { DeviceId = deviceId, Key = stroke.Key.Code, State = stroke.Key.State }; OnKeyPressed(this, args); if (args.Handled) { continue; } stroke.Key.Code = args.Key; stroke.Key.State = args.State; } } InterceptionDriver.Send(context, deviceId, ref stroke, 1); } Unload(); throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded."); }