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.
rcearleyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle 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?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
angus_young_acdcCommented:
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.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Haha...sounds like you had a blast with that one...  ;)
0
rcearleyAuthor Commented:
Not complete solution, but provided a lead of where to look.
0
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...  =)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.