Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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 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 Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function timeGetTime Lib "winmm.dll" () As LongPrivate Type POINTAPI
x   As Long
y   As Long
End Type
Const VK_F1 = &H70Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H8
Dim ii As IntegerPrivate Sub AllClear_Click()
List1.Clear
ii = 0
End SubPrivate Sub Command1_Click()
Print "1"
End SubPrivate Sub Command2_Click()
Print "2"
End SubPrivate Sub Command3_Click()
Print "3"
End SubPrivate Sub Form_Load()
Timer2.Enabled = True
End SubPrivate Sub Input_Click()
Dim str As String
CMD1.Filter = "文档文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CMD1.ShowOpen
On Error Resume Next
AllClear_Click
Open CMD1.FileName For Input As #1
Do While Not EOF(1)
    Line Input #1, str
    List1.AddItem str
Loop
Close 1
End SubPrivate Sub Modify_Click()
Dim str1 As String, str2 As String
Dim point
str1 = List1.List(List1.ListIndex)
point = Split(str1, ";", -1, 1)
point(2) = DelayTime.Text
point(3) = KeyNumber.Text
List1.List(List1.ListIndex) = point(0) & point(1) & point(2) & point(3)
End SubPrivate Sub OutPut_Click()
CMD1.Filter = "文档文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CMD1.ShowSave
On Error Resume Next
Open CMD1.FileName For Output As #1
For i = 0 To List1.ListCount - 1
    str1 = List1.List(i)
    Print #1, str1
Next i
Close 1
End SubPrivate Sub Remove_Click()
Dim str1 As String, ii As Integer, str2 As String, str3 As String
Dim point
ii = List1.ListIndex
List1.RemoveItem (List1.ListIndex)
For i = ii To List1.ListCount - 1
    If i >= 1 And i <= 7 Then
        str1 = List1.List(i)
        point = Split(str1, ":", -1, 1)
        str2 = Mid(point(0), 2, 1)
        str3 = Trim(Replace(point(0), str2, (i + 1), , , 1))
        List1.List(i) = str3 & ":" & point(1)
    End If
    If i >= 8 And i <= 97 Then
        str1 = List1.List(i)
        point = Split(str1, ":", -1, 1)
        str2 = Mid(point(0), 2, 2)
        str3 = Trim(Replace(point(0), str2, (i + 1), , , 1))
        List1.List(i) = str3 & ":" & point(1)
    End If
Next i
End Sub
'問題所在的代碼
Private Sub Timer1_Timer()
Static i As Integer
Dim str1 As String, str2 As String
Dim pointIf i = List1.ListCount Then
    i = 0
End If    str1 = List1.List(i)
    str2 = Mid(str1, 11, 10)
    point = Split(str2, ",", -1, 1)
    
    SetCursorPos point(0), point(1)
                    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0            '设置鼠标左键按下
                    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0              '设置鼠标左键弹出
    
    Delay (100)
i = i + 1
End SubPrivate Function Delay(LMSceond As Long)
        Dim TI As Long
        If LMSceond < 5 Then Exit Function
        TI = timeGetTime
        Do While timeGetTime - TI < LMSceond
           DoEvents
        Loop
Exit Function
End FunctionPrivate Sub Timer2_Timer()
Dim z As POINTAPI
x = GetAsyncKeyState(122)
If x = -32767 Then
    Timer1.Enabled = True
End Ifx = GetAsyncKeyState(123)
If x = -32767 Then
    Timer1.Enabled = False
End Ifx = GetAsyncKeyState(121)
If x = -32767 Then
    GetCursorPos z
    List1.AddItem "第" & ii + 1 & "步坐标为:" & Space(3) & z.x & "," & z.y & Space(3) & ":" & DelayTime.Text & Space(3) & ":" & KeyNumber.Text
    ii = ii + 1
End IfEnd Sub
問題是 運行是不會按鍵(左鍵)
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0            '设置鼠标左键按下
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0              '设置鼠标左键弹出
能延時  
但是 循環兩次行 (兩個坐標循環可以,但是上了兩個坐標以上循環他就不按鍵了)希望用高手能幫我解決一下

解决方案 »

  1.   

    沒人回答嗎 我自己先Ding 一下
      

  2.   

    晕 了 这很难吗 没人回答 ,还是太容易了 没人回答 。  
    CSDN 上不会没人 知道 吧 牛人不是很多吗 ??  这个问题值得考虑。。
      

  3.   

    代码与界面不相关,界面有5个按钮,代码中有9个按钮。
    你可将整个工程文件和相关文件发EMAIL
    [email protected]
      

  4.   

    按你发给我的代码,修改了获取屏幕设置参数。用于鼠标输入坐标的限制设置:
    Option Explicit
        Dim Xset As Integer
        Dim Yset As IntegerPrivate Sub Form_Load()
        '==============================
        '功能:读取脚本
        '参数:script.txt -> 脚本文件名
        '==============================
        Dim Scriptemp As String
        
        If Dir(App.Path + "\script.txt") = "" Then
            Open App.Path + "\script.txt" For Output As #1
            Close #1
        End If
        
        Open App.Path + "\script.txt" For Input As #1
            While Not EOF(1)
                Line Input #1, Scriptemp
                Script.AddItem Scriptemp
            Wend
        Close #1
         '获取屏幕像素
        Xset = Screen.Width / Screen.TwipsPerPixelX
        Yset = Screen.Height / Screen.TwipsPerPixelY
    End Sub'处理坐标是否超出一定长度
    Private Sub MouseX_Change()
        If MouseX.Text > Xset Then
            MsgBox "坐标错误,请重新输入"
            MouseX.Text = ""
        End If
    End SubPrivate Sub MouseY_Change()
        If MouseY.Text > Yset Then
            MsgBox "坐标错误,请重新输入"
            MouseY.Text = ""
        End If
    End Sub
      

  5.   

    MouseX_Change
    MouseY_Change
    您 加了两个文本控件   ?
      

  6.   

    Option Explicit
        Dim intIndex As Integer
    Private Sub Command1_Click()
        Script.AddItem ("坐标:" & MouseX.Text & "-" & MouseY.Text)
    End SubPrivate Sub Command2_Click()
        Script.AddItem ("鼠标:左键")
    End SubPrivate Sub Command3_Click()
        Script.AddItem ("鼠标:右键")
    End SubPrivate Sub Command4_Click()
        If KeyText.Text <> "" Then
            Script.AddItem ("键盘:" & KeyText.Text)
        End If
    End SubPrivate Sub Command5_Click()
    '==============================
    '功能:保存脚本
    '参数:script.txt -> 脚本文件名
    '==============================
    Dim i As Integer
    Open App.Path + "\script.txt" For Output As #1
        For i = 1 To Script.ListCount
            Print #1, Script.List(i - 1)            '这里使用 i-1 是因为 ListBox 控件是从 0 开始
        Next i
    Close #1
    MsgBox "保存完毕!", vbOKOnly, "保存脚本"
    End Sub
    Private Sub Command6_Click()
    End
    End SubPrivate Sub Command7_Click()
    Call Start
    End SubPrivate Sub cmdClear_Click()
        Script.Clear
        ii = 0
    End SubPrivate Sub cmdLoad_Click()
        ULoad
    End SubPrivate Sub ULoad()
        '==============================
        '功能:读取脚本
        '参数:script.txt -> 脚本文件名
        '==============================
        Dim Scriptemp As String
        
        If Dir(App.Path + "\script.txt") = "" Then
            Open App.Path + "\script.txt" For Output As #1
            Close #1
        End If
        
        Open App.Path + "\script.txt" For Input As #1
            While Not EOF(1)
                Line Input #1, Scriptemp
                Script.AddItem Scriptemp
            Wend
        Close #1
    End SubPrivate Sub cmdDel_Click() '删除选中单项
        Script.RemoveItem (intIndex)
    End SubPrivate Sub Form_Load()
        ULoad
    End SubPrivate Sub KeyText_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case 112
            KeyText.Text = "F1"
        Case 113
            KeyText.Text = "F2"
        Case 114
            KeyText.Text = "F3"
        Case 115
            KeyText.Text = "F4"
        Case 116
            KeyText.Text = "F5"
        Case 117
            KeyText.Text = "F6"
        Case 118
            KeyText.Text = "F7"
        Case 119
            KeyText.Text = "F8"
        Case 120
            KeyText.Text = "F9"
        Case 121
            KeyText.Text = "F10"
        Case 122
            KeyText.Text = "F11"
        Case 123
            KeyText.Text = "F12"
        Case Else
            KeyText.Text = Chr(KeyCode)
    End Select
    End Sub'处理坐标是否超出一定长度
    Private Sub MouseX_Change()
    If Val(MouseX.Text) > 1024 Then
        MsgBox "坐标错误,请重新输入"
        MouseX.Text = ""
    End If
    End SubPrivate Sub MouseY_Change()
        If Val(MouseY.Text) > 768 Then
            MsgBox "坐标错误,请重新输入"
            MouseY.Text = ""
        End If
    End SubPrivate Sub Script_Click() '选中项删除
        intIndex = Script.ListIndex
        Script.RemoveItem (intIndex)
    End Sub