What’s Interception?


    A programming interface for intercepting input device communication.


What can I do with that?


    With Interception you are able to intercept and transform input data from keyboard and mouse. Other devices are in the works.

    Current support is still Windows only (from Windows 2000 to Windows 7), but Mac and Linux support are also in the works.


I can use Windows hooks for that, so, what’s up?


    Yes, you can, but... are you able to identify from which device some event is coming when you connect multiple keyboard/mouse? You can’t! With generic user-mode hooks you are able to identify that a keyboard/mouse event has arrived, but not from which keyboard/mouse it’s coming. With Interception on Windows you can! (With Raw Input you also can but you cannot intercept input with it.)

    Can you even intercept CTRL-ALT-DELETE with user-mode hooks? No, you can’t!

    Does your user-mode hook work when you are playing that old game which uses DirectInput? NO! You can’t BOT it.

    The list goes on and the bottom line is: Interception is much more powerful and simple.


Ok, but, how do you achieve this?


    The Interception API provides a simple interface of communication with kernel-mode components, and those components are powerful. They intercept data in a early stage, before it reaches the core of OS input processing.


I have a x64 Windows box, I’ve heard that it cannot load kernel-mode components indiscriminately.


    Yes, indeed. The Interception core is built upon properly signed drivers, so that’s not a problem!


Ok then, let’s get to work.


    First, you must download the Interception core installation tool: install-interception.

This tool must be run from an administrator command line (you must run cmd as administrator). Just run it without arguments to receive instructions.

    Second, you must link against the Interception library, which is provided here as a convenient package, or you may build it from sources. Static and dynamic libraries are provided and the x86 version do not depend on the VC10 runtime.

    Third, you must include interception.h in your applications.


    The following sample shows how to intercept the x key and turn it into y:

    There are some concepts you need to know to use Interception well:

    1 - Contexts:

        You need to create a context of communication with the core components, most functions will require it.

    2 - Filters:

        Filters are a way to indicate what kind of events you want to intercept, for example, in the last sample we were interested in simple key up’s and key down’s, some special keys would not trigger events through this filter, like the DELETE key, because it needs the E0 flag too. If you do not set a filter for at last one device, you won’t be notified of any events.

    3 - Device selection predicate:

        The interception_set_filter function has three parameters, the context of communication, a function pointer and a desired filter. This second parameter, the function pointer, is a device selection predicate, a function that receives a device id (like INTERCEPTION_KEYBOARD(0), INTERCEPTION_KEYBOARD(1), etc) as parameter and returns true if the device id passed is one of a device that must be filtered through the chosen filter, or false for the devices that are not to be filtered through this filter.

        So the interception_set_filter works by scanning all possible devices, and using the provided predicate as the criteria to know for which devices the provided filter should be applied.


    The following sample shows how to invert the vertical mouse axis:

    The following sample shows how to intercept and block the CTRL-ALT-DEL sequence:

    The following sample identify multiple mice through left clicking (worked well for my magic mouse and touch pad):

    As you can see interception_is_keyboard and interception_is_mouse are convenience device selection predicates, but you can implement your own.

    If you are using Interception since before 16 February 2012, please, update your Interception installation, because the following sample is new stuff I’ve implemented recently.

    The following sample allows one to query for a device’s “hardware id”, which may help on disambiguation of device input. Just remember this hardware id’s are not required to be unique, but mostly will when you have at last two different device models.