Enabling shifted page keys in hterm

Suraj N. Kurapati

hterm binds Shift+PageUp/Down keys for scrolling its own backbuffer by default. To override those defaults and allow the underlying terminal session to receive those keys, while also adding support for Alt and Control modifier keys, simply:

  1. open the nassh extension’s options page
  2. open Chrome Developer Tools (Ctrl+Shift+I)
  3. paste the following snippet in the console:
term_.prefs_.set("keybindings", {
  "Shift-PGUP":          "'\u001b[5;2~'",
  "Shift-PGDN":          "'\u001b[6;2~'",
  "Alt-Shift-PGUP":      "'\u001b[5;4~'",
  "Alt-Shift-PGDN":      "'\u001b[6;4~'",
  "Ctrl-Shift-PGUP":     "'\u001b[5;6~'",
  "Ctrl-Shift-PGDN":     "'\u001b[6;6~'",
  "Ctrl-Alt-Shift-PGUP": "'\u001b[5;8~'",
  "Ctrl-Alt-Shift-PGDN": "'\u001b[6;8~'"
});

For example, I commonly use Shift+PageUp as a convenient shortcut to enter tmux’s copy mode and then immediately scroll up by one page (tmux copy-mode -u):

bind-key -n S-PPage copy-mode -u

But how could I possibly have known those esoteric keycodes in the first place? :-) It was only possible with the help of arcane knowledge in this MinTTY wiki, which explained the notation of special editing keys and how they are modified:

modifier keys Shift, Alt and Ctrl are … encoded as a one-digit number that becomes part of the keycode. To obtain that number, add the numbers for each pressed modifier to 1: Shift=1, Alt=2, Ctrl=4.

Key plain modified
PgUp ^[[5~ ^[[5;m~
PgDn ^[[6~ ^[[6;m~

Using that formula, I calculated the one-digit numbers for my modifier combos:

With these results, I was able to override the hterm keybindings setting above.