Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Block a pressed keyboard button

Posted on 2011-02-11
6
1,286 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.

856 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