キーボードショートカット

提供: ArchWiki
2022年5月13日 (金) 10:21時点におけるKgx (トーク | 投稿記録)による版 (→‎有効化: 翻訳)
ナビゲーションに移動 検索に移動

この記事では (あまり有名でない) デフォルトのキーボードショートカットのリストとユーザーカスタマイズの情報を提供します。

標準のショートカット

カーネル (SysRq)

sysrq キーを介してカーネルに実装されるローレベルなショートカットがいくつかあります。これらのショートカットは、システムが反応しなくなったときに復旧させたりデバッグするのに用いることができます。いつでも使うことができますが、特に、電源ボタンを長押しして無理やりシステムの電源を切るよりかはショートカットを使うほうが推奨されます。

詳細については、Wikipedia:Magic SysRq key を参照してください。

有効化

systemd は sysrq パーミッションのビットマスクがをデフォルトで 0X10に設定しており、特にプロセスのシグナリングや再起動などを許可していません。システムで sysrq キーを完全に使用できるようにするには sysctl の設定に、kernel.sysrq = 1 を追加してください。1 より大きい値は、sysrq 機能を選択的に有効にするために使用できます。詳細は、Linuxカーネルのドキュメントを参照してください。パーティションがマウントされる前やinitrd内でも有効にしたい場合は、sysrq_always_enabled=1カーネルパラメータに追加してください。

これらの方法で設定を変更すると、再起動しても変更が持続されることに注意してください。現在のセッションの sysrq 設定を変更してみたい場合は、 sysctl kernel.sysrq=1 または echo "1" > /proc/sys/kernel/sysrq を実行できます。

sysrq キーを完全に有効にすることには、いくつかの明らかなセキュリティ上の リスクがあります。強制的なリブートなどに加え、CPU レジスタの内容をダンプするために使用することができ、理論的には機密情報を明らかにすることができます。これを使うにはシステムに物理的にアクセスする必要があるので (あなたが 気にしない限り)、ほとんどのデスクトップユーザはおそらくそのリスクレベルを許容範囲と考えるでしょう。とはいえ、sysrq を有効にする前に、それを有効にすることの意味と、あなたのシステムが動作しているより大きな状況の力学を完全に理解していることを確認してください。

再起動

覚え方は "Reboot Even If System Utterly Broken" です ("REISUB" とも呼ばれます)。もしくは "BUSIER" の反対として覚えましょう。

ノート: Please be aware that "REISUB" itself is just a mnemonic, not any kind of general recommendation for the key press sequence to take back control of an unresponsive system. You should not blindly press these sequences each time without knowing their actual function as noted below.
キーボードショートカット 説明 Code to Enable Other Functions Enabled
Alt+SysRq+r Unraw キーボードの制御を X から取り戻す。 4 Alt+SysRq+k SAK
Alt+SysRq+e Terminate 全てのプロセスに SIGTERM を送り、丁寧にプロセスを終了させる。 64 Alt+SysRq+f OOM kill
Alt+SysRq+j Thaw
Alt+SysRq+i Kill 全てのプロセスに SIGKILL を送り、即座にプロセスを強制終了させる。
Alt+SysRq+s Sync データをディスクに書き込む。 16 -
Alt+SysRq+u Unmount 全てのファイルシステムをアンマウントして読み取り専用で再マウント。 32 -
Alt+SysRq+b Reboot 再起動 128 -

For example, to selectively enable just the reboot function, set kernel.sysrq to 128. The whole set of REISUB functions can be enabled by setting it to 244, although this also enables the additional functions listed in the last column of the table. For further documentation, see the sysrq key documentation, and the kernel source file /drivers/tty/sysrq.c.

Killing a memory-hogging process

Alt+SysRq+f can be used to invoke the OOM (out-of-memory) killer without causing a kernel panic if nothing can be killed. The OOM killer uses a set of heuristics to pick whichever relatively non-vital process is using the most memory and kill it. This is very useful to kill a process that is softlocking your system by causing excessive thrashing, such as a runaway browser script, and can alleviate the need for a reboot in many cases. Note that the OOM killer can target a wide variety of processes despite its well-meaning heuristics and can be somewhat unpredictable, so be careful about calling it casually.

Troubleshooting

  • If you are using a ディスプレイマネージャ and after Alt+SysRq+e you are presented with the login screen (or full desktop if autologin is enabled), it is most likely caused by Restart=always directive in the relevant サービスファイル. If necessary, ユニットファイルの編集, however this should not prevent the "REISUB" sequence from working.
  • If all the above combinations work except Alt+SysRq+b, try using the contralateral Alt key.
  • On laptops that use Fn key to differentiate SysRq from PrtScrn, it may not actually be necessary to use the Fn key (i.e., Alt+PrtSc+letter could work).
  • On Lenovo laptops SysRq is often configured as Fn+S. To use it press and hold Alt then press Fn+s, release Fn and s still holding Alt followed by the keys above.
  • You may need to press Ctrl along with Alt. So for example, full key shortcut would be Ctrl+Alt+SysRq+b.

Linux console

See Linux コンソール#キーボードショートカット.

X11 & Wayland

キーボードショートカット 説明 ノート
Ctrl+Alt+F1, F2, F3, ... n 番目の仮想端末にスイッチ 機能しない場合 Ctrl+Fn+Alt+F… を試してみてください。
Shift+Insert
Mouse Button 2
PRIMARY バッファからテキストを貼り付ける デフォルトでは QtShift+Insert で PRIMARY バッファではなく CLIPBOARD を使います [1]。そして PRIMARY バッファは Ctrl+Shift+Insert を使用します。

カスタマイズ

Readline

Readline is a commonly used library for line-editing; it is used for example by Bash, FTP, and many more (see the details of readline package under "Required By" for more examples). It has Emacs-like and vi-like editing modes which can be customized with escape sequences. Default key bindings are listed in readline(3) and the Info documentation.

Zsh

ZshZLE を使用して、ショートカットをウィジット、スクリプトおよびコマンドにリンクします。

Xorg

See Xorg でのキーボード設定#よく使われる XKB オプション for some common shortcuts, that are disabled by default.

When we are in a graphical environment we may want to execute a command when certain key combination is pressed (i.e. bind a command to a keysym). There are multiple ways to do that:

  • The most portable way using low level tools, such as acpid. Not all keys are supported, but configuration in uniform way is possible for keyboard keys, power adapter connection and even headphone jack (un)plugging events. It is also difficult to run programs inside X session correctly.
  • The universal way using Xorg utilities (e.g. xbindkeys) and eventually your desktop environment or window manager tools.
  • The quicker way using a third-party program to do everything in GUI, such as the Gnome Control Center.

sxhkd

A simple X hotkey daemon with a powerful and compact configuration syntax. See sxhkd for details.

actkbd

From actkbd home page:

actkbdAUR (available in AUR) is a simple daemon that binds actions to keyboard events. It recognises key combinations and can handle press, repeat and release events. Currently it only supports the linux-2.6 evdev interface. It uses a plain-text configuration file which contains all the bindings.

A sample configuration and guide is available here.

xbindkeys

xbindkeys allows advanced mapping of keysyms to actions independently of the Desktop Environment.

ヒント: If you find xbindkeys difficult to use, try the graphical manager xbindkeys_config-gtk2AUR from the AUR.

Desktop environments

Window managers

X-selection-paste のキーバインディング

マウスよりもキーボードを好んで使用する場合、マウスの中ボタンでペーストを行うキーバインドが役に立つかもしれません。特にキーボードを集中的に使う環境では有用です。ワークフローは以下のようになります:

  1. Firefox で、検索したい文字列を (マウスで) 選択してください。
  2. Ctrl+k を押して "Google search" フィールドにカーソルを移動。
  3. マウスポインタを移動して中ボタンを押す代わりに F12 でバッファを貼り付け。
ノート: Shift+Insert で同じような機能が実行できます。#X11 を見てください: Shift+Insert は x-selection-paste バッファではなくクリップボードバッファを挿入します。アプリケーションによっては、両方のバッファには同じ中身が入ります。

ここでは公式リポジトリにある3つのパッケージを使います:

  • xsel で x-selection-buffer の中身にアクセス。
  • Xbindkeys でキーストロークに操作をバインド。
  • xvkbdAUR でキーボードの入力をエミュレートしてバッファ文字列をアプリケーションに渡す。

以下の例では x-selection-paste の操作を F12 キーにバインドします:

.xbindkeysrc
"xvkbd -no-jump-pointer -xsendevent -text "\D1`xsel`" 2>/dev/null"
    F12

"\D1" コードはセレクションバッファの挿入の前に 100 ms のポーズを追加します (xvkbd のホームページ を参照)。

ノート: X の設定によっては、xvkbd の -xsendevent 引数を外す必要があります。

F12 以外のキーのキーコードは xbindkeys -k で確認できます。

参照:

XMonad ウィンドウマネージャ

xmonad ウィンドウマネージャには x-selection-buffer の中身を貼り付ける機能が内蔵されています。特定のキーストローク (例: Insert キー) にバインドするには以下の設定を使用:

xmonad.hs
import XMonad.Util.Paste
...
  -- X-selection-paste buffer
  , ((0,                     xK_Insert), pasteSelection) ]

ヒントとテクニック

参照