View Full Version : Detecting keystrokes in VB 2005
day1118
12-15-2007, 04:55 AM
Hi guys, I can detect key strokes using the keydown function, but this only works when the form has focus, I am after a way to detect all keystrokes despite what program has the focus, can any one help?
Kenneth Gorking
12-15-2007, 04:56 AM
DirectInput should be able to do that.
Skaldi
12-17-2007, 03:35 AM
Declare Function GetAsyncKeyState Lib "user32" ( _
ByVal vKey As Long) As Integer
This function should help you too if you don't want to use DirectInput....
This function also receives ctrl and alt keys. And the form doesn't need to be focused.
But you should call it in your Program loop, you don't get an event you only get the state of the wished Key (pressed or not pressed).
If you don't have your own program loop you should put it there:
I think the routine is called WndProc
I'm not sure but i guess the code goes like that:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
'Add your code here
End Sub
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.