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 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.

4
  • You've given half the question: we do not know what you tried and what the result was. If you were connected as a (pseudo)terminal, the ctrl+V part would tell you something, as would "stty -a". Nov 8, 2015 at 11:56
  • How are you connecting to the server? Are you connecting to port 23? That means you're using telnet. If you don't know whether you're using SSH or telnet then I think you may have bitten off more than you can chew! What you are essentially doing by connecting like this is writing a terminal emulator. You need to support everything that a terminal emulator needs to support. For example, from a Windows machine you might use PuTTY to connect to a remote Unix machine. PuTTY is a terminal emulator, so you would need to do everything that PuTTY does. So you need to implement the TELNET protocol.
    – Sam
    Nov 9, 2015 at 23:12
  • @ThomasDickey, edited question. Nov 10, 2015 at 8:08
  • @Sam, the code is here github.com/lxc/lxd/blob/… - it uses websockets. Nov 10, 2015 at 8:08

2 Answers 2

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
4
  • What is this Control+V mechanism? Is it something supported by all Linuxes? Nov 9, 2015 at 7:25
  • yes - it is a feature of all Unix-like systems. Nov 9, 2015 at 9:13
  • I don't see anything when I press F1, Arrows etc. after Ctrl-V, so that 100% means that my client doesn't send it, right? Nov 10, 2015 at 8:15
  • That sounds right - the keyboard implementation may be incomplete. Nov 10, 2015 at 9:03
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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .