Click here to Skip to main content
12,456,128 members (52,243 online)
Rate this:
 
Please Sign up or sign in to vote.
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 1-Jan-13 5:36am
Ritwesh1.7K
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
   
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
ProgramFOX 1-Jan-13 13:27pm
   
Thank you!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
ProgramFOX 1-Jan-13 13:28pm
   
Good answer, +5!
   
Thank you. Happy New Year!
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100