Hey Andrew, how's the fame going? :)
At times it is difficult to include certain characters. For instance a space is a character which can cause problems on the command line. 'ls /Applications/Address Book.app' would attempt to list files in the folder /Applications/Address and also in the folder Book.app because the space is typically the field separator for different parts of a command line, not just a character considered to be included in a specific part, I don't think I said that well at all but enh, moving on. To address that issue, the space can be quoted, for instance this 'ls "/Applications/Address Book.app"' would work since the double-quotes are used to indicate the beginning and end of the filepath part of the command line. However, space isn't the only problematic character. Others include tab, return and how about if the filename itself contains a double-quote? See the problem?
To overcome that, 'escaping' is used. In this example, the space in the filepath is escaped by the backslash character. /Applications/Address\ Book.app. This allows a space to be included without actually being treated as a space. Instead, its treated as a 'normal' character and not a possible field separator.
Another problem is that some characters may not necessarily be visible, or easily entered from a keyboard. A way to include such a character without causing other problems is to use the numerical value which represents the character, instead of the character itself.
"A" is generally how your computer would display the character whose value is 65. In AppleScript try "display dialog (ASCII character 65)". 65 is the value in decimal or base 10. Base 10 is 'native' for humans but not computers. Computers, having only 2 fingers, prefer to count in base 2 and multiples thereof. Base 2 is not exactly 'user-friendly' to the human attempting to issue commands to the computer. A "happy medium" of base 16 is commonly used instead. In base 16, the value 65 (being six 10s and five 1s) is expressed as 41 (four 16s and one 1). So the hexadecimal or hex value of A is 41.
But if you merely type 'echo 41' on the command line, it will return "41" not A. Escaping can be used to tell the computer that the 41 is actually the hex value of the character we want it to display instead. In Terminal, type...
CODE
echo -e "\x41"
And now we get the output we wanted, "A". Type 'help echo' for a somewhat incomplete explanation of the -e switch as applies to the bash built-in command "echo".
In the AppleScript examples you posted, we see a method of getting around yet another problem which is that the escape character backslash is also used in AppleScript, for instance like this 'display dialog "\x41"' which displays "x41". So when trying to pass the backslash from an AppleScript command to a shell command it fails because AppleScript assumes that by \x we mean the escaped character "x" so it would pass "x41" to bash instead of "\x41". To pass the backslash from an AppleScript command to a shell command, the escape character must be escaped with the escape character.
As you can see, forethought is not always a primary ingredient in designing computer languages. :)
Here's one of the commands you posted, and the output returned when the command is run in Script Editor.
CODE
set key2 to do shell script "echo -e \"\\x5b\\x61\\x2d\\x68\\x69\\x2d\\x6d\\x6e\\x2d\\x7a\\x5d\\x30\\x31\\x32\\x33\\x34\\x35\\x36\\x37\\x38\\x39\\x20\\x2d\""
"[a-hi-mn-z]0123456789 -"