Using PuTTY to talk with my PIC chip over a Serial connection. I want to recognize <CR> <Backspace> <Cursor Up> <Cursor Dwn> <Cursor left> <Cursor Right> and do the correct thing in the LCD display.
I figured this should be easy enough. Just go look at an Ascii table and use the Hex values being sent. Problem is I guess PuTTY sends more than one value for each of the cntrl char values.
Is there a list I can refer to for these values that I can modify my code with or is the answer starring me in the face?
I don't know the specifics of PuTTY's protocols, but ASCII does define escape characters - Control+key. To be more specific, ASCII 0 is Control-#, 1 through 26 (0x1 through 0x1a) are Control+the corresponding letter of the alphabet.
Related
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?
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.
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.
I can not find information about what should be done to spaces within ESC sequence. Example: position cursor
ESC[10;20H
is a valid ESC sequence, but is the one including spaces like
ESC[ 10; 20H
valid too? The point is that while ESC character is a control character with code 0x1b, text following it is human and machine readable text, and in general spaces should not harm the meaning of ESC sequence, thus I would just remove all the spaces found within ESC sequence.
Lots of article on the internet talking what ESC sequence is and what they may consist of (however there're only just few good and really informative ones), but none of them clarify this matter.
I found this one, and it says
Since ASCII control functions do not follow a structured syntax, the notation used to describe function sequences and parameters is important to avoid confusion. Escape sequences are shown with a space between each character to make them easier to read. These spaces are not part of the Escape sequence.
While it says that space char separates characters for readability, they do not say if keeping space invalidates the ESC sequence.
Is there any related RFC for it? I hope it unambiguously defines this case.
Update: thanks Thomas to pointing to space char being one of the ESC sequence operators. So now it is clear that [ should follow ESC character, and space is not allowed between them.
But what is about following arguments? As in the example above, spaces in row and column coordinates ESC[SP10;SP20H makes sequence invalid and I must stop processing it starting displaying space character instead?
Update1: I did small test using Windows telnet application. Logged into the remote server, and that server responds with ESC sequence. The result is:
ESC[2;5H positions properly row 2 column 5
ESC[ 2; 5H displays "2; 5H" in current cursor position
ESC[2 ; 5H displays "; 5H" in current cursor position
So basing on the empirical findings I suspect spaces are NOT allowed, and space char invalidates/cancels the sequence.
ECMA-48's the place to look (if you want an RFC). Look for mention of 02/00 (the way it represents the hexadecimal 0x20 for space).
For what it's worth, there are DEC control sequences (VT220 and up) with an embedded space, e.g., the ones marked with SP:
Controls beginning with ESC
This excludes controls where ESC is part of a 7-bit equivalent to 8-bit
C1 controls, ordered by the final character(s).
ESC SP F 7-bit controls (S7C1T), VT220.
ESC SP G 8-bit controls (S8C1T), VT220.
ESC SP L Set ANSI conformance level 1 (dpANS X3.134.1).
ESC SP M Set ANSI conformance level 2 (dpANS X3.134.1).
ESC SP N Set ANSI conformance level 3 (dpANS X3.134.1).
In your examples, the whitespace is just for readability, and non-printing characters such as ASCII escape (decimal 27, hexadecimal 01xb) are shown by a name such as ESC.
I am writing some behavioural tests for code that interacts with a terminal and I need to assert behaviour on the sequence C-p C-q (ctrl-p ctrl-q). In order to do this, I need to write the raw characters to the PTY. I have a small mapping at the moment for things like C-d => 0x04, C-h => 0x08.
Is there somewhere I can get a basic mapping of human readable control sequences, mapped to raw byte sequences for xterm?
Take the ASCII value of the character (e.g., for ^H, take 72), and subtract 64. Thus, ^H is 8.
This works for any control character. Using it, you can discover that, for example, ^# is the NUL character and ^[ is ESC.
I'm working with binary data and want to find out that is wrong.
I use notepad++ to preview binary, I have set View->Show Symbol->Show All Characters to see all chars, but there still exists some chars I cannot identify, e.g. â©ÎÅ. The problem is that ASCII has strong standart for number 0 to 127, extended ASCII may be picturing in many ways, so I have problem with chars what represents numbers 128 to 255.
Is there any table of notepad++ extended chars or some option to make it show symbol code instead of symbol.
Maybe not solution for you, but in PSPad and SynWrite editors you can:
create text-converter (INI file) which changes ASCII 127..255 to strings like <127>...<255> or others
apply this converter to text.
Text converter usage is described in help of both apps.
I have some UTF-Text starting with "ef bb bf". How can I turn this message to human read-able text? vim, gedit, etc. interpret the file as plain text and show all the ef-text even when I force them to read the file with several utf-encodings. I tried the "recode" tool, it doesn't work. Even php's utf8_decode failed to produce the expected text output.
Please help, how can I convert this file so that I can read it?
ef bb bf is the UTF-8 BOM. Strip of the first three bytes and try to utf8_decode the remainder.
$text = "\xef\xbb\xbf....";
echo utf8_decode(substr($text, 3));
Is it UFT8, UTF16, UTF32? It matters a lot! I assume you want to convert the text into old-fashioned ASCII (all characters are 1 byte long).
UTF8 should already be (at least mostly) readable as it uses 1 byte for standard ASCII characters and only uses multiple bytes for special/multilingual characters (Character codes > 127). It sounds like your file isn't UTF8, or you'd already be able to read it! Online content is generally UTF-8.
Unicode character codes are the same as the old ASCII codes up to 127.
UTF16 and UTF32 always use 2 and 4 bytes respectively to encode every character, whether those characters can be represented in a single byte or not. That makes it unreadable if the text editor is expecting UTF8.
Gedit supports UTF16 and UTF32 but you need to 'add' those encoding explicitly in the open dialog box (and possibly select them explicitly instead of using auto-detect)