我正在努力学习JScript (不是javascript),但是我在寻找资源的时间很长。我想要做的是操纵windows来创建一个操作其他程序的程序,所以我特别需要能够使用Jscript的AppActivate()函数来切换窗口之间的焦点,但是它不能工作。我假设它不起作用,因为对AppActivate的调用是在我试图操纵的全部加载窗口之前发生的。
请找个人:
给我一个在计算器和记事本之间切换的工作例子,也给我一些好的参考资料?
此外,如何在执行结束时暂停程序,以便读取命令提示符中的错误?
这就是我写的,每次都会崩溃。
import System;
import System.Drawing;
import System.Windows.Forms;
import Accessibility;
//Open calculator, wait 3 seconds, open notepad, wait three seconds, change focus to calculator.
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("calc");
WshShell.Sleep(3000);
WshShell.Run("c:/windows/system32/notepad.exe");
WshShell.Sleep(3000);
AppActivate("calc");发布于 2014-06-22 16:36:09
脚本的第一行(导入.)不是JScript。删除它们。WScript.Shell对象没有.Sleep方法。该方法由(全局) WScript对象提供。要使用.AppActivate,需要指定WScript.Shell对象。
工作代码:
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("calc");
WScript.Sleep(3000);
WshShell.Run("c:/windows/system32/notepad.exe");
WScript.Sleep(3000);
WshShell.AppActivate("calc");要查看发生了什么,请从控制台(“DOS框”)启动脚本。
开始阅读这里。
更新wrt注释:
WSH JScript不是.NET JScript。上面脚本到.NET的“端口”如下所示:
import System;
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("calc");
System.Threading.Thread.Sleep(3000);
WshShell.Run("c:/windows/system32/notepad.exe");
System.Threading.Thread.Sleep(3000);
WshShell.AppActivate("calc");
System.Threading.Thread.Sleep(3000);
WshShell.AppActivate("notepad");如您所见,您需要使用平台的睡眠特性(WSH .NET)。
https://stackoverflow.com/questions/24352607
复制相似问题