How to make winforms application keep focus

I have a winforms application that has one form.  That form responds to F keys such as F1, F2, F3, etc.  If that application is in focus, I can press F1 and the application will execute the command I have tied to F1.  

If a user clicks away from my application and presses F1, then my application is not able to respond to the F1 key.

How can I force my application to keep focus.  I tried setting topmost to true, but that makes my form stay on top, but you can still click on another application the the focus will leave my app.
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
An alternative to making your app keep focus would be to detect the keystrokes globally thru either Hotkeys or a Low Level Keyboard Hook.  Are you open to either of these approaches?
Oh Idle_Mind, you're brought back some memories :) If you do use a key hook remember to make sure that you handle any message boxes you show, or anything else that pops up above your form!

I remember when I was a junior, I had written an app that wouldn't let you loose focus (using a class somebody else had originally done), but I forgot to modify it for messageboxs... oh what a joy that was having to do a hard reboot as you couldn't even Ctrl + Alt + Del.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Haha...sounds like you had a blast with that one...  ;)
rcearleyAuthor Commented:
Not complete solution, but provided a lead of where to look.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Lol...if you had responded back to the thread and requested more info I would have gladly given you more detailed answers!

I left it wide open with my last question:

    "Are you open to either of these approaches?"

Participate in your thread next time and you might get even better answers...  =)
All Courses

From novice to tech pro — start learning today.