日本語なども通るSendKeys.exeを作る。
WScript.ShellやVBAのSendKeys()では、日本語やPrintScreenキーを送ることができません。
しかし、VBのSendKeys()や.NETのSystem.Windows.Forms.SendKeys.SendWait()では、可能です。
そこで、.NETで日本語なども通るSendKeys.exeを作っておくと、便利です。
SendKeys.JS
import System;
import System.Windows.Forms;
var CommandLine:String=Environment.CommandLine;
if(CommandLine.StartsWith('"')){
CommandLine=CommandLine.Substring(CommandLine.IndexOf('"',1)+2);
}else{
CommandLine=CommandLine.Substring(CommandLine.IndexOf(' ')+1);
}
try{
SendKeys.SendWait(CommandLine);
}catch(e){
Console.Error.WriteLine(CommandLine);
Console.Error.WriteLine(e.ToString());
}
これをコンソール アプリにコンパイルします。
jsc SendKeys.JS
また、ウィンドウ アプリ版も同様に作っておくとよいでしょう。
WSendKeys.JS
import System;
import System.Windows.Forms;
var CommandLine:String=Environment.CommandLine;
if(CommandLine.StartsWith('"')){
CommandLine=CommandLine.Substring(CommandLine.IndexOf('"',1)+2);
}else{
CommandLine=CommandLine.Substring(CommandLine.IndexOf(' ')+1);
}
Console.WriteLine(CommandLine);
try{
SendKeys.SendWait(CommandLine);
}catch(e){
MessageBox.Show(CommandLine + '\n\n' + e.ToString(),Environment.GetCommandLineArgs()[0],MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
ウィンドウ アプリにコンパイルします。
jsc /t:winexe WSendKeys.JS
« 画面全体やアクティブウィンドウのスナップショットを取得する。(その2) | トップページ | バッチ、VBS、コンソールアプリの起動時にコマンドラインを編集する。 »