Solved

Block a pressed keyboard button

Posted on 2011-02-11
6
1,288 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
[X]
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
  • 3
  • 3
6 Comments
 
LVL 86

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 86

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 86

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

726 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