Emulate keystrokes from a Gnome Shell extension

I want to know if there is a way of emulating a keystroke from a Gnome Shell extension; this is, to emulate a keystroke sent to the currently focused window. I need it because I’m building a clone of a StreamDeck using an Arduino One, which has only an USB serial port (can’t emulate a HID device), and I want some of the presses to emulate key combinations. I know that I can use an user-space /dev/uinput device to emulate them at system level, but it would require the code to run as root, which I don’t want, and since I want to do more things (like change the icons in the keys based on the active application, or launch applications as the current user), I prefer to concentrate everything “low level” in a gnome-shell extension, because anyway I will use it only in a graphical environment, so it would be enough with being able to send keystrokes to focused windows.

EDIT: tried this, but didn’t work… (0x41 is supposed to be the keycode for the A key)

const inputMethod = global.stage.context.get_backend().get_input_method();
inputMethod.forward_key(Gdk.KEY_A, 0x41, 0, 0, true);
inputMethod.forward_key(Gdk.KEY_A, 0x41, 0, 0, false);

EDIT2: also tried this, and also didn’t work:

for (let windowActor of global.get_window_actors()) {
    if (!windowActor.get_meta_window().has_focus()) {
        continue;
    }
    const inputMethod = windowActor.get_context().get_backend().get_input_method();
    inputMethod.forward_key(Gdk.KEY_A, 0x41, 0, 0, true);
    inputMethod.forward_key(Gdk.KEY_A, 0x41, 0, 0, false);
}