24-10 ?送鍵???

ڭ̥iHϥ sendKeys() ƨӶǰeLƥAoO@ӫܱjj\Anun䴩ϥμӾާ@Aڭ̴NiHϥ WSH ӹF@Ҥ@˪\C

bUoӽdҡAڭ̶} IE ðCLʧ@G

lɡ]iePrint01.js^G]ǦϰUYi^
// } IE ðCL
// Roger Jang, 20081215, tested under Vista

// Step 1: } IE øJ Google jM
WshShell=new ActiveXObject("WScript.Shell");
WScript.Echo('Will open IE in 5 sec...'); WScript.Sleep(5000);
WshShell.Run("iexplore", 9);

// Step 2: iCLʧ@
WScript.Echo('Will click alt-d in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("%{d}");
WScript.Echo('Will send URL in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("http://www.google.com");
WScript.Echo('Will click alt-f in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("%{f}");
WScript.Echo('Will click p in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("p");
WScript.Echo('Will click enter in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("{ENTER}");
WScript.Echo('Will close the browser in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("%{F4}");

Ъ`NbWzdҤA

HUCX@ǯS䪺Is覡G
Ų Is覡
SHIFT +
CONTROL ^
ALT %
LEFT ARROW {LEFT}
RIGHT ARROW {RIGHT}
UP ARROW {UP}
DOWN ARROW {DOWN}
{{{}
} {}}
[{[}
] {]}
~ {~}
+ {+}
^ {^}
% {%}
Ų Is覡
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
END {END}
ENTER {ENTER} or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
Ų Is覡
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

ڭ̤]iH}ҰOƥügJrG

lɡ]sendKeys01.js^G]ǦϰUYi^
// ϥ SendKeys h}ҰOƥügJrBsɩ junk.txt
// Roger Jang, 20081215, tested under Vista

outputFile="junk.txt";
WshShell=new ActiveXObject("WScript.Shell");
WshShell.Run("notepad", 9);	// Open notepad
WScript.Sleep(1000);		// Give Notepad some time to load
for (i=0; i<100; i++){
	WshShell.SendKeys(i+". Hello World!");
	WshShell.SendKeys("{ENTER}");
}
WshShell.SendKeys("%{F}");
WshShell.SendKeys("s");
WScript.Echo('Will input the file name in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys(outputFile);
//WshShell.SendKeys("{TAB}{TAB}{ENTER}");
WScript.Echo('Will save the file in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("%{s}");
WScript.Echo('Will click yes in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("%{y}");
WScript.Echo('Will close the file in 5 sec...'); WScript.Sleep(5000);
WshShell.SendKeys("%{F4}");

WzdҬO@ӫܦ쪺dҡAṲ̄@wn˦۸լݬݡA~|ϥWSHuǰeLƥviHF쪺jj\I

Hint
bWzdҤAڭ̥iHN^gJOƥAOYnNeJAN̪ӻAثe|X{ýXC@²檺ѨMסANONeŶKïAAKOƥYiC

Yn} IE ó]ww]AiUCdҡG

lɡ]sendKeys02.js^G]ǦϰUYi^
// ]w IE w]
// Roger Jang, 20081215, tested under Vista

WshShell=new ActiveXObject("WScript.Shell");
WshShell.Run("iexplore", 9);
WScript.Sleep(5000);		// ݺJ
WshShell.SendKeys("%t");
WshShell.SendKeys("o");
WScript.Sleep(500);
WshShell.SendKeys("http://www.google.com");
WScript.Sleep(500);
for (i=0; i<13; i++)	// Make sure it's 13...
	WshShell.SendKeys("{TAB}");
WshShell.SendKeys("{ENTER}");
WScript.Sleep(500);

bUzdҤAڭ̧QΰOƥŪJ@ӤrɡANrɪsX覡令 UTF-8AåtssɡApUG

lɡ]toUtf8.js^G]ǦϰUYi^
// ΪkGcscript toUtf8.js file1 file2 file3 ...
// \GN command line ҵrɧQ notepad ন utf-8 榡
// G
// 	pGJɦWO test.txtAXɦWhO text.txt_utf8
// 	`NGpGJɦWO۹|AhbϥΫeAݽT{ notepad w]xsؿOTؿ
// 	]Yϥε|AhSWzU{C^

// 	Roger Jang, 20041125

args=WScript.Arguments;
if (args.Count()==0) {
	WScript.Echo("Usage: " + WScript.ScriptName + " file1 file2 file3 ...");
	WScript.Quit();
}

fso = new ActiveXObject("Scripting.FileSystemObject");

WshShell=new ActiveXObject("WScript.Shell");
WScript.Echo("Current directory: "+WshShell.CurrentDirectory);

// CXҦJѼ
WScript.Echo("No. of arguments = " + WScript.Arguments.Count());
for (i=0; i<args.length; i++){
	WScript.Echo("args("+i+")="+args(i));
	targetFile=args(i)+"_utf8";
	WScript.Echo("targetFile="+targetFile);
	// Delete the targetFile if it exists
	if (fso.FileExists(targetFile)){
		WScript.Echo("Deleting "+targetFile);
		f = fso.GetFile(targetFile);
		f.Delete();
		WScript.Sleep(500);
	}

	WshShell.Run("notepad "+args(i), 9);
	WScript.Sleep(500);	// Give Notepad some time to load
	WshShell.SendKeys("%{F}");
	WshShell.SendKeys("a");
	WshShell.SendKeys(targetFile);
	WScript.Sleep(5000);
	WshShell.SendKeys("{TAB}{TAB}{TAB}");
	WshShell.SendKeys("{DOWN}{DOWN}{DOWN}{DOWN}");
	WshShell.SendKeys("{TAB}");
	WshShell.SendKeys("{ENTER}");
	WshShell.SendKeys("%{F4}");
	WScript.Sleep(1000);

	//ɦWGtest.txt_utf8.txt ===> test.txt_utf8
//	fso.MoveFile(targetFile+".txt", targetFile);
	WScript.Sleep(1000);
}

YnդUCdҡAŪ̥iHJ

cscript toUtf8.js test.txt WSH |ϥΰOƥŪJ test.txtANsXאּ UTF-8Aåts test.txt_utf8CYn˵oɮתPAiκsܳoɮסAåѤUԿu˵/sXvANiHݥXoɮצbsXWPC

Hint
Q UTF-8 sX覡ANiHPܦUꤣPrP@ӤrɮסC

LPǰeLƥ󪺬AiLnxG http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_hilv.mspx?mfr=true


JScript {]pPΡGΩ WSH