求记事本自动打字vb代码 不是vbs
展开全部
在这里有个参考代码,很简单
Private Sub Form_Load()
Dim x
x = Shell("Notepad.exe", vbNormalFocus)
SendKeys "这是一个文本文件的测试程序.", True ' 模拟输入英文字符串
SendKeys "{Enter}{Enter}", True ' 两次回车
waittime (2) ' 延时 2 秒
SendKeys "自动输入文字", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "既不是病毒,也不是木马!", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "开始退出... 看菜单项{(}F{)}...", True
SendKeys "%", True 'Alt 键激活菜单条
waittime (1)
SendKeys "(F)", True '按字母 "F",选择"文件(F)"菜单
waittime (1)
SendKeys "(X)", True '按字母 "X", 选择"退出(X)"
waittime (2)
SendKeys "(N)", True '弹出一个对话框,询问文件是否存盘,按 "N" 不存盘
End '结束本模拟程序
End Sub
Private Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
Loop
End Sub
Private Sub Form_Load()
Dim x
x = Shell("Notepad.exe", vbNormalFocus)
SendKeys "这是一个文本文件的测试程序.", True ' 模拟输入英文字符串
SendKeys "{Enter}{Enter}", True ' 两次回车
waittime (2) ' 延时 2 秒
SendKeys "自动输入文字", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "既不是病毒,也不是木马!", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "开始退出... 看菜单项{(}F{)}...", True
SendKeys "%", True 'Alt 键激活菜单条
waittime (1)
SendKeys "(F)", True '按字母 "F",选择"文件(F)"菜单
waittime (1)
SendKeys "(X)", True '按字母 "X", 选择"退出(X)"
waittime (2)
SendKeys "(N)", True '弹出一个对话框,询问文件是否存盘,按 "N" 不存盘
End '结束本模拟程序
End Sub
Private Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
Loop
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Const WM_SETTEXT = &HC
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 Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetDlgItem _
Lib "user32" (ByVal hDlg As Long, _
ByVal nIDDlgItem As Long) As Long
Private Sub Command1_Click()
Dim s As String
Dim FT_hWnd As Long
Dim ID_Control_hWnd As Long
s = "你好" '想要发送的字符串
Shell "notepad", vbNormalFocus
FT_hWnd = FindWindow(vbNullString, "无标题 - 记事本")
If FT_hWnd = 0 Then
MsgBox "False", vbInformation, "Title"
End
End If
ID_Control_hWnd = GetDlgItem(FT_hWnd, &HF)
SendMessage ID_Control_hWnd, WM_SETTEXT, 0, ByVal s
End Sub
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 Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetDlgItem _
Lib "user32" (ByVal hDlg As Long, _
ByVal nIDDlgItem As Long) As Long
Private Sub Command1_Click()
Dim s As String
Dim FT_hWnd As Long
Dim ID_Control_hWnd As Long
s = "你好" '想要发送的字符串
Shell "notepad", vbNormalFocus
FT_hWnd = FindWindow(vbNullString, "无标题 - 记事本")
If FT_hWnd = 0 Then
MsgBox "False", vbInformation, "Title"
End
End If
ID_Control_hWnd = GetDlgItem(FT_hWnd, &HF)
SendMessage ID_Control_hWnd, WM_SETTEXT, 0, ByVal s
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询