HID Features on GIGA R1

Hello guys,

Since I'm new to this, I need your help. I'm trying to code my new GIGA R1 board to simulate keyboard actions. I've been using the USBHID library included in the core but I feel like it's somewhat limited. I might be mistaken but this library only provides the ability to send key_codes right? Is there a way to simulate holding keys? Something like press/release in the mouse.h library? Or do any of you know how I could achieve this with the available functions?

Thanks in advance

Hi, @KurtE has done some sterling work on improving the Arduino_USBHostMbed5 library for the GIGA. The repo is here GitHub - KurtE/GIGA_USBHostMBed5_devices: Some USB Host device extension to Arduino_USBHostMBed5 library

oops, my mistake. I see you are emulating a kb not connecting one to the giga

Thanks @steve9 - I was going to respond, that most of my USB work was on the host side and not on the USB to the PC side.

However, looking at the Arduino HID Keyboard documentation, I believe you should be able to do what you are asking:
Keyboard | Arduino Documentation

That is you should be able to do something like:

Keyboard.press('a');
...
Keyboard.release('a');

Unfortunately looking at the code, it looks like they are not following their own
interface... Looks like, most of the code is still from what @facchinm did 6 years ago with the github commit: Start PluggableUSB-like porting.

It would probably not be hard to extend it to support the press/release.

You could probably do most of it outside of the library, by implementing your own press/release, that would break up the key_code_raw function to do the sends
of current state. You would either need to hold own to a HID_REPORT or
simply the 9 bytes for the modifier and keys, could be fewer number of bytes
depending on how many keys you want to emulate still being held down.
A couple of problems, most of the code like: send(&report) are public members
of the classes, however the _mutex is private, not sure if any problem not using it

Also their char to keycode translation is contained within the .cpp file, so not easy
to use it externally. However if you know the keycodes you are wanting to send, then...

bool USBKeyboard::key_code_raw(uint8_t key, uint8_t modifier)
{
    _mutex.lock();

    // 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] = key;
    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)) {
        _mutex.unlock();
        return false;
    }

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

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

    _mutex.unlock();
    return true;

}

Thank you very much both of u! And special thanks to KurtE and his awesome work regarding GigaHost stuff. It's been very helpful for some projects I'm currently working on.

I'll take a look at your explanations and see how it goes. Thanks!