Sending “ARROW KEY” key through serial port

一个人想着一个人 提交于 2019-12-14 03:53: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.




回答2:


Since ARROW keys are scan codes (not defined in ASCII table), it is necessary to send a sequence of bytes to represent arrow keys (See https://en.wikipedia.org/wiki/ANSI_escape_code for details). Unfortunately, this sequence may vary between different platforms and targets, so you need to experiment for what is correct for your target. Tested on a Ubuntu 16.04 target from a serial console on Windows, the ARROW UP sequence is three bytes (0x1b, 0x5b, 0x41), or on keyboard: ‘Esc’ ‘[‘ ‘A’



来源:https://stackoverflow.com/questions/13684675/sending-arrow-key-key-through-serial-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!