嗯,蛮巧的,前两天也在玩这个
不过我是用作PS2的扫描抢输入处理的。我偷偷懒不改程序了,您自己参考一下把,主要使用API:SetWindowsHookEx来实现,您只需要修改以下CallHookProc这个回调中的内容即可,其中我是让它遇到回车就RaiseEvent的,当然您也可以修改默认构造函数,使得初始化的时候传递一个函数方法的地址进来(就是那个GetBarCodeEvent委托声明,然后在创建实例的时候使用AddressOf来传递函数地址)
实现类:
======================
Imports SystemReflection
Imports SystemThreading
Imports SystemComponentModel
Imports SystemRuntimeInteropServices
Imports SystemText
Public Class MyHook
Private Structure KeyboardHookStruct
Dim vkCode As Integer
Dim ScanCode As Integer
Dim Flags As Integer
Dim Time As Integer
Dim DwExtraInfo As Integer
End Structure
Private Const WH_JOURNALRECORD = 0
Private Const WH_JOURNALPLAYBACK = 1
Private Const WH_KEYBOARD = 2
Private Const WH_GETMESSAGE = 3
Private Const WH_CALLWNDPROC = 4
Private Const WH_CBT = 5
Private Const WH_SYSMSGFILTER = 6
Private Const WH_MOUSE = 7
Private Const WH_HARDWARE = 8
Private Const WH_DEBUG = 9
Private Const WH_SHELL = 10
Private Const WH_FOREGROUNDIDLE = 11
Private Const WH_CALLWNDPROCRET = 12
Private Const WH_KEYBOARD_LL = 13
Private Const WH_MOUSE_LL = 14
Private Const VK_SHIFT As Byte = &H10
Private Const VK_CAPITAL As Byte = &H14
Private Const VK_NUMLOCK As Byte = &H90
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYDOWN = &H104
Private Const WM_SYSKEYUP = &H105
Private Delegate Sub HookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr)
Public Delegate Sub GetBarCodeDelegate(ByVal _BarCode As String)
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As Integer
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal idHook As Integer) As Integer
Private Declare Function CallNextHookEx Lib "user32" (ByVal idHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
Public Event OnBarCodeEvent(ByVal _BarCode As String)
Private GetBarCodeEvent As GetBarCodeDelegate
Private KeyboardHookProcedure As HookProc
Private m_lHook As Integer = 0
Private DataBuff As String = ""
Private IsShift As Boolean = False
Public Sub New()
End Sub
Protected Overrides Sub Finalize()
StopHook()
MyBaseFinalize()
End Sub
'打开系统钩子,开始监视扫描q
Public Sub StartSystemHook()
If m_lHook = 0 Then
KeyboardHookProcedure = New HookProc(AddressOf CallHookProc)
'Dim hMod() As SystemReflectionModule = SystemReflectionAssemblyGetExecutingAssemblyGetModules()
'm_lHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, MarshalGetHINSTANCE(hMod(0)), 0)
m_lHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, MarshalGetHINSTANCE([Assembly]GetExecutingAssemblyGetModules()(0)), 0)
End If
End Sub
'打开线程钩子,开始监视扫描q
Public Sub StartThreadHook(ByVal threadID As Integer)
If m_lHook = 0 Then
KeyboardHookProcedure = New HookProc(AddressOf CallHookProc)
Dim hMod() As SystemReflectionModule = SystemReflectionAssemblyGetExecutingAssemblyGetModules
m_lHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, MarshalGetHINSTANCE(hMod(0)), threadID)
End If
End Sub
'关闭监视
Public Sub StopHook()
If m_lHook <> 0 Then
UnhookWindowsHookEx(m_lHook)
End If
End Sub
Private Sub CallHookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr)
If nCode >= 0 And wParam = WM_KEYDOWN And Not isHookLock Then
Dim m As KeyboardHookStruct = MarshalPtrToStructure(lParam, GetType(KeyboardHookStruct))
If mvkCode >= 48 And mvkCode <= 57 Then
If Not IsShift Then
DataBuff += (mvkCode - 48)ToString
Else
Select Case mvkCode
Case 49
DataBuff += "!"
Case 50
DataBuff += "@"
Case 51
DataBuff += "#"
Case 52
DataBuff += "$"
Case 53
DataBuff += "%"
Case 54
DataBuff += "^"
Case 55
DataBuff += "&"
Case 56
DataBuff += ""
Case 57
DataBuff += "("
Case 48
DataBuff += ")"
End Select
End If
ElseIf (mvkCode >= 65 And mvkCode <= 90) Then
'如果扫描的是字母
DataBuff += Chr(mvkCode)ToString
ElseIf (mvkCode = 189) Or (mvkCode = 109) Then
'如果扫描码是"-"
DataBuff += "-"
ElseIf mvkCode = 187 Then
'如果扫描码是"="或"+"
If Not IsShift Then
DataBuff += "="
Else
DataBuff += "+"
End If
ElseIf mvkCode = 190 Then
'如果扫描码是""或">"
If Not IsShift Then
DataBuff += ""
Else
DataBuff += ">"
End If
ElseIf mvkCode = 191 Then
'如果扫描码是"/"或""
If Not IsShift Then
DataBuff += "/"
Else
DataBuff += ""
End If
ElseIf mvkCode = 13 Then
'如果扫描的是回车
RaiseEvent OnBarCodeEvent(DataBuffReplace(Chr(13), ""))
DataBuff = ""
Else
'DataBuff += " "
End If
If mvkCode = 160 Then
'若有Shift键盘,就设置Shift为开状态,然后由其它流程就判断下一个键值是多少
IsShift = True
Else
IsShift = False
End If
End If
End Sub
End Class
============================
附赠键盘键值图,注意VB中Shift、Alt、Ctrl键值有些不一样,自己分步调试一下就能获得(Shift是160,其它您自己找把)
能监控的还挺多的。大概可以分为以下4种:聊天记录监控、文件管理、屏幕自动录制、管理权限设置等等,如果细分的话大概有200多种功能。
具体的有:实现监控员电脑、U盘 *** 作报警、多台电脑 同时监控、员工搜索记录监控、敏感关键字报警、管理者远程 *** 控、违规 *** 作报警、U盘插拔报警、电脑远程屏幕截图、聊天记录截图、文件 *** 作记录、网址历史访问记录、游戏程序管控、usb使用记录、电脑远程屏幕监控等。
1比如这个屏幕快照功能。被控端电脑的实时画面就可以看的一清二楚,当然还可以实时生成视频并保存,这样员工的一切 *** 作都是可追溯的。
2比如防止员工走私单功能。在后台设置敏感关键词,比如红包、私聊、离职等,员工只要在聊天工具中发送这些字眼,后台就会自动d窗,提醒管理者,这样就更高效的提高了公司管理。
3比如文件加密功能,对政企事业单位、大型IT企业来说也颇为重要。能对word、Excel、PPT、写字板等文字储存工具进行加密处理,可以做到内部良性循环,外发无法使用。
可以用activity里的public boolean dispatchKeyEvent(KeyEvent event)或者public boolean onKeyDown(int keyCode, KeyEvent event)这两个回调函数都可以监测按键事件。根据keyCode来确定具体按的什么键。 查看原帖>>
以上就是关于vb 键盘监控全部的内容,包括:vb 键盘监控、监控电脑能监控什么、如何在一个程序里监控系统虚拟键盘按键事件等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)