internal static extern bool DeviceIoControl(
     SafeFileHandle hDevice,
     EIOControlCode IoControlCode,
     ref INJECT_MOUSE_MOVEMENT_INPUT_REQUEST InBuffer,
     int nInBufferSize,
     ref INJECT_MOUSE_MOVEMENT_INPUT_REQUEST OutBuffer,
     int nOutBufferSize,
     out uint pBytesReturned,
     IntPtr Overlapped
     );
Beispiel #2
0
        public bool InjectMouseMovementInput(ulong processId, ushort indicatorFlags, int movementX, int movementY)
        {
            if (driverHandle == null)
            {
                throw new Exception(
                          "Driver handle is null. Is the driver running and have you called Init() function?");
            }

            INJECT_MOUSE_MOVEMENT_INPUT_REQUEST Request = new INJECT_MOUSE_MOVEMENT_INPUT_REQUEST();

            Request.ProcessId      = (IntPtr)processId;
            Request.IndicatorFlags = indicatorFlags;
            Request.MovementX      = movementX;
            Request.MovementY      = movementY;

            uint dummy = 0;

            bool status = MouMoveIo.DeviceIoControl(
                driverHandle,
                EIOControlCode.IOCTL_INJECT_MOUSE_MOVEMENT_INPUT,
                ref Request,
                Marshal.SizeOf(Request),
                ref Request,
                0,
                out dummy,
                IntPtr.Zero
                );

            if (status)
            {
                Console.WriteLine("SUCCESS");
            }
            else
            {
                Console.WriteLine("Failed");
                Console.WriteLine(Connector.GetLastError());
            }
            return(status);
        }