我想编一个程序,内容是这样的
当我按下H健,文本中可以输入 A,延迟200ms,输入B,延迟200ms,输入C
而H,A,B,C,以及2个延迟都是可以手动输入改变的
请问我该怎么编写?
方法应该有很多,比如API函数,Sendkeys函数,还有驱动级别的

解决方案 »

  1.   

    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = Asc("h") Then
            KeyAscii = 0
            Text1.Text = Text1.Text & "A"
            Sleep 200
            Text1.Text = Text1.Text & "B"
            Sleep 200
            Text1.Text = Text1.Text & "C"
        End If
    End Sub
      

  2.   

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 72 Or KeyAscii = 104 Then
    Text1.Text = ""
    Dalay "A", 2000
    Dalay "B", 2000
    Dalay "C", 2000
    End If
    End Sub
    Private Sub Dalay(ByVal S As String, ByVal t As Integer)
    Sleep t
    SendKeys S
    DoEvents
    End Sub
      

  3.   

    四楼的不对,你的程序会是直接出来ABC,Sleep作用只是释放延迟了,不信自己试下
    五楼的思路对了,不过最后处理得有点问题,我如果按“H“,结果是ABCh
      

  4.   

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 72 Or KeyAscii = 104 Then
    Text1.Text = ""
    Dalay "A", 2000
    Dalay "B", 2000
    Dalay "C", 2000
    KeyAscii=0
    End If
    End SubPrivate Sub Dalay(ByVal S As String, ByVal t As Integer)
    Sleep t
    SendKeys S
    DoEvents
    End Sub
      

  5.   

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 72 Or KeyAscii = 104 Then
    Text1.Text = ""
    SendKeys "A"
    Sleep 2000
    DoEventsSendKeys "B"
    Sleep 2000
    DoEventsSendKeys "C"
    Sleep 2000
    KeyAscii = 0End If
    End Sub
    我给修改成这样了,总算成功了,只是不明白,为什么总是会有h?怎么还需要清空才行?
      

  6.   

    你输入了h,当然会有h,KeyAscii=0就不会显示了