Im an absolute clueless beginner and I wanted to do a project that recorded keystrokes and toggles the loop on/off via the very same keyboard ive been using domestically on my PC.
When i tried to assemble it the first time The connection was like this: My keyboard wire usb to the usb host shield, connected into the leonardo and the leonardo wired usb to the regular USB PC port.
I proceeded to the Arduino IDE, installed the Usb Host shield Library, checked the Tools>Board>leonardo, Tools>correct port with (arduino leonardo) and tried my best to get AI assistance but its not working so good;
Currently using this
#include <hidboot.h>
#include <usbhub.h>
#include <Keyboard.h> // para enviar para o PC
USB Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
class KbdRptParser : public KeyboardReportParser {
void OnKeyDown(uint8_t mod, uint8_t key) {
uint8_t c = OemToAscii(mod, key);
if (c)
Keyboard.write(c); // envia para o PC
}
void OnKeyUp(uint8_t mod, uint8_t key) {
// opcional: tratar soltando tecla
}
void OnControlKeysChanged(uint8_t before, uint8_t after) {
// opcional: ctrl, shift, alt
}
};
KbdRptParser KbdPrs;
void setup() {
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.println("Erro ao inicializar USB Host Shield");
while(1); // trava
}
delay(200);
HidKeyboard.SetReportParser(0, &KbdPrs);
Keyboard.begin(); // inicia teclado virtual Leonardo
}
void loop() {
Usb.Task();
}
I'm not sure if its a library issue, the main letters are working except its as if capslock was on but the keyboard led is off. Capslock and numlock are not working properly, it seems numlock is toggling both capslock and numlock leds.
Tried a keyboard tester online to see if inputs are being registered, even though numlock is turn on and off the right and wrong leds they are not registering on the tester.
Arrow keys, Insert, home,page up/down, delete are not working and the
Numpad is not working
Hopefully someone can share some thoughts? thank you in advance.
Do you mean the alpha keys "a..z" look like "A..Z" and the numeric keys "1..0" look like "!..)" or just the alpha keys? This function looks like CTRL, shift and ALT are not functional.
I wanted to make a project of simple keyboard macros using my PC keyboard to toggle and untoggle said macros.
The problem is im struggling with the setup so much and im not sure how to proceed from the very first steps.
Before the project i had to setup the keyboard + leonardo + usb host shield, when I opened the Arduino IDE, installed the usb host shield lib but my keyboard simple does not work.
Do I have to code every single keystroke possible on the keyboard?
How do i even do that? Even Capslock, capslock leds, shift, Fkeys, etc?
I thought this would be very plug n play since the leonardo is the board generally recommended to work with Keyboards. Can someone please, point me in a direction i could solve this issue?
Sorry if I was not clear, english is a second language.
Do you want your Leonardo to emulate a keyboard?
yes
Or do you want to plug a keyboard into your Leonardo?
I dont think i can do that right, I can plug it on the usb host shield
They way I invisioned the project was to record keystrokes for repetitive tasks such as holding arrow keys while operation any button of the keyboard, recording the same amount of time im holding the button, maybe im not sure if its possible, to hold two keys at the same time? like A+B. Only then after its all recorded, i could also have a key in the keyboard to toggle it on/off.
***edit
I forgot to mention, the project is not the issue yet, the problem is when i plug it to the USB host shield+leonardo, the keyboard does not work, all leds off, inoperable.
Thank you advance
can the USB host shield act as a USB device, e.g. a keyboard?
maybe worth looking at ESP32-S3 which supports USB OTG and can act as a USB keyboard device
I have merged your forum topics due to them having too much overlap on the same subject matter @kardanss.
In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.
The reason is that generating multiple forum topics on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Ive been trying to get my arduino to function as a keyboard and reproduce very same keystrokes I reecord with 1:1 precision.
biggest issue is i couldnt find any tutorial on the matter or seen real projects like that.
the way i invision the project is having a toggle for record/stop recording, ill proceed to press keyboard buttons untoggle the recording and playback as I see fit.
atm I have a leonardo and a usb host shield so i can use one keyboard as input recorder and operate the toggles, can someone please share knowledge on that matter?
I have no real coding experience, I'm just trying to figure out how to record the keystrokes for now.
That spying device you are seeking is called a Rubber Duckey or a Keylogger. Your government has one in your operating system and knows everything (everything) you type.
Here's one disclaimer from one web site:
Disclaimer
Use it only for testing purposes on your own devices!
I don't take any responsibility for what you do with this project.
Tell your people; visiting hours will be Sundays, 14h to 17h.
wut the, i dont wanna do for hacking people i just wanna automate certain stuff I do on computer, a macro of sorts?, I only intend on recording keystrokes for like 20-30s and loop.
Ive been trying to get my arduino to function as a keyboard and reproduce very same keystrokes I reecord
For help, post the code you are currently using, using code tags, and describe the problems you are having. Posting instructions can be found in the "How to get the best out of this forum" post, linked at the head of every forum category.
im not confident on sharing what I was using because it was AI assisted, I gave up on that, I never seen it work properly, i ditched the code because somehow it was not finding my com ports causing all sort of problems that I couldnt even start the leonardo and host shield together, I just need directions for now.
Cross-posting is against the Arduino Forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting can result in a suspension from the forum.
In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.
This is the second time I've had to clean up your cross-posts. You need to start behaving in a more responsible manner. If you won't listen to my polite warnings, then I'll be forced to resort to an account suspension to get your attention. I don't want to do that, and I'm sure you don't want that either.