c语言:鼠标和键盘函数的相关问题

2024-11-19 12:19:49
推荐回答(1个)
回答1:

通过调用API
mouse_event,SetCursorPos实现鼠标的模拟
给你点简单的代码自己研究下
想自己动手是好事
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
Declare
Function
SetCursorPos
Lib
"user32"
(ByVal
x
As
Long,
ByVal
y
As
Long)
As
Long
Const
MOUSEEVENTF_LEFTDOWN
=
&H2
Const
MOUSEEVENTF_LEFTUP
=
&H4
Const
MOUSEEVENTF_MIDDLEDOWN
=
&H20
Const
MOUSEEVENTF_MIDDLEUP
=
&H40
Const
MOUSEEVENTF_MOVE
=
&H1
Const
MOUSEEVENTF_ABSOLUTE
=
&H8000
Const
MOUSEEVENTF_RIGHTDOWN
=
&H8
Const
MOUSEEVENTF_RIGHTUP
=
&H10
Private
Sub
Command1_Click()
SetCursorPos
Val(400),
Val(0)
mouse_event
MOUSEEVENTF_LEFTDOWN
Or
MOUSEEVENTF_LEFTUP,
0,
0,
0,
0
End
Sub
Private
Sub
Command2_Click()
mouse_event
MOUSEEVENTF_MOVE,
210,
200,
0,
0
SetCursorPos
Val(300),
Val(300)
mouse_event
MOUSEEVENTF_RIGHTDOWN
Or
MOUSEEVENTF_RIGHTUP,
0,
0,
0,
0
End
Sub