- 按键认证大神
- 8648672
- 35
- 11
- 573 朵
- 299 个
- 159 个
- 0
- 2022-03-06
|
2#
t
T
发表于 2022-05-09 12:30
|
|只看楼主
星月扩展库发布贴(这个工程使用xyapi插件实现): http://bbs.anjian.com/showtopic-664233-1.aspx键鼠录制的核心功能由 xyapi 的这四个函数实现: - // HOOK库
- Declare Sub Hook_InsKey_LowLevel Lib "xyapi.dll" (ByVal EventProc As Long)
- Declare Sub Hook_DelKey_LowLevel Lib "xyapi.dll" ()
- Declare Sub Hook_InsMouse_LowLevel Lib "xyapi.dll" (ByVal EventProc As Long)
- Declare Sub Hook_DelMouse_LowLevel Lib "xyapi.dll" ()
复制代码这四个函数可以挂钩低级键鼠HOOK,从而在键盘和鼠标做动作的时候,将这些动作记录下来。 安装HOOK的时候有一个参数,是用来接收事件的标签控件句柄,这个用法和原理可以参考这个帖子: http://bbs.anjian.com/showtopic-699851-1.aspx之后我们处理两个事件,把获得的键盘和鼠标动作记录下来,就形成了我们需要的功能。 - // 键盘HOOK事件
- Event Form1.KHook.Click
- // 处理参数
- Dim Param = Split(Form1.KHook.Caption, "|")
- Dim iCode = CLng(Param(1))
- Dim wParam = CLng(Param(2))
- Dim wVk = CLng(Param(3))
- Dim wScan = CLng(Param(4))
- Dim dwFlags = CLng(Param(5))
- Dim Time = CLng(Param(6))
- Dim dwExtraInfo = CLng(Param(7))
- // 录制逻辑
- If iCode = 0 Then
- Dim NewTime = GetTickCount()
- RecordScript = RecordScript & "Delay(" & (NewTime - OldTime) & ")\r\n"
- OldTime = NewTime
- Select Case wParam
- Case 260, 256 // WM_SYSKEYDOWN, WM_KEYDOWN
- If WindowMode Then // 后台
- If GetForegroundWindow() = RecordWindow Then
- RecordScript = RecordScript & "dm.KeyDown(" & wVk & ")\r\n"
- End If
- Else // 前台
- RecordScript = RecordScript & "KeyDown(" & wVk & ")\r\n"
- End If
- Case 261, 257 // WM_SYSKEYUP, WM_KEYUP
- If WindowMode Then // 后台
- If GetForegroundWindow() = RecordWindow Then
- RecordScript = RecordScript & "dm.KeyUp(" & wVk & ")\r\n"
- End If
- Else // 前台
- RecordScript = RecordScript & "KeyUp(" & wVk & ")\r\n"
- End If
- End Select
- End If
- End Event
- // 鼠标HOOK事件
- Event Form1.MHook.Click
- // 处理参数
- Dim Param = Split(Form1.MHook.Caption, "|")
- Dim iCode = CLng(Param(1))
- Dim wParam = CLng(Param(2))
- Dim dx = CLng(Param(3))
- Dim dy = CLng(Param(4))
- Dim mouseData = CLng(Param(5)) \ 120
- Dim dwFlags = CLng(Param(6))
- Dim Time = CLng(Param(7))
- Dim RetXY = Window_ConvS2C(RecordWindow, dx, dy)
- // 录制逻辑
- If iCode = 0 Then
- Dim NewTime = GetTickCount()
- Dim KeyTbl = {513:"MouseDown(0)", 514:"MouseUp(0)", 516:"MouseDown(1)", 517:"MouseUp(1)", 519:"MouseDown(2)", 520:"MouseUp(2)"}
- Dim KeyTblDM = {513:"dm.LeftDown()", 514:"dm.LeftUp()", 516:"dm.RightDown()", 517:"dm.RightUp()", 520:"dm.MiddleClick()"}
- Select Case wParam
- Case 512 // WM_MOUSEMOVE
- If StepMove Then // 仅在开启 记录完整的鼠标移动轨迹 时录制
- If NewTime <> OldTime Then // 仅在时间变化时记录轨迹 [为了降低代码量]
- RecordScript = RecordScript & "Delay(" & (NewTime - OldTime) & ")\r\n"
- OldTime = NewTime
- If WindowMode Then // 后台 [只在窗口激活并且鼠标在窗口范围内才记录]
- If GetForegroundWindow() = RecordWindow Then
- If Window_GetRoot(Window_FormMouse()) = RecordWindow Then
- RecordScript = RecordScript & "dm.MoveTo(" & HiWord(RetXY) & ", " & LoWord(RetXY) & ")\r\n"
- End If
- End If
- Else // 前台
- If RelaMove Then
- RecordScript = RecordScript & "MouseMove(" & (dx - OldPointX) & ", " & (dy - OldPointY) & ", true)\r\n"
- OldPointX = dx
- OldPointY = dy
- Else
- RecordScript = RecordScript & "MouseMove(" & dx & ", " & dy & ")\r\n"
- End If
- End If
- End If
- End If
- Case 513, 514, 516, 517, 519, 520 // WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP
- If NewTime <> OldTime Then
- RecordScript = RecordScript & "Delay(" & (NewTime - OldTime) & ")\r\n"
- OldTime = NewTime
- End If
- If WindowMode Then // 后台
- If GetForegroundWindow() = RecordWindow Then
- If Window_GetRoot(Window_FormMouse()) = RecordWindow Then
- RecordScript = RecordScript & "dm.MoveTo(" & HiWord(RetXY) & ", " & LoWord(RetXY) & ")\r\n"
- If wParam <> 519 Then
- RecordScript = RecordScript & KeyTblDM[wParam] & "\r\n"
- End If
- End If
- End If
- Else // 前台
- If RelaMove Then
- RecordScript = RecordScript & "MouseMove(" & (dx - OldPointX) & ", " & (dy - OldPointY) & ", true)\r\n"
- RecordScript = RecordScript & KeyTbl[wParam] & "\r\n"
- OldPointX = dx
- OldPointY = dy
- Else
- RecordScript = RecordScript & "MouseMove(" & dx & ", " & dy & ")\r\n"
- RecordScript = RecordScript & KeyTbl[wParam] & "\r\n"
- End If
- End If
- Case 522 // WM_MOUSEWHEEL
- If NewTime <> OldTime Then
- RecordScript = RecordScript & "Delay(" & (NewTime - OldTime) & ")\r\n"
- OldTime = NewTime
- End If
- If WindowMode Then // 后台
- If GetForegroundWindow() = RecordWindow Then
- If Window_GetRoot(Window_FormMouse()) = RecordWindow Then
- If mouseData > 0 Then
- RecordScript = RecordScript & "dm.WheelUp()\r\n"
- Else
- RecordScript = RecordScript & "dm.WheelDown()\r\n"
- End If
- End If
- End If
- Else // 前台
- RecordScript = RecordScript & "MouseWheel(" & mouseData & ")\r\n"
- End If
- End Select
- End If
- End Event
复制代码大家也可以把代码记录成自己喜欢的格式,我这里用了大漠插件,各位也可以尝试换成乐玩之类的插件,这个脚本的可玩性还是很大的,甚至用按键再开发一个按键,也不无可能哦。
|