赵翔鹏的Blog -- Zhao Xiangpeng's Think-pad


载入中

我的分类
载入中
日志更新
载入中
最新评论
载入中
站内搜索
留言板
载入中
链接
管理我的BLOG
载入中
Blog信息
载入中

[rss] (推荐!)
(不推荐)

几个用Sendkeys做的脚本(zz)
翔 发表于 2004-12-3 10:17:00
下面是几个SendKeys的例子。关于Wscript和SendKeys,我还写过两篇相关的blog:
SendKeys参考文档在windows下编辑代码,用linux远程编译.

-----
我們可以使用 sendKeys() 函數來傳送鍵盤事件,在下面這個範例,我們開啟 IE 並執行列印的動作:

原始檔(printIE.js):(灰色區域按兩下即可拷貝)
// 由 IE 列印網頁
objMyIE = WScript.CreateObject("InternetExplorer.Application");
 
URL="http://neural.cs.nthu.edu.tw/jang";
//URL="http://www.google.com";
//URL="file://d:/users/jang/books/wsh/example/test.htm";
objMyIE.Navigate(URL);
objMyIE.visible = true;
 
while (objMyIE.Busy)
 WScript.Sleep(1000);

WshShell=new ActiveXObject("WScript.Shell");
WshShell.SendKeys("%{f}");
WScript.Sleep(1000);
WshShell.SendKeys("p");
WScript.Sleep(1000);
WshShell.SendKeys("%{p}");
 
//objMyIE.document.parentWindow.Print(); // 有 bug! 
//objMyIE.Quit();

我們也可以開啟記事本並寫入文字:

原始檔(sendKeys01.js):(灰色區域按兩下即可拷貝)
// 使用 SendKeys 去開啟記事本並寫入文字、存檔

WshShell=new ActiveXObject("WScript.Shell");

WshShell.Run("notepad", 9);
WScript.Sleep(500); // Give Notepad some time to load
for (i=0; i<10; i++){
 WshShell.SendKeys(i+". Hello World!");
 WshShell.SendKeys("{ENTER}");
}
WshShell.SendKeys("%{F}");
WshShell.SendKeys("s");
WshShell.SendKeys("test.txt");
WshShell.SendKeys("{TAB}{TAB}{ENTER}");
WshShell.SendKeys("y");
WshShell.SendKeys("%{F4}");

若要開啟 IE 並設定我的最愛,可見下列範例:

原始檔(sendKeys02.js):(灰色區域按兩下即可拷貝)
// 設定我的最愛(還有一些小問題!)
WshShell=new ActiveXObject("WScript.Shell");

WshShell.Run("iexplore", 9);
WScript.Sleep(1000); // Give Notepad some time to load
WshShell.SendKeys("%t");
WshShell.SendKeys("o");
WScript.Quit(1);
//WshShell.SendKeys("http://neural.cs.nthu.edu.tw/jang");
WshShell.SendKeys("http://www.cs.nthu.edu.tw");
WScript.Quit(1);

for (i=0; i<13; i++)
 WshShell.SendKeys("{TAB}");
WScript.Quit(1);
WshShell.SendKeys("{ENTER}");

阅读全文 | 回复(2) | 引用通告 | 编辑
 

回复:几个用Sendkeys做的脚本(zz)
def(游客)发表评论于2005-1-10 21:27:00
def(游客) 好东东哈~~我喜欢~~~呵呵~~

个人主页 | 引用 | 返回 | 删除 | 回复
 

回复:几个用Sendkeys做的脚本(zz)
fz-L(游客)发表评论于2004-12-17 15:37:00
fz-L(游客)你好,我做了一个vbs的批处理 但执行后要我输入y/n来确认 ,有没有办法 让程序来自动完成呢 谢谢 fzl168@21cn.com

个人主页 | 引用 | 返回 | 删除 | 回复
 

发表评论:
载入中
Powered by Oblog.