CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2007

    Injecting keyboard scan codes at driver level

    I am writing a program for a friend who has difficulty using the keyboard. I
    would like to create a program that injects scan codes directly into the
    keyboard data stream to simulate an actual key press. There are certain
    programs he has installed that read the raw keyboard data so the simple Post
    Message and Send Input solutions do not work. I must somehow simulate key
    presses at the lowest level so that they appear as raw data.

    The operating system is XP using a PS/2 keyboard. There is a high
    probability that he will upgrade to a USB keyboard and Vista but probably not
    at the same time. The program must therefore be compatible with both OS and
    both port types.

    I have 2 ideas. The first is to create a virtual keyboard in device manager
    that Windows sees as a real keyboard. My user program will tell this virtual
    keyboard what keys are pressed/released and the device will be read by
    Windows/programs as normal. I have found no information on how to do this
    My second idea is to create a keyboard filter driver which would append the
    scan codes to the keyboard data stream based on data received from the user

    How far I have got:
    I have no experience with drivers and Im eager to learn. I have determined
    - The driver must be an upper level keyboard class filter driver (simple
    registry installation)
    - The driver does not need to handle (dis)connection, power or LEDs. It only
    injects scan codes
    - The driver does not block, read or modify any real keyboard activity it
    lets it all through
    - The user program simply sends scan codes to the driver there is no other
    communication (although some result value to let the program know that the
    driver responded would be useful)

    I have hit a brick wall as I do not know where to begin! I have successfully
    built a scan code modifying kbfiltr from the DDK but this is PS/2 lower
    level, has complex unnecessary code and has no injection sample code.
    Ctrl2Cap sounds interesting but there is no source code available now and the
    author states that injection will be difficult to achieve.

    While I am fluent in C and programming in general, I understand that this
    program will require non-user mode programming and I have zero experience in
    this area. This program has a very simple, specific, unobtrusive function but
    Im finding it hard to know where to start. Any advice, links or samples to
    help me achieve this goal would be fantastic. Thank you.

    - Mark Andrews

  2. #2
    Join Date
    Nov 2014

    Re: Injecting keyboard scan codes at driver level


    Do you already have a solution for your problem?


  3. #3
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Injecting keyboard scan codes at driver level

    Assuming you have the issue too (even though you should have created a new post instead of resurrecting ancient ones).

    See MSDN for SendInput().

  4. #4
    Join Date
    Nov 2014

    Re: Injecting keyboard scan codes at driver level

    Thank you for the helpfull reply. I was trying to shut a computer down using send codes sending from a Teensy. But I will start a new topic for this.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.