Hello there, I need to make a program that can capture keyboard input from any window that has input focus. Anybody can help me out with some piece of code?
Printable View
Hello there, I need to make a program that can capture keyboard input from any window that has input focus. Anybody can help me out with some piece of code?
you'll need to look at the GetAsyncKeyState
Try the API guide download at www.allapi.net for a sample of this one
#If you are using WinNT4, Win2K or WinXP you can install a WH_KEYBOARD_LL hook that will receive keyboard event notifications for every keypress regardless of whether your application has focus or not...
To do this with the EventVB.dll :
HTH,Code:'\\ In form declarations...
Dim WithEvents vbLink As EventVB.APIFunctions
Dim WithEvents vbKddHook As EventVB.EnumHandler
[COLOR=green]'\\ Start hook when form loads [COLOR]
Private Sub Form_Load()
Set vbLink = New APIFunctions
Set vbKbdHook = vbLink.EventhandlerLink
vbKbdHook.StartHook WH_KEYBOARD_LL, vbLink.ModuleHandle, 0
End Sub
[COLOR=green]'\\ Stop hook when form unloads [COLOR]
Private Sub Form_Unload()
vbKbdHook.StopHook WH_KEYBOARD_LL
End Sub
[COLOR=green]'\\ Process keyboard events [COLOR]
Private Sub vbKbdHook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
With KeyStrokeInfo
If .KeyReleased Then
Debug.Print .KeyNameText & " released"
End If
End With
End Sub
Duncan
Further to the PM I just got...
Goto http://www.allapi.net/agnet/aanreg.php and download the program.
Search for "GetAsyncKeyState" down the left hand side and the right side will have some code under the Examples tab. Shove this into a new form & module & run it.
Follow the on screen instructions and this is basically the same as you're trying. By then changing this line in the sample :
toCode:MsgBox sSave
this will copy the text to the clipboard. ;)Code:Clipboard.Clear
Clipboard.SetText sSave
Thanx guys for the reply.
Thanx alex_read i got the sample code from allapi. That really helped me out!!!
Thanx guys for the reply.
Thanx alex_read i got the sample code from allapi. That really helped me out!!!
cheeers
vbud
Watch out there, when you start using those keyboard hooks, some antivirus programs (specifically McAfee) will pick up your code as a virus.. a keystroke logger..
-mcd
Thanx MetallicaD i`ll try to keep that in mind!!!