vb 鼠标移动的问题
添加多个. 数量不一定,有时候3个,有时候5个. (能把这些坐标
显示在文本框,或者列表框最好)
2. 按按钮2 ,先后将鼠标移到添加的坐标位置,按下
鼠标左键.
比方说,移到100,201,然后按下鼠标左键,再移到530,425,按下左键..
依次这样子.
请指教下代码.谢谢 展开
Option Explicit
'四个API : GetAsyncKeyState,mouse_event 和 GetCursorPos,SetCursorPos
'一个Timer,一个CommandButton
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 GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Command1_Click()
Dim dX As Integer, dY As Integer
Dim p As Long, k As Integer
For k = 1 To List1.ListCount
p = InStr(List1.List(k - 1), ",")
dX = CInt(Left(List1.List(k - 1), p - 1))
dY = CInt(Mid(List1.List(k - 1), p + 1))
SetCursorPos dX, dY
mouse_event &H6, 0, 0, 0, 0
Next k
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Command1.Caption = "执行"
End Sub
Private Sub Timer1_Timer()
Dim p As POINTAPI
GetCursorPos p
Me.Caption = "(" & CStr(p.X) & "," & CStr(p.Y) & ")"
If GetAsyncKeyState(vbKeyControl) And &H8000 Then
List1.AddItem CStr(p.X) & "," & CStr(p.Y)
ElseIf GetAsyncKeyState(vbKeyEscape) And &H8000 Then
'按下ESC 清除列表
List1.Clear
End If
End Sub
Private
Sub
Picture1_MouseDown(Button
As
Integer,
Shift
As
Integer,
x
As
Single,
y
As
Single)
Picture1.Picture
=
LoadPicture("空白图")
Screen.MousePointer
=
vbCustom
Screen.MouseIcon
=
LoadPicture("指针图")
SetCapture
(Picture1.hwnd)
End
Sub
Private
Sub
Picture1_MouseUp(Button
As
Integer,
Shift
As
Integer,
x
As
Single,
y
As
Single)
Picture1.Picture
=
LoadPicture("完整图")
Screen.MousePointer
=
vbDefault
End
Sub