NicoHood/HID

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

richardcodingstuff opened this issue · 1 comments

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

#include <HID-Project.h>
#include <HID-Settings.h>

// 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() {}

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