Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Block a pressed keyboard button

Posted on 2011-02-11
6
Medium Priority
?
1,290 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 1600 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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 1600 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

Industry Leaders: 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!

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.
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ā€¦
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

618 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