NicoHood / HID

Bring enhanced HID functions to your Arduino!
http://www.nicohood.de
MIT License
2.38k stars 408 forks source link

typeKey(KEY_RETURN); types "(" instead of enter. #419

Open richardcodingstuff opened 1 year ago

richardcodingstuff commented 1 year ago

I'm using the Duckuino converter and noticed that in my "test" script, the enter key does not work. Instead, it prints "(".

include

include

// Utility function void typeKey(int key){ Keyboard.press(key); delay(50); Keyboard.release(key); }

void setup() { // Start Keyboard and Mouse AbsoluteMouse.begin(); Keyboard.begin();

// Start Payload delay(1000);

Keyboard.press(KEY_LEFT_GUI); Keyboard.press(114); Keyboard.releaseAll();

delay(200);

Keyboard.print("notepad");

delay(300);

typeKey(KEY_ENTER);

delay(300);

Keyboard.print("guess what?");

delay(5000);

Keyboard.print("you just got....");

Keyboard.print(" ____ _ __ ____ ");

Keyboard.print("| \ \ / / \ | | __| __ \ | |");

Keyboard.print("| |) \ \ /\ / /| \| | | | | | || |");

Keyboard.print("| _/ \ \/ \/ / | | | | | | || |");

Keyboard.print("| | \ /\ / | |\ | |__| || ||_|");

Keyboard.print("|| \/ \/ || \_|__|____/ ||");

// End Payload

// Stop Keyboard and Mouse Keyboard.end(); AbsoluteMouse.end(); }

// Unused void loop() {}

WestonCode commented 1 year ago

This is little old, so not sure if you are still having the same problem. But hopefully it helps someone like me who just had the same issue.

If you need to move the Keyboard.press() into a utility function like this one.

void typeKey(int key){
    Keyboard.press(key);
    delay(50);
    Keyboard.release(key);
}

You need to pass the key value as a KeyboardKeycode instead of an int or uint8_t This should work in @richardcodingstuff 's situation.

void typeKey(KeyboardKeycode key){
    Keyboard.press(key);
    delay(50);
    Keyboard.release(key);
}

Basically when you pass the Key code constant as an int to the function, it is effectively the same as calling Keyboard.write(0xB0); instead of Keyboard.write(KEY_RETURN); which it says not to do here: https://github.com/NicoHood/HID/wiki/Keyboard-API#improved-keyboard