China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-26 02:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to make a VBS script automatically input a line of text in Notepad View 1,714 Replies 8
Original Poster Posted 2007-06-24 23:43 ·  中国 福建 厦门 电信
初级用户
Credits 94
Posts 40
Joined 2007-04-28 22:13
19-year member
UID 86806
Gender Male
Status Offline
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
Floor 2 Posted 2007-06-25 00:26 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Is it to simulate the effect of "typing input"?
Floor 3 Posted 2007-06-25 00:29 ·  中国 江苏 常州 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
flandy +1 2007-06-26 08:36
Floor 4 Posted 2007-06-25 22:32 ·  中国 浙江 嘉兴 海宁市 电信
中级用户
★★
Credits 360
Posts 216
Joined 2007-05-29 17:41
19-year member
UID 89677
Gender Male
Status Offline
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!
Floor 5 Posted 2007-06-25 22:32 ·  中国 浙江 嘉兴 海宁市 电信
中级用户
★★
Credits 360
Posts 216
Joined 2007-05-29 17:41
19-year member
UID 89677
Gender Male
Status Offline
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!
Floor 6 Posted 2007-06-26 02:31 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
But according to this method, it seems that Chinese characters cannot be input!!~
Floor 7 Posted 2007-07-01 23:41 ·  中国 上海 闵行区 电信
中级用户
★★
Credits 392
Posts 142
Joined 2007-06-10 09:48
19-year member
UID 90856
Gender Male
Status Offline
Not bad. It would be even better if Chinese characters could be input.
Floor 8 Posted 2007-08-13 12:33 ·  中国 福建 莆田 电信
初级用户
Credits 57
Posts 23
Joined 2007-04-23 05:19
19-year member
UID 86157
Gender Male
Status Offline
Can input Chinese characters.
Saw similar code a few months ago.
Hope some big shot can post it again.
Floor 9 Posted 2007-08-14 10:47 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Forum Jump: