如何用VB编写一个向指定窗口发送键盘命令的程序?
答案:3 悬赏:10 手机版
解决时间 2021-04-15 22:02
- 提问者网友:不爱我么
- 2021-04-15 17:00
如何用VB编写一个向指定窗口发送键盘命令的程序?
最佳答案
- 五星知识达人网友:由着我着迷
- 2021-04-15 17:21
用 Api函数 keybd_event
具体定义
Private Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
keybd_event 17, vbNull, &H2, vbNull
17 是要模拟的按键 17 是 ctrl 键
&H2模拟按键的动作 &H2是按下弹起
mouse_event 是模拟鼠标
具体定义
Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
mouse_event &H2,vbnull,vbnull,vbnull,vbnull
&H2是要模拟的动作
移动鼠标 =&H1
模拟鼠标左键按下 =&H2
模拟鼠标左键抬起 =&H4
模拟鼠标右键抬起 =&H8
模拟鼠标右键按下 =&H10
模拟鼠标中键按下 =&H20
模拟鼠标中键抬起=&H40参考资料:-原创-
具体定义
Private Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
keybd_event 17, vbNull, &H2, vbNull
17 是要模拟的按键 17 是 ctrl 键
&H2模拟按键的动作 &H2是按下弹起
mouse_event 是模拟鼠标
具体定义
Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
mouse_event &H2,vbnull,vbnull,vbnull,vbnull
&H2是要模拟的动作
移动鼠标 =&H1
模拟鼠标左键按下 =&H2
模拟鼠标左键抬起 =&H4
模拟鼠标右键抬起 =&H8
模拟鼠标右键按下 =&H10
模拟鼠标中键按下 =&H20
模拟鼠标中键抬起=&H40参考资料:-原创-
全部回答
- 1楼网友:長槍戰八方
- 2021-04-15 19:59
没有看懂你的意思
- 2楼网友:罪歌
- 2021-04-15 18:47
用函数 sendkey
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯