Sending “ARROW KEY” key through serial port

2019-07-21 09:36发布

问题:

In the same way that the question Sending “ENTER” key through serial port how can i send the "ARROW key" through the serial port? Most particuly the UP arrow key.

回答1:

Cursor keys are a relatively new feature of keyboards. They didn't yet exist at the time the ASCII codes were chosen. Which was largely based on the capabilities of teletypes that were used at that time. Like the widely used ASR-33, its keyboard layout looked like this:

No cursor keys. Note how line-feed was a separate key back then, '\n' in ASCII. Easier to get to and affecting the choice for the line-end control character in Unix. The Return key was the equivalent of the Enter key on a modern keyboard, '\r' in ASCII.

So there are no standard codes to pick for the cursor keys. You'll have to encode them yourself. ANSI escape codes were a common standard. Emulation of the DEC VT-52 and VT-100 were very common as well.