Capturing Terminal Keycodes and Using .inputrc ============================================== Author: Momchil Ivanov Date : 2021.08.02 Introduction ------------ This article describes methods of caputring the keycodes send by a terminal. The terminal sends a sequence of characters. Capturing Keycodes Using sed ---------------------------- To capture the sequence of characters sent by the terminal execute: $ sed -n l In case you press the Alt key and the left arrow key, the output might be one of the following: ^[[1;3D or ^[^[[D The ESC sign is 0x1b and is shown as ^[. Capturing Keycodes Using showkey -------------------------------- To capture the sequence of characters send by the terminal execute: $ showkey -a In case you press the Alt key and the left arrow key, the output might be one of the following: ^[[1;3D 27 0033 0x1b 91 0133 0x5b 49 0061 0x31 59 0073 0x3b 51 0063 0x33 68 0104 0x44 or ^[^[[D 27 0033 0x1b 27 0033 0x1b 91 0133 0x5b 68 0104 0x44 This the ESC character followed by the characters [1;3D. To capture each key press and key release, check the other options of showkey software. Managing Bindings in .inputrc ----------------------------- You can bind certain keycodes to functions in the ~/.inputrc file. To bind the combination of ALT + Arrow key to move wordwise, you can add the following to your .initrc file: "\e\e[C": forward-word "\e\e[C": backward-word where the keycodes correspond to the ones your terminal sends. The ESC character is denoted as \e here.