Keyboard functions for electron not working

STARTUP(Keyboard.begin());
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(MANUAL);

void setup() {

  Keyboard.press(KEY_LEFT_WINDOWS);
  Keyboard.press(KEY_LALT);
  Keyboard.press(KEY_DELETE);
  Keyboard.releaseAll();

  //Keyboard.click(KEY_DELETE, MOD_LCTRL | MOD_LALT);
    pinMode(D7, OUTPUT);
    digitalWrite(D7, LOW);
 
}

void loop() {

Keyboard.println("Hello world!");
digitalWrite(D7, HIGH);
delay(500);
digitalWrite(D7, LOW);
delay(500);

}

Tested on Windows 8 and 10 with DeviceOS 1.0.0 and 0.7.0.
Also tested with and without SYSTEM THREAD.

What specifically “isn’t working”? What was the intent? As far as I know WINKEY+ALT+DELETE doesn’t do anything on a Windows PC. And if it did anything, you could try adding a delay before the key presses… you might be sending the keys before windows attaches the USB device.

In C++ there is no guaranteed order for class constructors. Placing Keyboard.begin() in STARTUP() is not prudent. Instead, put it as the first statement in setup().

The docs do suggest using STARTUP() and USB HID should be a “native” object without dependencies to high level objects - if it were I’d expect to see an SOS panic.

However, I can confirm that USB HID Keyboard and Mouse are broken for both Electron and Photon on Windows machines that also have the Particle drivers installed, but on a “virgin” machine it seems to work.
The device is not even recognised as USB HID device when plugged in.

2 Likes