In Emacs, I want to bind a particular key combination to a command. However, because I am using Emacs in terminal mode within iTerm2 on OS X, I need to translate the key combo to character escape sequence and register that sequence with iTerm2 so that it will recognize the key combination.
But how do I find out the corresponding sequence given a key combination? For example, I found that something like ^[[1;8A corresponds to Ctrl+Alt+up (where I have configured Alt to function as +Esc in iTerm2), but I have no idea how that key combination translates into this particular sequence.
Is there a way to look up or work out the escape sequence for any given key combo? For example, what is the sequence for Ctrl+Alt+r?
A related question, can someone explain to me the relationship between setting up a key combo with its corresponding sequence in iTerm2 and making Emacs translate a sequence into its internal key representation using input-decode-map inside .emacs (e.g. (define-key input-decode-map "[escape_sequencehere]" [internal_key_representation_here])? It seems to me that setting it up in iTerm2 alone is sufficient to make the binding work in Emacs, so when and why do we need to set up the latter in .emacs? (and perhaps when do we need both to make something work?)