IEではCtrl-Nの入力に反応する処理をonkeydown
イベントで実装できたんだけど、EdgeのIEモードではそれが使えなくなっているらしいので実験した。
準備
- ReplitでこんなHTMLとJavaScriptを用意しておく。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>replit</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <ul id="parent"></ul> <script src="script.js"></script> </body> </html>
function consoleKeycode(event) { var ul = document.getElementById("parent"); var li = document.createElement("li"); li.textContent = event.key + ", Ctrl = " + event.ctrlKey; ul.appendChild(li); event.stopPropagation(); event.stopImmediatePropagation(); event.preventDefault(); event.keyCode = 0; return false; } document.onkeydown = consoleKeycode;
- PowerShellから以下を実行してInternet Explorerのプロセスを単独で起動する。
(New-Object -ComObject InternetExplorer.Application).Visible = $true
上記Replitのページ(Replitの右ペインでWebviewのアドレスバーに表示されているURL。
https://【repl名】.【ユーザ名】.repl.co
)をIEとEdgeでそれぞれ開く。Edgeは「Internet Explorerモードで再読み込みする」を実行しIEモードにしておく。以下の処理を「
SendKeys.vbs
」として保存する。
Set WshShell = CreateObject("WScript.Shell") WScript.Sleep(2000) WshShell.SendKeys ("^n")
SendKeys.vbs
をダブルクリックで実行したあと、2秒以内にブラウザウィンドウにフォーカスを当てる。
結果
いずれの場合も、まずCtrlキーが入力され、次にCtrl-Nが入力された動きになる。
- IEでは以下のように表示され、新しいウィンドウは開かない。
•Control, Ctrl = true •n, Ctrl = true
- EdgeのIEモードでは以下のように表示され、新しいウィンドウが開く。
•Control, Ctrl = true
•Control, Ctrl = true
*1:Edgeの設定で「Internet Explorerページ」にReplitのURLを指定したうえで、PowerShellから「& 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' --app="https://【repl名】.【ユーザ名】.repl.co"」で起動する。