Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to replace the "Z" key with "Y" and vice versa.
So if the user hits "Z" on the keyboard then I catch and
suppress it and send a "Y" instead.

Trouble is that so far I found no way to tell apart real key
events and fake ones. This means that a physically pressed
"Z" is detected, suppressed, a "Y" is sent but that enters
the system just like a real key press so gets caught and
suppressed, replaced by a "Z" and so on in an infinite loop.

"Z" and "Y" are just examples, my application should be able
to catch any key combo and replace with any other combo.

The keyboard hook is installed via SetWindowsHookEx() while
the key sending is done with SendInput().

COMMENTS:
"What do you want to happen when you send the key via SendInput()?"
I want the fake keypress to arrive to the focused application without
being intercepted and suppressed by the keyboard hook. (I only want
to do that with real keypresses.)

"You can use flags and tests to prevent the infinite loop in the event
handler."
What sort of flags and tests?
Posted
Updated 7-May-12 23:58pm
v2

What do you want to happen when you send the key via SendInput()?

You can use flags and tests to prevent the infinite loop in the event handler.
 
Share this answer
 
That change of Z and Y looks like English versus German keyboard settings. Thus, could InputLanguage.CurrentInputLanguage help in your case (i.e. you would no more need to change later on)?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900