Skip to main content

TIL: Using Vim Hex Editor To View Keyboard Key Hex Code

The best way to predict the future is to create it.
— Anonymous.

Hi guys, in this TIL (Today I Learned), we will review a way on how to view keyboard key hex code. As I modify my iTerm2 (a popular terminal emulator for macOS) key shortcuts to map my tmux Ctrl + b keys, I wonder how to get the keyboard key hex codes easily.

Then I remembered that there is the xxd (a command line hex viewer and editor which is part of the vim package) command which can process keys and convert them to hex code.

To start off, we run xxd from the terminal. It will wait for a read line. Execute your keystrokes (e.g. Ctrl - b) then press enter to create a new line. After the new line add EOF (End Of File) which would corresponds to the keyboard keys Ctrl + d. After doing the process above xxd would output a hex representation of the keyboard key code that you desire.1

Another trick using xxd command is to reverse hex string like this.

echo <hex code> | xxd -revert -plain | rev | tr -d '\n' | xxd -plain

An example hex code would be 030201. That would output a reverse 010203. The rev command will reverse the output while the tr would trim newline.


  1. https://stackoverflow.com/questions/36321230/finding-the-hex-code-sequence-for-a-key-combination ↩︎

Comments

Popular posts from this blog

TIL: Disable mDNS and SSDP Discovery in Google Chrome

We're born alone, we live alone, we die alone. Only through our love and friendship can we create the illusion for the moment that we're not alone. — Orson Welles.

TIL: Flutter Series - Custom Icons

Everyone thinks of changing the world, but no one thinks of changing himself. — Leo Tolstoy.

Editor Series: Configuring Emacs To Fit The Needs Part 2

The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking. — Albert Einstein. As the title says, to fit the needs. Currently, I’m looking into handling multiple projects but vast differ in programming paradigm ang language. Some of the language that I’ll probably tackling are Go, Rust, Ruby, Perl, C++, Javascript, Typescript, and etc.

TIL: Creating Bootable ISO from macOS Installer

If the freedom of speech is taken away then dumb and silent we may be led, like sheep to the slaughter. — George Washington.