SeanMC
SeanMC

Reputation: 2346

Trying to use xTerm to send command or control key combinations

when using xTermJS, I am trying to use a UI to send commands, rather than just typing.. It's the project..

So, I sometimes need to send key combinations. Running on a Mac, I need to send "control+X" aka ^X

However, it doesn't seem like this is possible? At least not that anyone has published. IS it possible? I can use ASCII and hex characters to send, return, shift, arrow keys, etc. Can I do this "control" and/or "control+X" combination?

Upvotes: 2

Views: 2159

Answers (2)

skinnedknuckles
skinnedknuckles

Reputation: 411

Ascii representations of decimal 0 through 31 are all escape codes representing combinations of the Ctrl key plus another character. The ascii characters used are taken from 4 rows below (add 64) on the ascii chart (decimal 64 through 94). For example

decimal 64 is ascii @ => decimal 00 is ascii Ctrl + @
decimal 65 is ascii A => decimal 01 is ascii Ctrl + A
decimal 66 is ascii B => decimal 02 is ascii Ctrl + B

(some ASCII tables represent the Ctrl key with the carat '^' symbol as in ^@ instead of Ctrl + @)

The chart image below shows the binary, octal, decimal, hexadecimal and escape codes/ascii representation for the first 128 values. As an online reference I recommend this ASCII Table (from the excellent reference website SS64.com). Or you can modify this spreadsheet and make your own ascii chart. This version has the original control code names once used by teletype machines. enter image description here

Upvotes: 3

SeanMC
SeanMC

Reputation: 2346

Ok, just as I was posting this querstion, I found the answer. I found it here: https://mw.lojban.org/papri/List_of_ASCII_letterals#ASCII_control_code_chart

under ASCII control code chart, under ^X which has the ASCII code of 18, which I send to xTermJs as \x18. This immediately solved my problem.

Seems like even these character combinations are defined as 1 ASCII character, and not 2 used together. In this case, my Control+X character is actually called a "Cancel" character.

Upvotes: 0

Related Questions