按键精灵2014
NO.1-同步的前提前提1 同步的两个窗口需要是同一个应用窗口,并且窗口大小要相同2 同步窗口可以接收到按键的键鼠发送信息3 同步的窗口支持后台键鼠操作
NO.2-本节例子及其能实现的功能例子1 画图工具,实现同步画图2 记事本,实现同步删除内容功能 ① 键鼠同步 ② 支持组合键
NO.3-思路大剖析思路步骤1 获取主窗口和被同步窗口句柄● WaitKey 命令等待键盘按下○ 按下F6则获取当前鼠标指向的窗口句柄,作为主窗口句柄。○ 按下F7 则获取当前鼠标指向的窗口句柄,作为同步窗口句柄。● 用Do循环来等待按键,当主窗口句柄和同步窗口句柄都获取到时,退出Do循环● 代码Do Key = WaitKey() If Key = 117 Then 主窗口 = Plugin.Window.MousePoint() End If If Key = 118 Then 同步窗口 = Plugin.Window.MousePoint() End If Delay 500 If 主窗口 <> 0 and 同步窗口 <> 0 Then Exit Do End IfLoop2 设置两个窗口的窗口大小一致● 窗口大小一致,同步的时候鼠标才能移动到正确的位置。● 代码 Call Plugin.Window.Size(主窗口,800,600) Call Plugin.Window.Size(同步窗口,800,600)3 获取主窗口的左上角坐标● GetWindowRect 命令获取主窗口的左上角坐标● 代码 sRect = Plugin.Window.GetWindowRect(主窗口) dim MyArray MyArray = Split(sRect, '|') L = Clng(MyArray(0)): T = Clng(MyArray(1))4 获取当前鼠标在主窗口的位置● GetCursorPos命令获取当前鼠标位置● 代码 GetCursorPos mx, my5 计算主窗口内当前鼠标位置和窗口左上角距离● 公式:当前鼠标位置减去窗口左上角坐标值( mx-L, my-T)6 开始同步● 被同步窗口,使用按键后台键鼠命令,将鼠标移动到和主窗口相同的位置( 按键后台命令鼠标移动是以窗口客户区左上角坐标为基点)● 代码 Call Plugin.Bkgnd.MoveTo(同步窗口, mx-L, my-T)●在主窗口内按下任意键时,同步窗口也执行同样的操作● 代码 Key = GetLastKey() Call Plugin.Bkgnd.KeyPress(同步窗口, Key)
NO.4-代码代码Do Key = WaitKey() If Key = 117 Then 主窗口 = Plugin.Window.MousePoint() //Call Plugin.Window.Size(主窗口,800,600) End If If Key = 118 Then 同步窗口 = Plugin.Window.MousePoint() // Call Plugin.Window.Size(同步窗口,800,600) End If Delay 500 If 主窗口 <> 0 and 同步窗口 <> 0 Then Exit Do End IfLoopDo Mouse = GetLastClick() If Mouse = 32769 Then //鼠标左键按下时ASCII码为 32769 sRect = Plugin.Window.GetWindowRect(主窗口) dim MyArray MyArray = Split(sRect, '|') L = Clng(MyArray(0)): T = Clng(MyArray(1)) GetCursorPos mx, my Delay 10 Call Plugin.Bkgnd.LeftDown(同步窗口, mx-L, my-T) Delay 10 Do Mouse = GetLastClick() If Mouse = 0 Then //鼠标无点击操作 GetCursorPos mx, my Delay 10 Call Plugin.Bkgnd.MoveTo(同步窗口, mx-L, my-T) Delay 10 End If If Mouse = 32770 Then //鼠标左键弹起时ASCII码为 32770 GetCursorPos mx, my Delay 10 Call Plugin.Bkgnd.LeftUp(同步窗口, mx-L, my-T) Exit Do End If Loop End If Key = GetLastKey() Call Plugin.Bkgnd.KeyPress(同步窗口, Key)Loop
NO.5-效果演示演示画图 记事本 注意 画图和记事本,获取窗口句柄的时候请点击白白的客户区进行获取,因为我们是要对它的客户区进行操作
NO.6-温馨小提示温馨小提示 * 游戏窗口中的同步,需要注意几个窗口中人物的朝向和坐标是否相同 * 如果坐标朝向不同,一个窗口里的角色往西边走一个往北边走,就无法达到预期同步任务的效果