我的计算机配有USB键盘和USB条形码扫描仪,可以快速击键发送重新编码的代码。
现在我的应用程序是100%键盘记录程序,但我想区分usb键盘和条形码扫描仪,只将条形码发送到键盘记录器。
这是我正在使用的代码。
声明
Private Declare Function SetWindowsHookEx Lib "user32.dll" _
Alias "SetWindowsHookExA" (ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
Private Declare Function CallNextHookEx Lib "user32.dll" (ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, _
ByRef Source As Any, _
ByVal Length As Long)
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
Private Const WH_KEYBOARD_LL As Long = 13
Public Type KBDLLHOOKSTRUCT
VkCode As Long
ScanCode As Long
Flags As Long
Time As Long
DwExtraInfo As Long
End Type
Dim KBHook As Long
Dim KeyData As String
Public Sub main()
ManageKeylogger True
End Sub
键盘挂钩
Public Sub ManageKeylogger(ByVal Enable As Boolean)
Select Case Enable
Case True
KBHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KBProc, App.hInstance, 0)
Case False
Call UnhookWindowsHookEx(KBHook)
End Select
End Sub
键盘回调方法
Public Function KBProc(ByVal nCode As Long, ByVal wParam As Long, lParam As Long) As Long
Dim KeyBoardHook As KBDLLHOOKSTRUCT
If nCode = 0 Then
CopyMemory KeyBoardHook, lParam, Len(KeyBoardHook)
With KeyBoardHook
If .Flags = 0 Or .Flags = 1 Then
If SaveLog(TranslateKey(.VkCode)) > 0 Then
Call LogToFile(App.Path & "\Log.log")
End If
End If
End With
Else
KBProc = CallNextHookEx(KBHook, nCode, wParam, lParam)
End If
End Function
关键翻译
Private Function TranslateKey(ByVal KeyCode As Long) As String
'stuff
End Function
日志
Public Function SaveLog(ByVal sKey As String) As Double
KeyData = KeyData & sKey
SaveLog = Len(KeyData)
End Function
Public Sub LogToFile(ByVal sPath As String)
Open sPath For Binary As #1
Put #1, , KeyData
Close #1
End Sub
答案 0 :(得分:0)
我做过类似的条形码输入,以回车符结束。