Link to home
Start Free TrialLog in
Avatar of rcearley
rcearley

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Haha...sounds like you had a blast with that one...  ;)
Avatar of rcearley
rcearley

ASKER

Not complete solution, but provided a lead of where to look.
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...  =)