Skip to content

Instantly share code, notes, and snippets.

@MlsDmitry
Last active January 3, 2024 01:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save MlsDmitry/a645a49e1d94f912d0cc6df164bc4308 to your computer and use it in GitHub Desktop.
Save MlsDmitry/a645a49e1d94f912d0cc6df164bc4308 to your computer and use it in GitHub Desktop.
MacOs Guide: determine hex code sequence for key combinations
  1. Ctrl + F keys and a lot of other key combinations are hooked by MacOs. You're mostly don't use them, so just turn everything off in System Preferences -> Keyboard -> Shortcuts. If you have another software that handles your key combinations, like Keyboard Maestro, you should turn these actions/macros off, otherwise you won't get right hex sequence.

  2. Enter command below in default MacOs Terminal. (Warning!: shortcuts can also be hooked by terminal emulators, like iTerm. To avoid it use default MacOs terminal. If you are on alacritty, you can enter alacritty --print-events and use poped up terminal).

xxd -psg

then type your key combination and hit enter. (Warning!: if you don't see any output for your combination, then read step 1 again)

Example output:

1: > xxd -psg
2: ^[[24~^[[1;2Q
3: 1b5b32347e1b5b313b32510a

Line 2 is sequence of F12, Shift and F2. Line 3 is output that you would use as hex sequence.

  1. Once you've got hex sequence, remove last two characters -- 0a. It's hex code for a new line (\n), you surely don't need this in your shortcut.
  2. place \x every 2 characters. For the output below it would look like this:

\x1b\x5b\x32\x34\x7e\x1b\x5b\x31\x3b\x32\x51

  1. Nice! Now you can just copy line you've got and use it in your terminal emulator (iTerm, Alacritty or any other)

If you like this guide, please star it or leave a comment if everything works fine. If you have any troubles just leave comment here and we'll try to figure something out.

@sergio0p
Copy link

sergio0p commented Aug 14, 2023

This is very nice! Thanks! But in my Japanese keyboard the ¥ and the \ (option+¥) generate the same hex code 5c. Also, the yen symbol is never printed on the terminal screen, only the backslash. This behavior does not happen with other keys: key and option+key generate different codes. I think that the problem is with terminal when I type ¥ in other apps it shows as the yen symbol but when I type ¥ in the terminal command line or even in the vi editor is shows as the backslash . Weird...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment