Hi,
I'm kind of a noob at this, but i tried making some code but the function typeKey doesn't seem to work when i call it with typeKey(KEY_RETURN)
Here's my code.
#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(100);
Keyboard.releaseAll();
delay(100);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(114);
Keyboard.releaseAll();
delay(100);
Keyboard.print("chrome");
typeKey(KEY_RETURN);
/* Keyboard.press(KEY_RETURN);
delay(50);
Keyboard.release(KEY_RETURN);
*/
}
// Unused
void loop() {}
Maybe it is caused by a wrong data type, try to alter "typeKey(int key)" to either "typeKey(unsigned int key)" or "typeKey(uint16_t key)".
the function keyPrint doesn't seem to work when i call it with typeKey(KEY_RETURN)
What keyPrint() function would that be ?
In any case, what value does KEY_RETURN have when you call typeKey() ?
UKHeliBob:
What keyPrint() function would that be ?
In any case, what value does KEY_RETURN have when you call typeKey() ?
Sorry, i meant the typeKey() function.
I read that keys are of type "char".
I think I know where it goes wrong though, when I run it, it prints "chrome(", instead of just "chrome". So it sends a different scancode instead of the one related to the RETURN key.
I don't know why this is happening though, if i remove the call to that function and simply write:
Keyboard.press(KEY_RETURN);
delay(50);
Keyboard.release(KEY_RETURN);
[which is the function's body]
Then it works perfectly.
You are combining signed (int) and unsigned (uint16_t) types, this may cause problems. Please fix your "typeKey" function as mentioned above.
Danois90:
You are combining signed (int) and unsigned (uint16_t) types, this may cause problems. Please fix your "typeKey" function as mentioned above.
Can you tell me where I'm combining these 2 types?
thanks
There are two(*) Keyboard.press() functions, one that handles KEY_xxx and one that handles ASCII:
class KeyboardAPI : public Print
{
public:
...
// Raw Keycode API functions
inline size_t write(KeyboardKeycode k);
inline size_t press(KeyboardKeycode k);
...
// Print API functions
inline virtual size_t write(uint8_t k) override;
inline size_t press(uint8_t k);
...
};
You need two typeKey() functions, too:
void typeKey(KeyboardKeycode key)
{
Keyboard.press(key);
delay(50);
Keyboard.release(key);
}
void typeKey(int key)
{
Keyboard.press(key);
delay(50);
Keyboard.release(key);
}
or use a template:
template <typename T> void typeKey(T key)
{
Keyboard.press(key);
delay(50);
Keyboard.release(key);
}
(*) Well, actually three:
class DefaultKeyboardAPI : public KeyboardAPI
{
public:
// Add special consumer key API for the reserved byte
inline size_t write(ConsumerKeycode k);
inline size_t press(ConsumerKeycode k);
...
};
class Keyboard_ : public DefaultKeyboardAPI
{
...
};
extern Keyboard_ Keyboard;