2

I'd like to get the string representation of a keymap event. For instance 19 should be printed as C-s, 1 as C-a etc...

I could make my own function to do that but since describe-keyis capable of printing the string representation of an event there must be a built-in function to do that somewhere. I looked into the manual and browsed some code and was not able to found it.

syl20bnr
  • 2,095
  • 11
  • 21

1 Answers1

4

If a single key/character, just use function single-key-description.

(single-key-description 19) ; => "C-s"

If a list of characters, convert them to a string and use function key-description.

(key-description (string 19 25 20 5 43)) ; => "C-s C-y C-c C-e +"

If a key sequence as a string, use function key-description. (Here I write "^Y" etc when I mean the string with a single control char, ^Y.)

(key-description "^S^Y^T^e+") ; => "C-s C-y C-c C-e +"
Drew
  • 75,699
  • 9
  • 109
  • 225