Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am looking for way/script in C to detect real physical keystroke. I don't want to use SendInput (or any other simulator input).

If possible, it would be good only to have RAWINPUT data without SendInput.
Posted
Updated 16-Dec-15 2:50am
v2
Comments
Jochen Arndt 16-Dec-15 8:41am    
SendInput generates key events and does not react on real keys. So you may clarify your question.

The usual method to react to key events is handling the WM_KEYDOWN and WM_KEYUP messages. But these will include events generated by SendInput. Do you want a method to detect real key presses and not those simulated ones?
Member 10616564 16-Dec-15 14:12pm    
Yes. I just need to detect real ones not simulated ones.
Jochen Arndt 16-Dec-15 17:07pm    
You can still handle the WM_KEY* messages in PreTranslateMessage (see Karsten's solution) because simulated key strokes will be only present if send by your application and might be detected therefore.
Sergey Alexandrovich Kryukov 16-Dec-15 11:08am    
SendInput has nothing to do with detection, it sends... :-)
Per application of system-wide?
—SA

1 solution

The normal way is to overwrite PreTranslateMessage and check for these values.

In this webpage from Microsoft is another approach well explained and also some sample code can be found.

Tip: If you handle the keystroke make a return and not handling to the default .
 
Share this answer
 
Comments
Member 10616564 16-Dec-15 15:22pm    
Does WM_KEYDOWN or WM_SYSKEYDOWN have anything to do with SendInput? Can that be generated by SendInput API?
.:floyd:. 2-May-16 11:02am    
Raw Input inspects packages that are enqueued into the hardware input buffer, long before the system converts them into regular Windows messages. If you want to respond to raw input messages (WM_INPUT) and filter out fake input generated from a call to SendInput you cannot do this in your regular keyboard/mouse message handling. This has to take place when handling WM_INPUT messages.

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