I am having a hard time finding documentation on how to properly use USB HID buffers, so the issue may lie there instead of with my code.

To get 0x47, I used this table: https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf

Here's code that is loosely based off of http://mitchtech.net/arduino-usb-hid-keyboard/

    /* Arduino USB Keyboard HID demo
 * Cut/Copy/Paste Keys

#define SCRLCK  0x47
//#define KEY_LEFT_SHIFT  0x02
//#define KEY_RIGHT_CTRL  0x10
//#define KEY_RIGHT_SHIFT 0x20

uint8_t buf[8] = { 
  0 };  /* Keyboard report buffer */

#define PIN_PTT 2
//#define PIN_CUT 6
//#define PIN_PASTE 7

int state = 1;
int prevState;

void setup() 

  pinMode(PIN_PTT, INPUT);
  //pinMode(PIN_CUT, INPUT);
  //pinMode(PIN_PASTE, INPUT);
  // Enable internal pull-ups
  digitalWrite(PIN_PTT, 1); 
  //digitalWrite(PIN_CUT, 1);
  //digitalWrite(PIN_PASTE, 1); 


void loop() 
  state = digitalRead(PIN_PTT);
  if (prevState != state) {
    buf[0] = SCRLCK;   // Scroll Lock
    // buf[2] = 27;    // Letter X
    // buf[2] = 123;    // Cut key: Less portable
    Serial.write(buf, 8); // Send keypress
    prevState = state;

void releaseKey() 
  buf[0] = 0;
  Serial.write(buf, 8); // Release key  

Using a keyboard testing application, the green keys (minus mouse) are the buttons that appear to be pressed when the Arduino is using the USB HID firmware:

Upon using Passmark Keyboardtest, it looks like it's pressing Shift, Ctrl, Left alt, and right alt when I press the button.

My assumption is that I am writing to the 'modifier key' buffer instead of the 'other key' buffer. How would I define the correct key?

  • about the defines at top of your sketch ..... convert 0x02, 0x10, 0x20 and 0x47 to binary ...... what do you see when you do that? – jsotola Apr 29 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.