WDF keyboard filter driver-kbfiltr
The kbdfltr sample is an example of a keyboard input filter driver.
This sample is WDF version of the original WDM filter driver sample. The WDM version of this sample has been deprecated.
This is an upper device filter driver sample for PS/2 Keyboard. this driver layers in between the kbdclass driver and i8042prt driver and hooks the callback routine that moves keyboard inputs from the port driver to class driver. in its current state, it only hooks into the keyboard packet report chain, the keyboard initialization function, and the keyboard ISR, but does not do any processing of the data that it sees. (the hooking of the initialization function and ISR is only available in the i8042prt stack .) with additions to this current filter-only code base, the filter cocould conceivably add, remove, or modify input as needed.
This sample also creates a raw PDO and registers an interface so that applications can talk to the filter driver directly without going through the PS/2 devicestack. the reason for providing this additional interface is because the keyboard device is an exclusive secure device and it's not possible to open the device from usermode and send custom IOCTLs through it.
This driver filters input for a particle keyboard on the system. if you want to filter keyboard inputs from all the keyboards plugged into the system, you can install this driver as a class filter below the kbdclass filter driver by adding the service name of this filter driver before the kbdclass filter in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E96B-E325-11CE-BFC1-08002BE10318}\UpperFilters
Note
To build this sample, you can use Microsoft Visual Studio 2013 (Express, professional, or ultimate) and Windows Driver kit (wdk) 8.1 update. you can get Visual Studio 2013 and wdk 8.1 update here.
You can also build this sample with Visual Studio 2013 (professional or ultimate) and Windows Driver kit (wdk) 8.1.
For Windows Driver kit (wdk) 8 samples, download the wdk 8 samples pack. the samples in the wdk 8 samples pack will build only with Microsoft Visual Studio professional 2012 (professional or ultimate) and wdk 8.
Operating System Requirements
Client |
Windows 8 |
Server |
Windows Server 2012 |
Build the sampledownload and extract the sample
Click the Download button on this page. ClickSave, And then clickOpen folder. Right click keyboard input WDF filter driver (kbfiltr).zip, and chooseExtract all. Specify or browse to a folder for the extracted files. For example, you cocould extract to c: \ keyboard input WDF Filter Driver (kbfiltr ).
Open the driver solution in Visual Studio
Navigate to the folder that has the extracted sample. Double Click the solution file, kbfiltr. sln. in Microsoft Visual Studio, locate Solution Explorer. (if this is not already open, chooseSolution ExplorerFromViewMenu.) In Solution Explorer, you can see one solution that has two projects. There is a driver project namedKbfiltrAnd a package project namedPackage(Lower case ).
Set the configuration and platform in Visual Studio
In Visual Studio, in Solution Explorer, right clickSolution 'kbfiltr' (3 Projects), And chooseConfiguration Manager. Set the configuration and the platform. Make sure that the configuration and platform are the same for both the driver project and the package project. Do not checkDeployBoxes. Here are some examples of configuration and platform settings.
Configuration |
Platform |
Description |
Win8.1 debug |
X64 |
The driver will run on an x64 hardware platform that is running Windows 8.1. The driver will not run on any earlier versions of Windows. |
Win7 debug |
X64 |
The driver will run on an x64 hardware platform that is running Windows 7 or a later version of Windows. |
Set the hardware ID in the specified file
This step is required for automatic deployment (described later) to work properly. in the kbfiltr. stored file (located with the driver source files), find the [ddk_ex.mfg.nt $ arch $] section. change the hardware ID in the % ddk_ex % entry from the dummy value to the hardware ID of the PS/2 keyboard on the target computer. the following example shows the hardware ID change.
; For XP and above[DDK_Ex.Mfg.NT$ARCH$];%DDK_Ex% = kbfiltr, *PNP0BAAD%DDK_Ex% = kbfiltr, ACPI\VEN_PNP&DEV_0303
Build the sample using Visual Studio
In Visual Studio, onBuildMenu, chooseBuild Solution.
For more information about using Visual Studio to build a driver package, see building a driver.
The test application,Kbftest.exeIs also built as part of the solution under the 'exe 'Folder.
Locate the built driver package
In File explorer, navigate to the folder that contains your built driver package. the location of this folder varies depending on what you set for configuration and platform. for example, if your settings are win7 debug and x64, the package is your solution folder under x64 \ win7debug \ package.
The package contains these files:
File |
Description |
Kmdfsamples. Cat |
A signed catalog file, which serves as the signature for the entire package. |
Kbfiltr. inf |
An information (INF) file that contains information needed to install the driver. |
Wdfcoinstaller010Xx. Dll |
The coinstaller for Version 1.XxOf kmdf. |
Kbfiltr. sys |
The driver file. |
Using msbuild
As an alternative to building the kbfiltr filter driver sample in Visual Studio, you can build it in a Visual Studio Command Prompt window. in Visual Studio, onToolsMenu, chooseVisual Studio Command Prompt. In the Visual Studio Command Prompt window, navigate to the folder that has the solution file, kbfiltr. sln. Use the msbuild command to build the solution. Here are some examples:
Msbuild/P: configuration = "win7 debug"/P: Platform = "x64" kbfiltr. sln
Msbuild/P: configuration = "Win8 release"/P: Platform = "Win32" kbfiltr. sln
For more information about using msbuild to build a driver package, see building a driver.
Run the sample
The computer where you install the driver is calledTarget computerOrTest Computer. Typically this is a separate computer from where you develop and build the driver package. The computer where you develop and build the driver is calledHost Computer.
The process of moving the driver package to the target computer and installing the driver is calledDeploying the driver. You can deploy kbfiltr sample driver automatically or manually.
Automatic deployment
Before you automatically deploy a driver, you must provision the target computer. For instructions, see creating a computer for driver deployment, testing, and debugging.
- On the host computer, in Visual Studio, in Solution Explorer, right clickPackage(Lower case), and chooseProperties. NavigateConfiguration Properties> driver install> deployment.
- CheckEnable deployment, And checkRemove previous driver versions before deployment.Target computer name, Select the name of a target computer that you provisioned previusly. SelectInstall and verify, And chooseDefault Driver package installation taskIn the list. ClickOK.
- OnBuildMenu, chooseDeploy packageOrBuild Solution.
Manual deployment
Before you manually deploy a driver, you must turn on test signing and install a certificate on the target computer. you also need to copy the devcon tool to the target computer. for instructions, see preparing a computer for manual driver deployment.
- Copy all of the files in your driver package to a folder on the target computer (for example, c: \ kbfiltrdriverpackage ).
On the target computer, open a command prompt window as administrator. Navigate to your driver package folder, and enter the devcon command with the correct hardware ID, such:
Devcon install kbfiltr. inf ACPI \ ven_pnp & dev_0303
-Or-
Using Device Manager, update the driver for the PS/2 Keyboard by manually selecting kbfiltr. inf from the location where you copied the driver files.
View the installed driver in Device Manager
On the target computer, in a command prompt window, enterDevmgmtTo open Device Manager. In Device Manager, onViewMenu, chooseDevices by type. In the Device Tree, locateDDK example device that needs FilteringUnderKeyboardsNode.
Testing
To use the test application provided with the sample, it must be copied to the target computer manually. save the kbftest.exe file from the folder where the build result is placed (for example, exe \ x64 \ win7debug ). this file is copied somewhere on the target, possibly where the driver package files are located. the test application is the executed on the target computer in a command prompt usingKbftestAs the command.
TipTo avoid DLL dependencies for kbftext.exe, and the need to copy additional files, select the statically linked run-time library when building.
Keyboard Input WDF Filter Driver (kbfiltr) source code learning notes