Using USB Keyboard on games

27 May 2013

Hello! Has anybody tried using mbed to emulate USB keyboard and tried it on games? Does it really work like how normal keyboard does? Share please!

31 May 2013

It should work like a normal keyboard does. However, the response time might be a bit slow compared to a normal keyboard. I haven't tried it though. It shouldn't be hard try out with the USB device libraries.

25 Sep 2015

It doesn't work with games D:

16 Jan 2019

and thats the reason why:

port of USBKeyboard.cpp

bool USBKeyboard::keyCode(uint8_t key, uint8_t modifier) {
    // Send a simulated keyboard keypress. Returns true if successful.
    HID_REPORT report;

    report.data[0] = REPORT_ID_KEYBOARD;
    report.data[1] = modifier;
    report.data[2] = 0;
    report.data[3] = keymap[key].usage;
    report.data[4] = 0;
    report.data[5] = 0;
    report.data[6] = 0;
    report.data[7] = 0;
    report.data[8] = 0;

    report.length = 9;

    if (!send(&report)) {
        return false;
    }

    report.data[1] = 0;
    report.data[3] = 0;

    if (!send(&report)) {
        return false;
    }

    return true;

}

The library is simulating a full Key press including the release of the key. If you want your controller to act like a "normal" keyboard you have to send usb reports yourself with the timing your use case requires. So it is possible to do what you want with Mbed.

Posted just for the case someone ever comes here again.