窗口的键盘鼠标模拟,可以用来实现后台窗口操作
//向窗口发送键盘,鼠标消息,窗口后台操作也可以
import winex
import winex.key
import winex.mouse
import process.popen
var $key = winex.key
var $mouse = winex.mouse
//在64位系统会返回64位进程,兼容32位系统才可修改标题
process.popen.cmd64("notepad.exe")
var $hwnd,$hEdit = winex.wait("记事本",,"Notepad","Edit")
var $text =
/*
1
2
3
4
5
6
7
8
9
10
*/
//设置文本用来演示效果
winex.setText($hEdit,$text)
win.setPos($hwnd,100,100,500,300)
//附加到外部线程窗口,保证后台输入成功
if winex.attach($hEdit) win.msgbox("附加线程成功")
/*模拟按键{{*/
//最小化窗口,后面的操作用后台完成
win.show($hwnd,6/*_SW_MINIMIZE*/)
win.setFocus($hEdit)
//分别发送WM_KEYDOWN,WM_CHAR,WM_KEYUP消息模拟键盘打字
$key.send($hEdit,"你好Test")
//模拟键盘按下K键,发送wm_keydown消息
$key.down($hEdit,"K")
//弹起K键,发送wm_up消息
$key.up($hEdit,"K")
//设置击键的间隔时间100毫秒,默认是5毫秒
$key.delayClick = 100
//模拟按下K键
$key.click($hEdit,"k")
//发送组合键,必须先附加线程 winex.attach
win.showForeground($hwnd) //还原看效果
$key.combine($hEdit,"CTRL","A") //全选
/*}}*/
win.delay(4000)
//发送 _wm_mousemove消息,模拟鼠标移动
$mouse.move($hEdit,50,80)
//发送 WM_LBUTTONDOWN 和 WM_LBUTTONUP消息,模拟按下和弹起
$mouse.down($hEdit,100,100)
$mouse.up($hEdit,100,100)
//模拟在窗口位置点击
$mouse.click($hEdit,100,200)
//发送 WM_LBUTTONDBLCLK 消息,模拟左键双击
$mouse.clickDB($hEdit,100,300)
//右键点击,其它函数跟左键一样
$mouse.rb.click($hEdit,100,300)
//模拟中键向下向上滑动,其它函数跟左键一样
$mouse.mb.roll($hEdit,100,200,100)
$mouse.mb.roll($hEdit,100,200,-100)
————————————————
版权声明:本文为CSDN博主「风行者_」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_60842374/article/details/120089783