Registering Laptop Keystrokes

Hi all! I'm aware of Arduino's Keyboard library, but it sounds like it only works with USB keyboards connected directly to the board via a shield. I'd like to treat my laptop's built-in keyboard as a USB keyboard (can I treat my computer as a USBHost?), but am unsure of how to do so, or whether such a thing is possible. My goal is to register my computer's keystrokes, and have that change a value during runtime. Many thanks!

If I’m reading your question properly..l

You simply need to use the Serial monitor or something like it - to exchange characters with the Arduino over a USB COM port.

You can try applications like PuTTY or similar, and there are many examples of what’s needed at the Arduino end.

The keyboard library allows the arduino to appear as a USB keyboard to a computer, so that the arduino can send key characters to the computer. Sounds like that is the opposite of what you want.

If you can get the Microsoft software development kit documentation( Many volumes) you can write a program to intercept all the keyboard strokes and either pass them on to Windows or do what you want with them.

Thanks! I know I can send text by writing to the Serial monitor. But I'd like to instead register keystrokes, even when I'm not in the Serial, and without having to hit enter each time to send the data. Is there a way to do this? Not sure if PuTTY would achieve this.

Right--that's indeed the opposite of what I'm trying to do. Although, that sounds like a fun thing to explore on its own. Reminds me of the Makey Makey.

I'm sadly working on macOS, so I'm not sure this applies. In either case, it sounds like you're suggesting that I intercept the keystrokes with some external software, but I'm not sure how I'd then pass that information to the microcontroller. Thoughts on that?

Maybe it’s time to articulate EXACTLY what you’re trying to achieve.

No program expects RETURN if it programmed to sniff the port…. it just sees characters (RETURN) is just another character.

We don’t know what you’re trying to do, so the answers and observations already provided will do what you want, but maybe you want something else.

I might be misunderstanding, but here's what I've been trying to articulate: I'm writing a very simple program that changes the brightness of an LED incrementally using commands. At the moment, I know how to do this using the serial monitor--suppose u is up, so if I were to type u and hit enter repeatedly in the Serial Monitor, then I would increment the brightness repeatedly until it reaches some maximum--but I'm looking for a way to do this without using the Serial Monitor. My goal is to be able to press the u key in any other window, have that keypress be intercepted, and use that event to increment the value in the microcontroller's memory.

I'm not exactly sure what you are trying to do.
You want to be able to press a key on your PC/Laptop and that will tell the controller to up or down LED brightness.

Senario 1.How will you distinguish say pressing "u" on your laptop, when typing the word say "understand" in a word processor app, and not have the LED brightness increase?

I would just have a separate window open with serial monitor or putty or TeraTerm terminal app running to send my LED commands the controller USB.

Another suggestion, use an ESP32 as your LED controller/web server, and open a browser window to send commands over WiFi.
Your Laptop app can be two buttons you click with the mouse.

First can you explain how to over come scenario 1?

Tom... :smiley: :+1: :australia:

Thoughts? Yes, begin with the software development documentation for the Mac. Since it and Windows are all based on message systems, similar to Unix and Lenix from program to program, you can also intercept those messages. Not made to be easy, but can be done.
Would likely take years of work, however.

's OK, neither is the OP. :rofl:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.