Using Vim Hex Editor To View Keyboard Key Hex Code

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

— Anonymous.

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. Ctrlb) 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 ↩︎

Posted

in

by

  • Let’s Explore!

    It’s 04:03am Tuesday, and I’m starting this blog. There are a lot of things currently bothering my mind, and sometimes I’m thinking of what the future will look like. Waiting till 10:00 to get onto my work and start doing some stuff. Let’s find some beautiful place and get lost. – Me I’ve been a… Read More

  • Installing MySQL2 Ruby Gem in macOS Mojave

    Installing MySQL2 gem became a common problem for people who uses macOS to develop Ruby1 based apps that utilized MySQL2 data store. I’ve personally encountered this problem myself back in the days and still encountering this on brand new setup macOS workstation. In this article, we will go through the steps I did to resolved… Read More

  • Changing Xserver Default Applications Using XDG Tools

    XDG (freedesktop.org) which stands for X Desktop Group is a group which develop the X11 and xdg utilities which currently runs as barebones of linux desktop. So how do we change the defaults when opening a file on XServer? Be free, and live life fully. — Caroline Shaw. So how do we configure XDG? Tools… Read More