System Wide [ Global] Keyboard Hook - Pure VB
Posted: 2002-06-01
By: ArchiveBot
Viewed: 72
Filed Under:
Title | Uploaded | Size |
---|---|---|
CODE_UPLOAD1257712112000.zip | 9/3/2020 3:45:00 PM | 3,171 |
This Global Keyboard Hook / System wide keyboard hook is written entirely in VB. No Visual C++ code or any other tricks, just plain and simple API's. No more of the secretive VC ++ Dll's.
The sole purpose of this sample is only to demonstrate the ablility of Visual Basic to set a keyboard hook. No attention has been paid to the User interface or other enhancements. It has only the bare functional necessities.
It logs all keyboard events, doesnt filter out any of the system calls. The system calls this function every time a new keyboard input event is about to be posted into a thread input queue.
Original Author: unknown
Assumptions
Open the source code. go to the module and change the path of the text file to which the events are to be sent.
Returns
The sample logs the keyboard events to a 'c: empkeybd.txt' file. Please check if the file exists or change the file path in the code and compile.
Side Effects
Do not kill the program untill you have clicked the unhook button.
Tested on Win NT4 and Windows 2000. Yet to be tested on Win9x.
API Declarations
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function SetWindowsHook Lib "user32" Alias "SetWindowsHookA" (ByVal nFilterType As Long, ByVal pfnFilterProc As Long) As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Global Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0
Type HookStruct
vkCode As Long
scancode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.