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 8391645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:19:02+00:00 2026-06-09T19:19:02+00:00

I have written the following method that prevents all keys from being pressed: private

  • 0

I have written the following method that prevents all keys from being pressed:

private IntPtr HookHandler(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
{
    if (nCode >= 0)
    {
        ...

        //Return a nonzero value to prevent the system from passing the message to the
        //rest of the hook chain or the target window procedure.
        return (IntPtr)1;
    }

    return NativeMethods.CallNextHookEx(_hookID, nCode, wParam, ref lParam);
}

When the above code runs, though, it allows keys like my keyboard’s calc key or the email key, etc.

I debug, and the code does get to the return (IntPtr)1; line (and it does show correctly what key is being pressed), but by then, the calc window (or other) has already opened. Even if I return a 1, its too late.

Is there something I can be doing different here?

  • 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-09T19:19:03+00:00Added an answer on June 9, 2026 at 7:19 pm

    Well, that ought to work. Normal routing is from a WM_KEYDOWN message to a WM_APPCOMMAND message generated by the default window procedure. WM_XBUTTONUP is another route but an unlikely one. Have a look with Spy++ to see if anything unusual is happening.

    You are also a potential victim of another process hooking keys that got ahead of you and is not properly calling CallNextHookEx(). Tackle that with TaskMgr.exe, Processes tab and start killing processes. Start with anything that smells like vendor supplied shovelware, particularly if the keyboard has keys that don’t fit the WM_APPCOMMAND command set and thus needs such a program to add gizmos.

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

Sidebar

Related Questions

I have written the following method to detemine whether file in question is formatted
Currently, I have the following method that writes to excel 2007. public static void
I have written two methods that take and return a string. One converts from
I'm trying to convert a method that I have written in C# to Java
All, I have a mathod called TaskSpin that runs the passed method on a
I have the following code that defines a getParts method to find a given
I have the following method to test and i have written two tests, testing
I have written the following .NET Framework 3.5 C# method which takes the location
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in

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.