中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-25 17:40
47,813 topics / 349,918 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » How to make a VBS script automatically input a line of text in Notepad
Printable Version  1,879 / 8
Floor1 flandy Posted 2007-06-24 23:43
初级用户 Posts 40 Credits 94
Let a VBS script automatically input a line of text in Notepad, and let the script automatically input the following two short sentences

This is the most wonderful day of my life
because I'm here with you now

After inputting the short sentences, automatically close Notepad and save the file with the name "test". The combination key Alt + F4 can be directly used to close Notepad
Floor2 lxmxn Posted 2007-06-25 00:26
版主 Posts 4,938 Credits 11,386
Is it to simulate the effect of "typing input"?
Floor3 terse Posted 2007-06-25 00:29
银牌会员 Posts 946 Credits 2,404
Search it out

dim ws
set ws=wscript.createobject("wscript.shell")
str = "This is the most wonderful day of my life$because I'm here with you now"
Num = len(str)
ws.run("notepad.exe")
wscript.sleep 100
for i = 1 to Num
Input = Mid(str, i, 1)
if Input = "$" then Input = vbCr
wscript.sleep 100
ws.sendkeys(Input)
next
WS.SendKeys "^s"
WScript.Sleep 100
WS.SendKeys "test"
WScript.Sleep 100
WS.SendKeys "{ENTER}"
WS.SendKeys "%{f4}"

This one has no typing effect
dim ws
set ws=wscript.createobject("wscript.shell")
ws.run("notepad.exe")
wscript.sleep 100
ws.sendkeys "because I'm here with you now"
wscript.sleep 100
WS.SendKeys "{ENTER}"
ws.sendkeys "This is the most wonderful day of my life"
WS.SendKeys "^s"
WScript.Sleep 100
WS.SendKeys "test"
WScript.Sleep 100
WS.SendKeys "{ENTER}"
WS.SendKeys "%{f4}"

[ Last edited by terse on 2007-6-25 at 12:37 AM ]
Floor4 bd123456789 Posted 2007-06-25 22:32
中级用户 Posts 216 Credits 360
Originally posted by terse at 2007-6-25 12:29 AM:
Search it.
dim ws
set ws=wscript.createobject("wscript.shell")
str = "This is the most wonderful day of my life$because I'm here with you now"
Num = len(str)
ws.run(& ...


Wonderful!
Floor5 bd123456789 Posted 2007-06-25 22:32
中级用户 Posts 216 Credits 360
Originally posted by terse at 2007-6-25 12:29 AM:
Search it
dim ws
set ws=wscript.createobject("wscript.shell")
str = "This is the most wonderful day of my life$because I'm here with you now"
Num = len(str)
ws.run(& ...


Wonderful!
Floor6 kich Posted 2007-06-26 02:31
中级用户 Posts 168 Credits 397
But according to this method, it seems that Chinese characters cannot be input!!~
Floor7 flyingphf Posted 2007-07-01 23:41
中级用户 Posts 142 Credits 392
Not bad. It would be even better if Chinese characters could be input.
Floor8 enixchen Posted 2007-08-13 12:33
初级用户 Posts 23 Credits 57
Can input Chinese characters.
Saw similar code a few months ago.
Hope some big shot can post it again.
Floor9 zh159 Posted 2007-08-14 10:47
金牌会员 Posts 1,467 Credits 3,687
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023