在C中为Windows 10开发鼠标过滤器驱动程序

时间:2016-03-31 05:16:17

标签: c filter kernel driver mouse

我正在尝试使用C中的内核模式驱动程序(KMDF)空项目中的Visual Studios 2015创建鼠标上层过滤器驱动程序。我还使用来自GitHub的Microsoft示例驱动程序moufiltr作为一个headstart,我修改了.inf文件以便在USB鼠标上工作。

我打算在过滤器驱动程序中实现的一个功能是即使鼠标处于空闲状态而不移动,光标也应该继续沿着先前移动的方向移动。最初我曾计划使用moufiltr的回调函数来实现这个:

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->UpperConnectData.ClassService)(
        devExt->UpperConnectData.ClassDeviceObject,
        InputDataStart,
        InputDataEnd,
        InputDataConsumed
        );
}

通过修改InputDataStart中的坐标直到InputDataEnd,我可以模拟我想要的运动。然而,在测试时我意识到只有在鼠标改变位置或移动时才会调用此函数,而不是我认为每次轮询鼠标时都会调用该函数,即使它处于空闲状态。

为了解决这个问题,我开始寻找可以通过内核或Windows API分配函数的方法,这些函数将在每次轮询鼠标时调用,类似于当有数据包要处理时调用上述函数的方式。但我还没有找到关于如何做到这一点的大量文件。有没有办法做到这一点?或者我应该找到实现此功能的替代方案。

0 个答案:

没有答案