VB 在指定文本框内输入指定字符代码

如题所述

第1个回答  2020-05-07
实现倒是可以实现,不过有些麻烦,我不知道你要用于哪方面,做了个例子给你看,简单的自动登陆代码。
Private
Declare
Function
GetAsyncKeyState
Lib
"user32"
(ByVal
vKey
As
Long)
As
Integer
Private
Sub
Command1_Click()
If
Text1.Text
=
"账号"
And
Text2.Text
=
"密码"
Then
MsgBox
"登陆成功",
vbOKOnly,
"提示"
Else
MsgBox
"登陆失败",
vbOKOnly,
"提示"
End
If
End
Sub
Private
Sub
Form_Load()
Timer2.Enabled
=
False
Timer2.Interval
=
300
Timer1.Interval
=
200
End
Sub
Private
Sub
Timer1_Timer()
If
GetAsyncKeyState(vbKeyF1)
Then
Timer2.Enabled
=
True
End
If
End
Sub
Private
Sub
Timer2_Timer()
Static
a
As
Integer
a
=
a
+
1
If
a
=
1
Then
AppActivate
"用户登陆"
Text1.SetFocus
ElseIf
a
=
2
Then
SendKeys
"账号"
ElseIf
a
=
3
Then
SendKeys
"{TAB}"
ElseIf
a
=
4
Then
SendKeys
"密码"
ElseIf
a
=
5
Then
Call
Command1_Click
a
=
0
Timer2.Enabled
=
False
End
If
End
Sub
其它的也一样,比如QQ,先用shell
"C:\qq.exe"
'这里是你QQ的地址。
然后用appactevate
"QQ2012"
'这里是你QQ标题
然后用我上面的sendkeys,其它的窗口也一样。
相似回答