Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.5 VS2008
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 at 1-Jan-13 11:45am
   
And why do you want to do this?
Ritwesh at 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
Sergey Alexandrovich Kryukov at 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
ProgramFOX at 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 at 1-Jan-13 13:28pm
   
Good answer, +5!
Sergey Alexandrovich Kryukov at 1-Jan-13 13:35pm
   
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
0 CPallini 365
1 Sergey Alexandrovich Kryukov 277
2 OriginalGriff 165
3 George Jonsson 159
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,860
2 CPallini 5,125
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
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