I am in too deep with this. I have an integer that points to a KBDLLHOOKSTRUCT structure.
Here is the code for the structure:
Code:
Private Structure KBDLLHOOKSTRUCT
Public vkCode As Integer ' virtual key code
Public scanCode As Integer ' scan code
Public flags As Integer ' flags
Public time As Integer ' time stamp for thismessage
Public dwExtraInfo As Integer ' extra info from the driver or keybd_event
End Structure
How do i get virtual key code from this? Here is the full code.
Code:
Private Structure KBDLLHOOKSTRUCT
Public vkCode As Integer ' virtual key code
Public scanCode As Integer ' scan code
Public flags As Integer ' flags
Public time As Integer ' time stamp for thismessage
Public dwExtraInfo As Integer ' extra info from the driver or keybd_event
End Structure
Private Const LLKHF_ALTDOWN = 32
Private Const HC_ACTION = 0
Public Delegate Function CallBack( _
ByVal idHook As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Integer
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal ncode As Integer, ByVal wParam As Long, ByVal lParam As Integer) As Integer
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As CallBack, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
Public Declare Sub CopyStructFromPtr Lib "kernel32" Alias "RtlMoveMemory" (ByRef struct As Object, ByVal ptr As Integer, ByVal cb As Integer)
Private hHook As Integer
Private CTRLDown As Boolean
Private pkbhs As New KBDLLHOOKSTRUCT()
' wParam - Specifies the identifier of the
' keyboard message.
' This parameter can be one of the
' following messages:
' WM_KEYDOWN,WM_KEYUP,WM_SYSKEYDOWN,
' or WM_SYSKEYUP.
' lParam - pointer to KBDLLHOOKSTRUCT structure
Private hookproc As CallBack
Private Function LowLevelKeyboardProc(ByVal idHook As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Try
msgbox "VK CODE NEEDS TO GO HERE"
LowLevelKeyboardProc = CallNextHookEx(hHook, idHook, wParam, lParam)
Catch ex As Exception
ErrorBox.Text = "Error: " + ex.Message
ErrorPanel.Show()
End Try
End Function
Public Sub HookKeyboard()
Dim hinstance As Integer = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, hinstance, 0&)
End Sub
Public Sub UnHookKeyboard()
'remove the windows-hook
Call UnhookWindowsHookEx(hHook)
End Sub