首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

WScript.Shell模拟键盘输入中文的有关问题

2012-02-27 
WScript.Shell模拟键盘输入中文的问题htmlheadtitle/titlescriptfunctionclearTest(len){for(i

WScript.Shell模拟键盘输入中文的问题
<html>
<head>        
<title> </title>
<script>
function   clearTest(len)
{
for(i=1;i <=len;i++){
var   obj   =   eval( "document.form1.fileName "+i);
obj.select();
document.execCommand( "delete ")
}
}
function   onTest(len){
clearTest(len)
var   WshShell   =   new   ActiveXObject( "Wscript.Shell ");
form1.fileName1.focus()
for(i=1;i <=len;i++){
var   srcValue=i+ "测试.jpg ";
window.clipboardData.clearData( "text ");
window.clipboardData.setData( "text ",srcValue);
WshShell.sendkeys( "^(v) ");
WshShell.SendKeys( "{TAB} ")
WshShell.SendKeys( "{TAB} ")
}

}
</script>
</head>
<body>
<table>
    <form   name= "form1 "   method= "post "   action= " "   enctype= "multipart/form-data ">
    <tr>
        <td>
<input   name= "fileName1 "   type= "file "/>
<input   name= "fileName2 "   type= "file "/>
<input   name= "fileName3 "   type= "file "/>
<input   name= "fileName4 "   type= "file "/>
<input   type= "button "   onClick= "onTest(4); "   value= "ok ">
</td>
</tr>
</form>
</table>
</body>
</html>

为什么onTest(1)的时候可以正常的输出中文,当大于1的时候,只是输出最后的一个,例如,当onTest(2)时,fileName1,fileName2中应该分别输出的是:1测试.jpg,2测试.jpg,可是实际2个输出的内容是一致的,都是2测试.jpg

[解决办法]
<html>
<head>
<title> </title>
<script>
function clearTest(len)
{
for(i=1;i <=len;i++){
var obj = eval( "document.form1.fileName "+i);
obj.select();
document.execCommand( "delete ")
}
}
function onTest(len){
clearTest(len)
form1.fileName1.focus()
for(i=1;i <=len;i++){

var srcValue=i+ "测试.jpg ";
var WshShell = new ActiveXObject( "Wscript.Shell ");
//try{

//obj.focus();
WshShell.SendKeys(srcValue);
WshShell.SendKeys( "{TAB} ")
WshShell.SendKeys( "{TAB} ")
/*}catch(e){
alert(e);
} */
WshShell.Quit;
}

}
</script>
</head>
<body>
<table>
<form name= "form1 " method= "post " action= " " enctype= "multipart/form-data ">
<tr>
<td>
<input name= "fileName1 " type= "file "/>
<input name= "fileName2 " type= "file "/>
<input name= "fileName3 " type= "file "/>
<input name= "fileName4 " type= "file "/>
<input name= "fileName5 " type= "file "/>
<input type= "button " onClick= "onTest(5); " value= "ok ">
</td>
</tr>
</form>
</table>
</body>
</html>

昨天也有个人问这个问题,这是斑竹给的答案,你看看吧
[解决办法]
这个东西感觉写WEB程序不是好东西,写CMD程序到是挺好用的,因为里面WScript对象不能用。


如果用的话只有这样了
<html>
<head>
<title> </title>
<script>
function clearTest(len)
{
for(i=1;i <=len;i++){
var obj = eval( "document.form1.fileName "+i);
obj.select();
document.execCommand( "delete ")
}
}
function onTest(len){
clearTest(len)

form1.fileName1.focus()
show(1,len)


}
function show(i,len){
var srcValue=i+ "测试.jpg ";
window.clipboardData.clearData( "text ");
window.clipboardData.setData( "text ",srcValue);
var WshShell = new ActiveXObject( "Wscript.Shell ");
WshShell.sendkeys( "^(v) ");
WshShell.SendKeys( "{TAB} ")
WshShell.SendKeys( "{TAB} ")
WshShell.Quit;
if(i> len){
return
}
i++
setTimeout( "show( ' "+i+ " ', ' "+len+ " ') ",100)
}
</script>
</head>
<body>
<table>
<form name= "form1 " method= "post " action= " " enctype= "multipart/form-data ">
<tr>
<td>
<input name= "fileName1 " type= "file "/>
<input name= "fileName2 " type= "file "/>
<input name= "fileName3 " type= "file "/>
<input name= "fileName4 " type= "file "/>
<input type= "button " onClick= "onTest(4); " value= "ok ">
</td>
</tr>
</form>
</table>
</body>
</html>

热点排行
Bad Request.