4

Stop reading if uname -r returns a Linux version greater than 5.9, since scrollback has been simply removed (1, 2).


My keyboard does not have separate PgUp and PgDown keys. They are in the numpad, sharing their position with KP_9 and KP_3.

Keypad picture

Scrolling terminals with Shift+Pg{Up,Down} was not possible either with Numlock on or off.

Since I don't care for the keypad numbers but do care a lot for scrolling, I have successfully remapped them in X11 to "Prior" and "Next" regardless of Numlock state, and now Shift+{PgUp,Down} both work in Xterm.

However, I can't achieve the same in the TTY. With other keyboards that had exclusive Page keys, I could use Shift+PgUp to scroll back after cating a large file, for example.

Original keycodes

As of showkeys:

KP_3/KP_PgUp   = 73
KP_9/KP_PgDown = 81
Slash          = 89
Right Shift    = 54

As of dumpkeys:

PgUp   = 104
PgDown = 109

Slash and Right Shift were also listed because I will also swap them just for testing.

Attempts

  • Modified /etc/console-setup/remap.inc to exactly this:

    keycode 73 = Prior
      shift keycode 73 = Scroll_Backward
      shift shiftl  keycode 73 = Scroll_Backward
      shift shiftr  keycode 73 = Scroll_Backward
      shift shiftl  shiftr  keycode 73 = Scroll_Backward
      shift ctrll keycode 73 = Scroll_Backward
      shift shiftl  ctrll keycode 73 = Scroll_Backward
      shift shiftr  ctrll keycode 73 = Scroll_Backward
      shift shiftl  shiftr  ctrll keycode 73 = Scroll_Backward 
    keycode 81 = Next
      shift keycode 81 = Scroll_Forward
      shift shiftl  keycode 81 = Scroll_Forward
      shift shiftr  keycode 81 = Scroll_Forward
      shift shiftl  shiftr  keycode 81 = Scroll_Forward
      shift ctrll keycode 81 = Scroll_Forward
      shift shiftl  ctrll keycode 81 = Scroll_Forward
      shift shiftr  ctrll keycode 81 = Scroll_Forward
      shift shiftl  shiftr  ctrll keycode 81 = Scroll_Forward  
    keycode  89 = Shift
    keycode  54 = slash
      shift keycode  54 = question
      altgr keycode  54 = degree
      shift altgr keycode  54 = questiondown
    
  • Followed the instructions of How to change console keymap in Linux?.

    dumpkeys > pageupdown
    

    Then swapped

    keycode 73  keycode 104
    keycode 81  keycode 109
    keycode 54  keycode 89
    

    in that file and issued loadkeys -s pageupdown.

Results

In both experiments,

  • Although the two keypad keys don't print numbers anymore and PgUp still works (it scrolls in less) as desired, Shift+PgUp does not scroll the TTY.

  • Right Shift and Slash have been correctly swapped.

Additional notes

  • Toggling Numlock does not help in any of the configurations. The Fn key also does not have any effect in those keys.

  • I have also tried mapping more ordinary keys, namely l and p, to the Page actions, without success.

  • If it helps in any way, this is the XKB map that works in the X session:

    partial keypad_keys
    xkb_symbols "noKPNumbers" {
        key  <KP9> {  [  Prior,   Prior   ]   };
        key  <KP3> {  [  Next,    Next    ]   };
    };
    

How can I map the keypad PgUp and PgDown keys in such a way that Shift+Pg{Up,Down} scroll the TTY buffer? Is it possible at all?

5
  • You should be able to achieve this by editing /etc/default/keyboard on Debian-based systems. However, I couldn't get it to work outside of X either... Oct 21 '20 at 17:52
  • @hedgie Thank you for your feedback. I had already tried something along that route, but the results were not any better. Differently from it, I believe the two presented methods are much more direct and that it is less probable to miss something in them than in the default/keyboard approach.
    – Quasímodo
    Oct 21 '20 at 22:33
  • I had added and removed an answer for doing it in X, as I realized you have done this already for X. Could this post help you into what you are trying?
    – thanasisp
    Oct 25 '20 at 1:55
  • @thanasisp Thanks for your help and the link, I had already gone through that post too. But see how, at the end, loadkeys is responsible for loading the keymap, confirming that my approach is technically correct.
    – Quasímodo
    Oct 25 '20 at 10:51
  • Not a solution, a workaround: Launch tmux or screen after logging in and use their respective scrollback. The advantage being that you don't have to care where and how the shell is launched (tty, serial, xterm, something else), the scrolling works the same every time. You also get copy/paste everywhere which is nice.
    – Patrick
    Oct 30 '20 at 12:43
-2

The reason it doesn't work is that you are trying to add form control to a formless output. There is no Buffer to scroll.

That may not seem to make sense, so let me explain. TTY is a historical artifact from when Console output was to an actual TTY or TeleTYpe device. It was a serial terminal printer, search up a LA120 from DEC for an example. You can actually still do this hooking a line printer into /dev/tty. Some server hardware also will allow you to redirect this output at the BIOS level to a serial device. It comes in darn handy if you know how to use it in the absolute worst case hardware troubleshooting scenarios.

The TTY printer would print every line just as it happened and then the paper piled up on the floor of the Operations room. What is on the screen is just what was printed within the screen buffer. there is no other retained information to scroll though.

The Console TTY is meant as a last ditch effort to retain some sort of log even when everything else shits the bed. Its where the disk full message or the seg fault that halts the system shows up to give the actual operator some clue why the system is using electricity but not being otherwise useful.

4
  • Thank you for all the historic background, but I have always scrolled with Shift+Pg{Up,Down}, see for instance stackoverflow.com/q/15255070. Are we talking about the same thing, the TTYs 1 to 7 that one gets with CTRL-ALT-F{1..7}, which have a framebuffer? Also, if there were no buffer to scroll, why would the keymap contain (by default!) actions such as Scroll_Backward?
    – Quasímodo
    Oct 27 '20 at 11:50
  • I am not talking about the launchable /dev/tty# that you can use, those Sub-shells similar to running screen are buffered. I am talking about the console output that appears on the screen at the login prompt. Console output is TTY based. The keymap is for when you are operating within a shell or shell application like login. The console output is not within a shell or any buffered environment thus you cannot scroll it. I find the Function Key launched shells less useful than screen because you can't copy and paste data between them. screen is something I install on every system I admin. Oct 27 '20 at 12:15
  • I am talking about the console output when I have already logged in and already have the login shell. I want to scroll back when I cat a large file, for example. That one is scrollable. I'm sorry if I didn't convey it precisely enough in the question, I guess, but thank you for your answer anyway, it is very informative.
    – Quasímodo
    Oct 27 '20 at 12:16
  • @someone Why the downvote? Care to explain so we all could know your point of view ?
    – ImHere
    Nov 2 '20 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.