やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

xdotool 任意ウインドウに任意ショートカットキーを入力するスクリプト

 WindowsでいうAutoHotKeyみたいなやつ。ウインドウ操作の自動化。

手順

  1. インストール
  2. 使ってみる

1. インストール

sudo apt install -y xdotool

1-1. バージョン確認

$ xdotool --version
xdotool version 3.20160805.1

1-2. help

$ xdotool --help
Available commands:
  getactivewindow
  getwindowfocus
  getwindowname
  getwindowpid
  getwindowgeometry
  getdisplaygeometry
  search
  selectwindow
  help
  version
  behave
  behave_screen_edge
  click
  getmouselocation
  key
  keydown
  keyup
  mousedown
  mousemove
  mousemove_relative
  mouseup
  set_window
  type
  windowactivate
  windowfocus
  windowkill
  windowclose
  windowmap
  windowminimize
  windowmove
  windowraise
  windowreparent
  windowsize
  windowunmap
  set_num_desktops
  get_num_desktops
  set_desktop
  get_desktop
  set_desktop_for_window
  get_desktop_for_window
  get_desktop_viewport
  set_desktop_viewport
  exec
  sleep

1-2-1. key help

$ xdotool key --help
Usage: key [options] <keysequence> [keysequence ...]
--clearmodifiers     - clear active keyboard modifiers during keystrokes
--delay DELAY        - Use DELAY milliseconds between keystrokes
--repeat TIMES       - How many times to repeat the key sequence
--repeat-delay DELAY - DELAY milliseconds between repetitions
--window WINDOW      - send keystrokes to a specific window
Each keysequence can be any number of modifiers and keys, separated by plus (+)
  For example: alt+r

Any letter or key symbol such as Shift_L, Return, Dollar, a, space are valid,
including those not currently available on your keyboard.

If no window is given, and there are windows in the stack, %1 is used. Otherwise
the currently-focused window is used
This command consumes all arguments after it, so you cannot chain
 additional commands after it.

 たとえばCtrl+Vでペーストするショートカットキーのキーイベントを送信したいときは以下。

xdotool key ctrl+v

2. 使ってみる

xdotool key ctrl+shift+v

 Raspbian標準ターミナルのlxterminalCtrl+Shift+Vでペーストされる。上記コマンドをターミナルで実行するとクリップボードのテキストが貼り付けられるはず。

対象環境

  • Raspbierry pi 3 Model B+
  • Raspbian stretch 9.0 2018-11-13
  • bash 4.4.12
    • zenity 3.28.1
    • whiptail 0.52.19
$ uname -a
Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux