【求援助】按键盘,让鼠标单击,求思路
大神帮帮忙!比如按下Q键,让鼠标右键在300,200处,单击一下,什么思路啊
最好写个例子看看。。
[ 本帖最后由 mmttvv11 于 2014-4-3 17:32 编辑 ]
'新建一个VB工程,把form1的KeyPreview属性设置为True。这样,当有按键操作时,首先执行form1的KeyPress事件 '需要用到2个API函数,SetCursorPos用来设置光标位置,mouse_event模拟鼠标按键 Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '鼠标右键,按下和弹起,对应的常量 Private Const MOUSEEVENTF_RIGHTDOWN As Long = &H8 Private Const MOUSEEVENTF_RIGHTUP As Long = &H10 '下面,模拟按键操作 Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = Asc("Q") Or KeyAscii = Asc("q") Then '如果按下Q建 SetCursorPos 300, 200 '鼠标移动到(300,200)处 mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 '鼠标右键按下 mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 '鼠标右键抬起 End If End Sub