'使用VBS例,下載dynwrap.dll,然后拷貝至c:\windows\system32,運行regsvr32 dynwrap.dll進行注冊
創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于成都網(wǎng)站制作、網(wǎng)站建設、蘄春網(wǎng)絡推廣、小程序開發(fā)、蘄春網(wǎng)絡營銷、蘄春企業(yè)策劃、蘄春品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供蘄春建站搭建服務,24小時服務熱線:028-86922220,官方網(wǎng)址: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}" '發(fā)送tab鍵移動焦點
ws.sendkeys "^v" '發(fā)送粘貼,確保剪切板有內容
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}")
有的時候會出現(xiàn)發(fā)送不完全,我也正在尋找更好的方法,多多交流。