Arduino Leonardo Keyboard for PS4 Hack

Hello,

I have successfully programmed an Arduino Uno to act as a keyboard. When coupled with a Titan 2, I can then use it for PS4 adaptive controls.

The function I used to send the 'keystrokes' for the Arduino Uno was Serial.write(buf, 8 ), where buf was a unit8_t consisting of the ASCII codes for the given buttons pressed ( 0 or null if not pressed).

Now that I would like to do the same task with the Leonardo (cost savings and ease of board configuration) I have tried using Keyboard.write, Keyboard.press and Keyboard.release, which do not accept unit8_t inputs. I have tried multiple different arrangements of the three functions. I have ended up with individual lines of code, for example:

Keyboard.press(buf[2]);
Keyboard.press(buf[3]);
Keyboard.press(buf[4]);
Keyboard.press(buf[5]);
Keyboard.press(buf[6]);
Keyboard.press(buf[7]);
Keyboard.releaseAll();

Keyboard.write with a delay acts exactly as a keyboard, however cause serious glitching on the Titan 2 (gaming controls very unresponsive).

Keyboard.Press and Keyboard.releaseall (as above), type multiple characters for one press, but drastically reduced the glitchiness on the Titan 2. Which is good but not perfect.

I have a hunch that reducing the amount of data being sent to the Titan 2, by finding the correct format to use Keyboard.write in one line of code, would do the trick.

Any thoughts?

RBernier:
I have tried using Keyboard.write, Keyboard.press and Keyboard.release, which do not accept unit8_t inputs.

Do you mean uint8_t? If so, what makes you think that? The function signatures say you're wrong:

  size_t write(uint8_t k);
  size_t write(const uint8_t *buffer, size_t size);
  size_t press(uint8_t k);
  size_t release(uint8_t k);

Try adding some delays between key presses. The Uno can type way, way faster than any human and this often causes problems.

Thanks for your reply. I have already successfully programmed my UNO. I am now trying to accomplish the same thing on a Leonardo, using this library:

Sorry, I meant to write Leonardo, not Uno.

When using the Uno, what i in the 8 byte buffer? For example, to send lowercase 'a' does the buffer contain in hex "00 00 04 00 00 00 00 00"? If yes, this is a standard USB keyboard HID report using USB key codes, not ASCII.

It is possible to send USB keyboard HID reports on Leonardo and Micro. This helps when the ASCII to USB key code translation does not do what you want.

   buf[0] = 0;     // modifier bits, shift, ctrl, alt, win
   buf[1] = 0;     // always 0
   buf[2] = 4;     // A key code
   buf[3] = 0;     // 
   buf[4] = 0;     // 
   buf[5] = 0;     // 
   buf[6] = 0;     // 
   buf[7] = 0;     // 
   HID().SendReport(2, buf, 8);

Hi mate,

How did you end up going with your Arduino Leonardo Keyboard for PS4 ? I was trying to do this project a few weeks already and unfortunately, no luck. Would you mind to share your UNO programming and wiring as well ?

Cheers,
Mid

RBernier:
Hello,

I have successfully programmed an Arduino Uno to act as a keyboard. When coupled with a Titan 2, I can then use it for PS4 adaptive controls.

The function I used to send the 'keystrokes' for the Arduino Uno was Serial.write(buf, 8 ), where buf was a unit8_t consisting of the ASCII codes for the given buttons pressed ( 0 or null if not pressed).

Now that I would like to do the same task with the Leonardo (cost savings and ease of board configuration) I have tried using Keyboard.write, Keyboard.press and Keyboard.release, which do not accept unit8_t inputs. I have tried multiple different arrangements of the three functions. I have ended up with individual lines of code, for example:

Keyboard.press(buf[2]);
Keyboard.press(buf[3]);
Keyboard.press(buf[4]);
Keyboard.press(buf[5]);
Keyboard.press(buf[6]);
Keyboard.press(buf[7]);
Keyboard.releaseAll();

Keyboard.write with a delay acts exactly as a keyboard, however cause serious glitching on the Titan 2 (gaming controls very unresponsive).

Keyboard.Press and Keyboard.releaseall (as above), type multiple characters for one press, but drastically reduced the glitchiness on the Titan 2. Which is good but not perfect.

I have a hunch that reducing the amount of data being sent to the Titan 2, by finding the correct format to use Keyboard.write in one line of code, would do the trick.

Any thoughts?