Close

Simultaneous Keystrokes

A project log for F.P.S: Foot Presto Switch

Pedal Switch for playing FPS games

danjovicdanjovic 03/22/2016 at 05:320 Comments

Spent some time trying to figure out how to allow simultaneous keypresses using DigiKeyboard Library.

Both the problem and the solution were right in front of me but took some time until I figure out that the report size of only one keystroke was hardcoded in Digikeyboard.h file.

First step was to find the Digikeyboard.h file:

In Windows it is located in the following folder

c:\Users\username\AppData\Roaming\Arduino15\packages\digistump\hardware\avr\1.6.5\libraries\DigisparkKeyboard\

In Linux the file is on a hidden folder

/home/username/.arduino15/packages/digistump/hardware/avr/1.6.7/libraries/DigisparkKeyboard/

const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */
  0x05, 0x01,  // USAGE_PAGE (Generic Desktop) 
  0x09, 0x06,  // USAGE (Keyboard) 
  0xa1, 0x01,  // COLLECTION (Application) 
  0x05, 0x07,  //   USAGE_PAGE (Keyboard) 
  0x19, 0xe0,  //   USAGE_MINIMUM (Keyboard LeftControl) 
  0x29, 0xe7,  //   USAGE_MAXIMUM (Keyboard Right GUI) 
  0x15, 0x00,  //   LOGICAL_MINIMUM (0) 
  0x25, 0x01,  //   LOGICAL_MAXIMUM (1) 
  0x75, 0x01,  //   REPORT_SIZE (1) 
  0x95, 0x08,  //   REPORT_COUNT (8) 
  0x81, 0x02,  //   INPUT (Data,Var,Abs) 
  0x95, 0x06,  //   REPORT_COUNT (6 simultaneous keystrokes) 
  0x75, 0x08,  //   REPORT_SIZE (8) 
  0x25, 0x65,  //   LOGICAL_MAXIMUM (101) 
  0x19, 0x00,  // (Reserved (no event indicated)) 
  0x29, 0xE7,  //   USAGE_MAXIMUM (Right GUI) 
  0x81, 0x00,  //   INPUT (Data,Ary,Abs) 
  0xc0         // END_COLLECTION 
};

The 2nd parameter in the 12th line was changed to 0x06, to allow up to 6 simultaneous key presses.

0x95, 0x06,  //   REPORT_COUNT (6 simultaneous keystrokes) 

The Buffer size was also updated to allow up to 6 keys (plus a modifier)

  //private: TODO: Make friend?
 // maximum 6 keystrokes, defined in HID report
  uchar    reportBuffer[7];    // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
  using Print::write;

Discussions