We help IT Professionals succeed at work.

Capturing KeyDown without an active form

wailqill asked
Medium Priority
Last Modified: 2010-05-02
I have tried to figure out how to transparently capture a keyevent regardless of what appliation is in focus.

think of it just like a normal external ScreenCapture-program is triggered by a combo of keystrokes (ie CTRL+SHIFT+F12)

ho is this done?
i haven't found that, anyone got experiance with this?

Watch Question

I have a vb program that does this if you want me to email you the source.
I suppose you could just set the KeyPreview property on all of your forms to True and then include a call to a public function which actually checks for the designated key combination.  RainUK's solution might be less cumbersome.  I can't seem to get the link he supplied to work.  

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    CheckForCtrlShftF12  KeyCode, Shift
End Sub

Hi dreamingeagle

Unfortunately DreamEagle is wrong, my solution is a lot more grief! :-P  
But its the only way you will get what you want to do :-)

Just go to www.Planet-Source-code.com
Then in the search box type "kbhook"

There is only one download (Although there are lots of KB hook examples, type in "Keyboard" if you want them all). It uses an API to get a system level keyboard hook.

Using KeyPreview, only works when your form has focus, therefore if you switch applications or lose focus, it won't pick up the keyboard events.

Actually the example I've pointed you to is only a Thread Wide keyboard hook, you actually want this example same website:


This is a system wide lowl level hook and is what you are looking for



thank you VERY much :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.