I am trying to disable windows keys. Bt while running the application i get an error "CallbackOnCollectedDelegate was detected" Below is my code
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As LowLevelKeyboardProcDelegate, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As IntPtr
Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHook As IntPtr) As Boolean
Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal hHook As IntPtr, ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
Delegate Function LowLevelKeyboardProcDelegate(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
Const WH_KEYBOARD_LL As Integer = 13
Structure KBDLLHOOKSTRUCT
Dim vkCode As Integer
Dim scanCode As Integer
Dim flags As Integer
Dim time As Integer
Dim dwExtraInfo As Integer
End Structure
Dim intLLKey As IntPtr
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, IntPtr.Zero, 0)
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
UnhookWindowsHookEx(intLLKey)
End Sub
Private Function LowLevelKeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
Dim blnEat As Boolean = False
Select Case wParam
Case 256, 257, 260, 261
'Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key
blnEat = ((lParam.vkCode = 9) AndAlso (lParam.flags = 32)) Or
((lParam.vkCode = 27) AndAlso (lParam.flags = 32)) Or
((lParam.vkCode = 27) AndAlso (lParam.flags = 0)) Or
((lParam.vkCode = 91) AndAlso (lParam.flags = 1)) Or
((lParam.vkCode = 92) AndAlso (lParam.flags = 1))
End Select
If blnEat = True Then
Return 1
Else
Return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)
End If
End Function
Any help is very much appreciated