Hi all,
I'm working on a user interface for a project that will use an Arduino and a serial terminal to display menus, allow the user to select options and finally run the device.
My problem is that in some cases, keyboard control keys send ANSI control sequences. For example, a user may enter some data into the menu and then attempt to edit it by backspacing over some characters and re-typing.
But if the user uses a LEFT ARROW key to backspace, it sends this sequence:
0x1B, 0x5B, 0x44 (which is the proper sequence for ANSI "cursor left").
Unfortunately, the menu code doesn't (yet) recognize these sequences and ends up displaying garbage such as "~^[D" when that key is pressed.
So, upon searching the web, I found that most of the control codes start with ESCAPE (0x1B) followed by a left bracket (0x5B) and then various character(s) depending on the key's function.
I tried to catch the 0x1B, then set a flag that meant "control codes are probably following" and then looked for the left bracket, etc...
But I just can't get it to work right. Some codes are "1B 5B 5B xx yy 7E", others are "1B 5B xx" and even more combinations.
My code "almost works", but sometimes a stray character from the sequence gets through, or (worse) it "eats" a valid key that's supposed to get through.
Does anyone know of the "standard" and "accepted" way of detecting VT-100/ANSI control codes?
I don't want to DO anything with them (other than the left arrow which will be "backspace"), but I do need to detect them and direct them to the bit bucket so that they don't garbage-up the display.
I've been at this for almost 3 days now and I'm just not seeing it, and I KNOW it can't be that difficult, so if someone could give me a shove in the right direction, I would REALLY appreciate it!
Thanks!
-- Roger