Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
setwindowshookex (user32)
.
C# Signature:
[D)
' setup a keyboard hook
SetWindowsHookEx(HookType.WH_KEYBOARD, Me.myCallbackDelegate, IntPtr.Zero, AppDomain.GetCurrentThreadId())
End Sub
<DllImport("user32.dll")> _
Friend Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal lpfn As HookProc, ByVal hInstance As IntPtr, ByVal threadId As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Friend Shared Function CallNextHookEx(ByVal hhk As intptr, ByVal nCode As Integer, ByVal wParam As intptr, ByVal lParam As intptr) As Integer
End Function
Private Function MyCallbackFunction(ByVal code As Integer, ByVal wParam As intptr, ByVal lParam As intptr) As Integer
If (code < 0) Then
'you need to call CallNextHookEx without further processing
'and return the value returned by CallNextHookEx
Return CallNextHookEx(IntPtr.Zero, code, wParam, lParam) 'unt
End If
' we can convert the 2nd parameter (the key code) to a System.Windows.Forms.Keys enum constant
Dim keyPressed As Keys = CType(wParam.ToInt32, Keys)
Console.WriteLine(keyPressed)
'return the value returned by CallNextHookEx
Return CallNextHookEx(IntPtr.Zero, code, wParam, lParam)
End Function
End Class
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).