編集はVSCodeでやってるんですが、クロスビルドとリモートデバック実行のためだけに、Eclipse(の派生IDE)で実行を行わないといけなかったので、VSCodeからウィンドウを切り替えないで実行できないか調べました。
Linux環境では xdotool
というものを使えばコマンドラインから別のアプリケーションにキー入力を送れたので実現できました。
tasks.json 設定例
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "sh",
"args": [
"-c"
],
"isShellCommand": true,
"showOutput": "always",
"tasks": [
{
// need 'apt-get install xdotool'
"taskName": "Test",
"isTestCommand": true,
"suppressTaskName": true,
"args": [
"xdotool search --name 'Eclipse' windowfocus --sync %1 key 'ctrl+F11' && xdotool search --name 'Visual Studio Code' windowactivate --sync %1"
]
}
]
}
解説
実行には xdotool
が必要です。おそらくX11環境下では使えるんじゃないかと思います。(確認はUbuntuのUnity環境下のみ)
sudo apt-get install xdotool
上記のタスクでは以下の2つのコマンドを実行しています。
$ xdotool search --name 'Eclipse' windowfocus --sync %1 key 'ctrl+F11'
$ xdotool search --name 'Visual Studio Code' windowactivate --sync %1
--name
のところは、指定した文字列がウィンドウタイトルに含まれていれば良いです。
1つ目のコマンド実行後にフォーカスが移ってしまっているので、2つ目のコマンドでもとに戻しています。
(VSCodeを2つ立ち上げてると誤動作するかもです(未確認))
参考
Ubuntu Manpage: xdotool - command-line X11 automation tool
音声と xdotool でキーボードとマウスのアクションをトリガーする
xdotoolでシェルからブラウザをリロードするワンライナー - Qiita
x11 - How to send keystrokes (F5) from terminal to a process? - Unix & Linux Stack Exchange
Eclipseショートカットキー Mac & Windows 対応表 - CODESCRIBBLE