Linux: more keys!

21 views
Skip to first unread message

S.E. Mitchell

unread,
Sep 5, 2025, 6:53:02 AM9/5/25
to TSEPro Support
I found out something new and exciting (for me at least).
But first, compile the C program below with:

cc -o keypress keypress.c

---------------keypress.c---------------------------------------
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>

struct termios orig_termios;

void disable_raw_mode() {
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
fputs("\033>", stdout); // restore alt keypad mode
fputs("\033[>4;0m", stdout); // restore CIS u style key reporting
fflush(stdout);
}

void enable_raw_mode() {
tcgetattr(STDIN_FILENO, &orig_termios);
struct termios raw = orig_termios;
cfmakeraw(&raw); /* set raw mode */
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
atexit(disable_raw_mode);
}

int main() {
enable_raw_mode();
fputs("\033=", stdout); // alternate keypad mode
fputs("\033[>4;2m", stdout); // request CSI u style key reporting
fflush(stdout);
char c;
while (read(STDIN_FILENO, &c, 1) == 1 && c != 'q') {
if (iscntrl(c)) {
printf("%d\r\n", c);
} else {
printf("%d ('%c')\r\n", c, c);
}
}
return 0;
}
---------------keypress.c---------------------------------------

Run this in an xterm.

./keypress

type <ctrl i>, and <tab>. Both should return 9. You can type 'q' to quit.

Now, if you are running WSL, in the terminal, type: xterm
This will load a real xterm - the one supplied by Windows
terminal is not apparently just an emulated xterm.

In the real xterm, again run ./keypress, and type <ctrl i> and
<tab>. For me at least, <tab> is still 9, but <ctrl i> is now:

27 [105;5u

This is great! I can now also distinguish grey-+ from +, and
many other things.

TSE doesn't know about these "new" keys, but it will soon!

Also:
If you don't have WSL, but are running a real xterm, and you
don't see the new keys, try the following:

printf '\e[>4;0m'

And then run ./keypress

If that doesn't work, one last thing to try:

Edit your ~/.Xresources file.

Add this line:

XTerm*modifyOtherKeys: 2

Once you have saved the file, type:
xrdb -merge ~/.Xresources

Restart your xterm, or load another one.
If you run ./keypress, you should notice different strings for
<tab> 9 - and <ctrl-i>.

Let me know how it goes/what you think!

And I would be curious what you get for <ctrl i> if it is
different from 9.

Thanks!

p.s.: Now I can distinguish between grey /*-, ctrl-i and tab, and
many others! I am so excited! :)
Reply all
Reply to author
Forward
0 new messages