Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8769671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:23:55+00:00 2026-06-13T17:23:55+00:00

Currently, I’m making a program that intercept keystrokes from a specific keyboard (filtered using

  • 0

Currently, I’m making a program that intercept keystrokes from a specific keyboard (filtered using its HID). So to know which keystrokes have been sent by a specific device, I used the RawInput technic, inspired by this great tutorial:

http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard

Now, it works great: I can get a keystroke and know which keyboard have generated it.

The difficult part of my project is to intercept and block keystrokes from this specific keyboard, to avoid these keystrokes to reach the focused application (focused mean the foreground window brought by the OS).

So the natural solution was a low level global hook, on all current threads that have a window handle.

I used and adapted the code from this page to do that:

http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx

I created a new project in visual studio to avoid putting the mess in my work. After some research, I was able to block keystrokes on all applications, by returning the value (-1) in the callback function:

private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)  
{
//Check if we have a key to pass

if (
    nCode >= 0 && ( 
    (wParam == (IntPtr)WM_KEYDOWN) || (wParam == (IntPtr)WM_KEYUP) ) 
    )
{
    int vkCode = Marshal.ReadInt32(lParam);
    if ((Keys)vkCode == Form1.KeysToIgnore)
    {
        return (IntPtr)(-1);
    }
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}

To put all together (the hook procedure, and the keystroke detection), I create two threads in the final project:

1st : using RawInput to identify and attach each keystroke to a device

2nd : used to hook all windows and block certains keystrokes

Thread 1 is designed to send keystroke to block to the thread 2, that read all messages sent to all window application and trash keystrokes from a specific keyboard. I precise that these two threads are synchronized.

The problem is that the hook seems to be executed before the execution of Rawinput, so I can’t identify the keyboard that sent the keystroke. I have no idea how to do that, maybe to change the type of hook (avoid using low level keyboard hook, but using a user-space level keyboard hook).

Or maybe someone know a clever way to do what I want?

I know this request is really complicated, don’t hesitate to ask for more details.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:23:56+00:00Added an answer on June 13, 2026 at 5:23 pm

    Ok, Silence Dogood give me a good clue:

    The library Interception is perfect for my use. You can find it here:

    https://github.com/oblitum/Interception

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have a loop in my program that has the format: #include<stdio.h> int
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I am using HTML files for parts of my user interface. I display
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently working with converting SQLException error messages into messages that are more useful for
currently I'm struggling with maps which should contain themselves. But I don't know the
Currently, my MVC 3 app has a dependency on a static class that is
Currently I am using Amazon Cloudfront to service static objects on my ASP.Net MVC3
Currently, Enum.Parse supports only the comma as the value separator, so that MemberOne,MemberThree will
Currently I have a web service, which loads up any plugins located within its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.