Web Pribadiku

Home » » berikut script untuk menonaktifkan keyboard control, alt, winkey dengan vb.net

berikut script untuk menonaktifkan keyboard control, alt, winkey dengan vb.net

Posted by CB Blogger

  1. 'Event types
  2. Private Const WM_KEYUP As Integer = &H101
  3. Private Const WM_KEYDOWN As Short = &H100S
  4. Private Const WM_SYSKEYDOWN As Integer = &H104
  5. Private Const WM_SYSKEYUP As Integer = &H105
  6. 'Event Info structure
  7. Public Structure KBDLLHOOKSTRUCT
  8. Public vkCode As Integer
  9. Public scanCode As Integer
  10. Public flags As Integer
  11. Public time As Integer
  12. Public dwExtraInfo As Integer
  13. End Structure
  14. 'Keyboard hook related functions
  15. Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
  16. Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
  17. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
  18. Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As KBDLLHOOKSTRUCT) As Integer
  19. Private Delegate Function KeyboardHookDelegate(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
  20. Private KeyboardHandle As IntPtr = 0 'Handle of the hook
  21. Private callback As KeyboardHookDelegate = Nothing 'Delegate for the hook
  22. Private Function Hooked()
  23. Return KeyboardHandle <> 0 'If KeyboardHandle = 0 it means that it isn't hooked so return false, otherwise return true
  24. End Function
  25. Public Sub HookKeyboard()
  26. callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)
  27. KeyboardHandle = SetWindowsHookEx(13, callback, Process.GetCurrentProcess.MainModule.BaseAddress, 0)
  28. If KeyboardHandle <> 0 Then
  29. Debug.Write(vbCrLf & "[Keyboard Hooked]" & vbCrLf)
  30. End If
  31. End Sub
  32. Public Sub UnhookKeyboard()
  33. If (Hooked()) Then
  34. If UnhookWindowsHookEx(KeyboardHandle) <> 0 Then
  35. Debug.Write(vbCrLf & "[Keyboard Unhooked]")
  36. KeyboardHandle = 0 'We have unhooked successfully
  37. End If
  38. End If
  39. End Sub
  40. Public Function KeyboardCallback(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
  41. 'Variable to hold the text describing the key pressed
  42. Dim Key = lParam.vkCode
  43. 'If event is KEYDOWN
  44. If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then
  45. 'If we can block events
  46. If Code >= 0 Then
  47. If Key = 91 Or Key = 92 Then
  48. Return 1 'Block event
  49. End If
  50. End If
  51. End If
  52. Debug.Write(Key)
  53. 'Return CallNextHookEx(KeyboardHandle, Code, wParam, lParam) 'Let event go to the other applications
  54. End Function
  55. Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  56. UnhookKeyboard()
  57. End Sub
  58. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  59. HookKeyboard()
  60. End Sub
Sumber: https://www.daniweb.com/programming/software-development/threads/420235/disabling-windows-key-in-vb-net


1 komentar:

  1. This comment has been removed by the author.

    ReplyDelete

\
\