Solved

Block a pressed keyboard button

Posted on 2011-02-11
6
1,285 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
ID: 34875888
"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
ID: 34903014
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
ID: 34903202
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:techsuppoprt
ID: 34912355
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
ID: 34912478
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
ID: 34917898
Yup, I got it, thank you!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Diagnostics with Net and Net.Sockets 2 28
Install Problem 13 31
VB.Net - MemoryMappedFiles - Confirm receipt 2 19
Help with adding DLL file in Windows project 20 31
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.

778 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