Solved

Block a pressed keyboard button

Posted on 2011-02-11
6
1,283 Views
Last Modified: 2013-12-17
Hi Experts

Need some help here please. I have an application that forwards my keyboard button press events to other events. I'm using a keyboard global hook to detect user key stokes and return something else.
Eventually it's a macro program. For example user hits "2" on the keyboard and "Hello" is returned.

My problem is that I cannot get rid of that "2" itself. Instead of "Hello" - "2Hello" is returned.
How can I block the selected key from being returned to the user ? I need only "Hello" to be returned.

Thank you.
0
Comment
Question by:techsuppoprt
  • 3
  • 3
6 Comments
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 400 total points
Comment Utility
"I'm using a keyboard global hook"

In your hook callback method, instead of executing CallNextHookEx(), you simply immediately exit by returning true:

    // when key you want to suppress is encountered:
    return true;

This will suppress the keystroke.  You may need to do this for both WM_KEYDOWN and WM_KEYUP for the target key.
0
 
LVL 1

Author Comment

by:techsuppoprt
Comment Utility
Hmmm , did it but now it doesn't return any keys at all.
Keyboard's just not responding unless I hit the trigger that starts my macro.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
If you return true for ALL keystrokes then your keyboard won't respond anymore.   =\

What you need to do is return true ONLY for the number "2" so that only the number "2" is consumed.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:techsuppoprt
Comment Utility
Thanks.
I should've mentioned that this is actually what I'm using:

http://www.codeproject.com/KB/cs/globalhook.aspx

So extra digging is required , it's not exactly what you're saying :)
Let me see....brb!
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 400 total points
Comment Utility
Gotcha...in the FAQs from that page:

Question

I need to suppress some keystrokes after I have processed them.

Answer

Just set the e.Handled property to true in the key events you have processed. It prevents the keystrokes being processed by other applications.
0
 
LVL 1

Author Comment

by:techsuppoprt
Comment Utility
Yup, I got it, thank you!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now