###### tags: `Arduino` `Keyboard` `PrintScreen`
# 用 Arduino keyboard 程式庫送出 PrintScreen 鍵
同事想模擬鍵盤送出 PrintScreen 鍵, 不過查了 [Arduino Keyboard 的文件](https://www.arduino.cc/en/Reference/KeyboardModifiers), 就是找不到 PrintScreen 鍵倒底要送什麼碼?還好, 網路神人就是神, 在[這一篇問答](https://github.com/arduino-libraries/Keyboard/issues/24#issuecomment-532682683)裡找到了答案, 206。
這是因為 USB 鍵盤應該是要依據 [Universal Serial Bus HID Usage Tables](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 中有關 USB keyboard 的 Usage Id (在文件中的 53 頁, 也可以參考[這裡](https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2)), [Adafruit 的 hid 程式庫](https://circuitpython.readthedocs.io/projects/hid/en/latest/api.html#adafruit-hid-keycode-keycode)就是依據這樣的方式指定按鍵, 不過 Arduino 的 [Keyboard 程式庫](https://github.com/arduino-libraries/Keyboard/blob/master/src/Keyboard.cpp)在實作時為了方便使用者送出文字字串, 所以幫使用者加上了一層轉換, 規則如下:
1. ASCII 可列印的文字都直接送 ASCII 碼給程式庫。
2. Usage Id 原本在 0xE0~0xE7 的輔助鍵, 也就是左右邊的 Ctrl、Shift、GUI、Alt, 被對應到 128~135。
3. 其餘的按鍵就依照原始的 Usage ID + 136 來編碼, 所以像是同事要找的 PrintScreen, 原本 Uage Id 是 0x46, 也就是 70, 加上 136 之後就是 206, 所以使用 Arduino 的 Keyboard 程式庫時若要送 PrintScreen, 就要送 206。