黄昌水吧 关注:79贴子:1,357
  • 4回复贴,共1

sendkeys 例子

收藏回复



IP属地:广东1楼2011-03-24 00:40回复
    Option Explicit
        Private Sub Form_Load()
        Dim ReturnValue, I
        ReturnValue = Shell("CALC.EXE", 1) ' 运行计算器
        AppActivate ReturnValue ' 激活计算器
        For I = 1 To 100 ' 设置计数循环
          SendKeys I & "{+}", True ' 按下按键给计算器
        Next I ' 将所有 I 值相加
        SendKeys "=", True ' 取得总和
        SendKeys "%{F4}", True ' 按 ALT+F4 关闭计算器
        End Sub


    IP属地:广东2楼2011-03-24 00:40
    回复
      Option Explicit
          Private Sub Form_Load()
          Dim x
          x = Shell("D:\Program Files\Microsoft Office\Office\winword.exe", vbNormalFocus)
          '启动 Word97
          SendKeys "This is a demo program for Microsoft Word97.", True    ' 模拟输入英文字符串
          SendKeys "{Enter}{Enter}", True      ' 两次回车
          waittime (2)     ' 延时 2 秒
          SendKeys "Some letters keyin automatically.", True
          SendKeys "{Enter}{Enter}", True
          waittime (2)
          SendKeys "Not virus,and not hackers!", True
          SendKeys "{Enter}{Enter}", True
          waittime (2)
          SendKeys "Being Exit... Look the MenuBar File{(}F{)}...", True
          SendKeys "%", True 'Alt 键激活菜单条
          waittime (1)
          SendKeys "(F)", True '按字母 "F",选择"文件(F)"菜单
          waittime (1)
          SendKeys "(X)", True '按字母 "X", 选择"退出(X)"
          waittime (2)
          SendKeys "(N)", True 'Word 弹出一个对话框,询问文件是否存盘,按 "N" 不存盘
          End '结束本模拟程序
          End Sub
          Private Sub waittime(delay As Single)
          Dim starttime As Single
          starttime = Timer
          Do Until (Timer - starttime) > delay
          Loop
          End Sub
      


      IP属地:广东3楼2011-03-24 00:40
      回复
        Shell qq路径, vbMinimizedFocus
        Sleep 1000
        DoEvents
        SendKeys "+{tab}"
        SendKeys text1.text
        SendKeys "{tab}"
        SendKeys text2.text
        SendKeys "{enter}"


        IP属地:广东4楼2011-03-24 01:08
        回复
          Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
          Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
          Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
          Private Const WM_SETTEXT = &HC
          Private Sub Command1_Click()Dim hwnd As Long, Thwnd As LongShell "notepad.exe", 2 '打开一个记事本,将它最小化
          hwnd = FindWindow("Notepad", "无标题 - 记事本") '得到记事本句柄
          Thwnd = FindWindowEx(hwnd, 0, "Edit", vbNullString) '得到记事本句柄(就是我们写字的那里)
          SendMessage Thwnd, WM_SETTEXT, 0, ByVal "好了,快给我分" '向记事本写入文字End Sub


          IP属地:广东5楼2011-03-24 01:12
          回复