Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How I can get an event to be generated whenever the user presses a key(even if my current application is not in focus)? I actually wish to execute some code according to the keys pressed by the user. My application will be running in back end. Looking forward to any help.
Posted
Comments
Abhinav S 1-Jan-13 11:45am    
And why do you want to do this?
Ritwesh 1-Jan-13 11:54am    
I actually want to develop an application by which I can perform many actions even when the user just presses a few keys even without opening any application as such and such that my application can trace any key pressed even for other applications. I hope I was able to express myself. So, can it be done as I wish it to be? Plz... help

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jan-13 13:26pm    
I voted 5, because if the control is out of focus, this is the only way, and because this is valuable information.

At the same time, I added my own solution where I explained some background and recommended UI design review. Your solution is of course credited.

—SA
Thomas Daniels 1-Jan-13 13:27pm    
Thank you!
You should understand that "focus" always means "keyboard focus" and nothing else. It means, only the control which has focus receives input events when the user presses key on a keyboard.

Solution 1 explains how you can trigger some events via a keyboard Windows Hook, but that would be a real abuse of normal UI development. Using such hooks can be justified only for some special cases. For example, it could be recording of keyboard macro, system-global utilities and the like. If this is just the separate UI application which does not have a task of intervention into the behavior of other processes, you should rather review your UI design.

—SA
 
Share this answer
 
Comments
Thomas Daniels 1-Jan-13 13:28pm    
Good answer, +5!
Sergey Alexandrovich Kryukov 1-Jan-13 13:35pm    
Thank you. Happy New Year!
—SA
 
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