2

I have a custom client that connects to remote Ubuntu via websocket and runs bash there. But keys like Del, Arrows etc. don't work. How can I output what is being received on the server side? None of the solutions mentioned in Show keys pressed in Linux work.

UPDATE: I first asked a question about SSH, but later realized that I am probably not using SSH.

UPDATE2: What have I tried:

# showkey
Couldn't get a file descriptor referring to the console

evtest

No device specified, trying to scan all of /dev/input/event* USAGE: Capture mode: evtest [--grab] /dev/input/eventX --grab grab the device for exclusive access

Query mode: (check exit code) evtest --query /dev/input/eventX <type> <value>

<type> is one of: EV_KEY, EV_SW, EV_LED, EV_SND <value> can either be a numerical value, or the textual name of the key/switch/LED/sound being queried (e.g. SW_DOCK).

ls /dev/input

ls: cannot access /dev/input: No such file or directory

stty -a

speed 38400 baud; rows 300; columns 80; line = 0; intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 hupcl -cstopb cread -clocal -crtscts -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc ixany imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

Basically, I need something like this:

termbox keyboard demo

UPDATE3: The communication between console client and server is done through websockets in Go. Sources: client and server.

2 Answers2

2

The result showing stty -a was promising, but neither the question nor the other answer pointed to the usual way to find what is sent by a special key such as Del, Left-cursor, etc.

It is unclear which "Del" OP is referring to. I have both Delete and Del keys on my keyboard (on the editing- and numeric-keypads). Both could send a series of data bytes beginning with ESC (the ASCII escape character). That is, in a regular terminal.

However, the question referred to websocket, which sounds as if this is running in a web browser. The screenshot shows some type of onscreen keyboard, with DEL in the editing keypad.

If the implementation is complete, one would expect something like this to be sent to the shell when pressing that key, if you first press controlV:

^[[3~

The ^[ is the echoed ASCII escape character (control[). You need the controlV lnext character to prevent the shell from interpreting it or throwing it away.

The lnext (literal next) setting is a feature of any termios which you are likely to encounter, but oddly not mentioned in the POSIX standard except as reserved for an extension (see the mention of VLNEXT). However, since this is tagged for linux, the Linux documentation is what you can use for a reference:

  • termios(3)

    The termios functions describe a general terminal interface that is provided to control asynchronous communications ports.

  • stty(1)

    Print or change terminal characteristics.

You can see it in the output of stty -a, i.e., in the fourth output line in this example:

$ stty -a
speed 38400 baud; rows 40; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
1

I think you need to take a step back and think about what you're trying to do. You weren't clear on how you are connecting to the server over WebSockets. I'm assuming you are connecting to a WebSocket server which is proxying the connection to the telnet port, is that right (because WebSockets can only connect to WebSockets)? You may want to take a look at the Websockify project which has an example VT100-compatible telnet client. You could base your project off that.

Sam
  • 111