Hello everyone,
I'm currently in the process of using an Arduino Pro Micro clone to make a keyboard device. While most of the features work as expected, I've been getting strange results with using the Keyboard library to print newlines.
As an example, if my code calls the "TypeStringWithNewline" function below with the "helloworld" string, this is what happens:
1st call : helloworld [CRLF]
2nd call: helloworld (no newline)
3rd call: hellworld [CRLF]
4th + 5th call: helloworld (no newline)
6th call: helloworld [CRLF]
However, if I call TypeStringWithNewline with different inputs, it prints the newline each time.
Has anyone come across this issue before? I'm running this on a Windows 11, with a USB-C-USB3.0 connector between the Arduino and the PC.
Much appreciated in advance!
commandHandlers.cpp file below:
#include "commandHandlers.h"
#include "commands.h"
#include <Keyboard.h>
namespace CommandHandlers
{
void HandleCommand(const Command& command)
{
switch(command.command)
{
case CommandType::TYPESTRING:
TypeString(command.args);
break;
case CommandType::TYPESTRINGNEWLINE:
TypeStringWithNewline(command.args);
break;
case CommandType::ALTF4:
AltF4();
break;
case CommandType::ALTTAB:
AltTab(atoi(command.args));
break;
case CommandType::NONE:
break;
default:
break;
}
return;
}
void AltTab(int count)
{
Keyboard.press(KEY_LEFT_ALT);
for(int i = 0; i < count; ++i)
{
Keyboard.write(KEY_TAB);
}
Keyboard.release(KEY_LEFT_ALT);
}
void AltF4()
{
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F4);
Keyboard.release(KEY_F4);
Keyboard.release(KEY_LEFT_ALT);
}
void TypeString(const char* message)
{
Keyboard.print(message);
}
void TypeStringWithNewline(const char* message)
{
Keyboard.println(message);
}
}