Keyboard Event Handling

I like to develop a small test application in which while the program is running in the background, if a certain keyboard combination is detected a message box will popup.

Say for example, Control 5.  This needs to be done while the program is running but not neccessarily in focus. I can be in Iexplorer and i hit Control F5 and the message box pops up but the program shouldnt refocus.

any suggestions with the KeyUp/Down events i can find useful? I am in a bit of a pickle.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.


   I think this is what you are looking for :

Hope this helps !


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
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

jwnrbAuthor Commented:
Hmm, it appears to work however when the prog is minimised the text box is also minimised on the tray. how can i force the event to pop up in the middle of the screen no matter whats open
jwnrbAuthor Commented:
Hmm, also, it seems this code is quite complicated. Anything else simpler?
Like this:

private void txtTest_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
                  if(e.KeyCode == Keys.D5 && e.Modifiers == Keys.ControlKey) // Ctrl+5
                        MessageBox.Show("You pressed the special key combination.  Good for you!","Key Catcher",MessageBoxButtons.OK, MessageBoxIcon.Information);

but works in the background and on the form itself (this code doesnt actually work yet but the jist of it)
No, the KeyDown event works only when your form has the focus.
jwnrbAuthor Commented:
Oh, so the only other way is to use what you provided?  Okay, I cant seem to find in the src then where i can decided which key stroke combinations i want to invoke the event.
also how can i cause a messagebox to take over the screen (like being an obnoxious popup more or less)

jwnrbAuthor Commented:
Just realised where to change the hot key. my bad.
anyways, i cant figure out the message box so it popups over in the application whre it was called
jwnrbAuthor Commented:
Well my boss likes it thus far and wants me instead of the msgbox, wants text to be sent from the program to an application.

such that, if i am in Word, Excel, Notepad, etc, a predefined string of text would be sent to the program and typed out such, "hello" for example and the program can not lose focus.
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

From novice to tech pro — start learning today.