title: Developing a Mouse Filter Driver for Windows 10 in C
body: <p>I am trying to create a mouse upper-level filter driver using Visual Studios 2015 in a Kernel Mode Driver(KMDF) empty project in C. I am also using Microsoft's sample driver <code>moufiltr</code> from GitHub as a headstart, which I modified the .inf file to work on USB mice.</p>
  
  <p>A function I intend to implement in the filter driver is that even when the mouse is idle and not moving, the cursor should keep moving in the direction it was previously moving. Originally I had planned to use <code>moufiltr</code>'s callback function to implement this:</p>
  
  <pre><code>VOID
  MouFilter_ServiceCallback(
      IN PDEVICE_OBJECT DeviceObject,
      IN PMOUSE_INPUT_DATA InputDataStart,
      IN PMOUSE_INPUT_DATA InputDataEnd,
      IN OUT PULONG InputDataConsumed
      )
      /*++
  
      Routine Description:
  
      Called when there are mouse packets to report to the RIT.  You can do
      anything you like to the packets.
  
      Arguments:
  
      DeviceObject - Context passed during the connect IOCTL
  
      InputDataStart - First packet to be reported
  
      InputDataEnd - One past the last packet to be reported.  Total number of
      packets is equal to InputDataEnd - InputDataStart
  
      InputDataConsumed - Set to the total number of packets consumed by the RIT
      (via the function pointer we replaced in the connect
      IOCTL)
  
      Return Value:
  
      Status is returned.
  
      --*/
  {
      PDEVICE_EXTENSION   devExt;
      WDFDEVICE   hDevice;
  
      hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject);
  
      devExt = FilterGetData(hDevice);
  
      /*********
      My Code to modify mouse packets goes here
      *********/
  
      //
      // UpperConnectData must be called at DISPATCH
      //
      (*(PSERVICE_CALLBACK_ROUTINE)devExt-&gt;UpperConnectData.ClassService)(
          devExt-&gt;UpperConnectData.ClassDeviceObject,
          InputDataStart,
          InputDataEnd,
          InputDataConsumed
          );
  }
  </code></pre>
  
  <p>And by modifying the coordinates in InputDataStart until InputDataEnd, I could simulate the movement I had intended. However, while testing I realized that this function would only be called everytime the mouse changed position or moved, instead of what I thought that the function would be called every time the mouse was polled, even when it was idle. </p>
  
  <p>To work around this I started searching ways I could assign a function, either through the kernel or Windows API, that would be called everytime the mouse was polled instead, similar to how the above function is called when there are packets to process. But I haven't found much documentation on how I could do that. Is there a way to do this? Or should I find an alternative to implement this functionality.</p>