'使用VBS例,下载dynwrap.dll,然后拷贝至c:\windows\system32,运行regsvr32 dynwrap.dll进行注册
创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站制作、网站建设、蕲春网络推广、小程序开发、蕲春网络营销、蕲春企业策划、蕲春品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供蕲春建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com
Set ws=CreateObject("WSCript.shell")
Set Wrap1 = CreateObject("DynamicWrapper")
Wrap1.Register "USER32.DLL", "FindWindow","I=ss","f=s", "R=l"
Wrap1.Register "USER32.DLL", "SetForegroundWindow", "I=h", "f=s", "R=l"
hWin = Wrap1.FindWindow(vbNullString, CStr("窗口名称"))
if hWin 0 then
Clipboard = "MsHta vbscript:ClipBoardData.setData(""Text"",""" "您要输入的文本" """)(Close)"
ws.Run(Clipboard) '复制文本
ws.sendkeys "{tab}" '发送tab键移动焦点
ws.sendkeys "^v" '发送粘贴,确保剪切板有内容
end if
假如Form1有个TextBox1,双击TextBox1填入123
Public Class Form1
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.DoubleClick
System.Windows.Forms.SendKeys.Send("123")
End Sub
End Class
看你的VB.NET 版本了
用 My.Computer.Keyboard.SendKeys("123", True) 代替 System.Windows.Forms.SendKeys.Send("123") 也可以
原码:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.DoubleClick
My.Computer.Keyboard.SendKeys("123", True)
End Sub
End Class
private
sub
Command1_click()
'点击按钮事件
Dim
x
As
String
'定义变量
Text1.SetFocus
'文本框获得焦点,只要鼠标自动到达文本框
Open
"d:\ab\12.txt"
For
Input
As
#1
'打开文本文件,文本文件的路径和文件名是d:\ab\12.txt,修改为你需要的路径和文件名
Input
#1,
x
'读取文本文件的内容到变量x中
Close
#1
'关闭打开的文本文件
Text1.Text
=
x
'将变量x的值赋值给文本框控件
End
Sub
'事件结束
Dim myexe As Integer
myexe = Shell("xxx.exe")
AppActivate(myexe)
System.Threading.Thread.Sleep(50)
System.Windows.Forms.SendKeys.Send("帐号")
System.Threading.Thread.Sleep(50)
System.Windows.Forms.SendKeys.Send("{tab}")
System.Threading.Thread.Sleep(50)
System.Windows.Forms.SendKeys.Send("密码")
System.Threading.Thread.Sleep(50)
System.Windows.Forms.SendKeys.Send("{Enter}")
有的时候会出现发送不完全,我也正在寻找更好的方法,多多交流。