I'm pretty sure that this is the right forum to ask this question, but if it's not just lmk.

I am trying to create an auto clicker that is as hidden as possible for a computer engineering HID unit project.

What I have created so far (it works) is an Arduino being sent serial data via a C++ application that when receives a '@' character triggers the auto clicker code and a '#' to stop the clicking. I showed my teacher and he said this is too basic as it's just simply a serial data sending application, but he likes the autoclicking idea.

I had a few ideas but I don't know how I would make them work. All I am trying to do is while a keyboard or mouse button the arduino sends mouse clicks.

TLDR; Is there a way that I can communicate keyboard or mouse events from the mouse/keyboard directly to the Arduino whilst still working normally on the computer itself, or maybe even something less discrete like making a device driver?

I suck at coding btw so I will most likely need someone I know to help me code it.

  • Use an ATMega౩2U4 based board like a Leonardo. – Majenko Apr 20 '17 at 21:31
  • inside a single app or web site it's no problem, but i don't think there's an easy way to harvest system-wide key presses, at least in windows. it's a security issue, so it would be concerning if apps were given such great power. you might look into autohotkey: you can use it to set traps for certain keys/combos and fire actions when they happen. you would then need a self-contained action that talks to the arduino, like a bat file or shell script that echos over the serial. or use wifi and you can ping a url to send the MCU stuff. – dandavis Apr 21 '17 at 8:06
  • This appears to be a host software problem, not an Arduino problem. – Chris Stratton Jul 20 '17 at 15:20
  • @Majenko - an ATmega32U4 could emulate a USB mouse, but not get data from one which is what the question is actually about. This would only seem to help if you started with a ps/2 mouse and bridged it to the PC as if it were a USB one. – Chris Stratton Jul 20 '17 at 15:21
  • @ChrisStratton Emulating a mouse is what he wants. The control of it needs to come from the computer, and that is outside the remit of this site (windows programming). Nothing there is about the Arduino getting information from a mouse, only reacting to instructions from a PC to emulate a mouse. – Majenko Jul 20 '17 at 15:24

I think want you to look at this function SetWindowsHookEx on Windows. It lets you grab any mouse of keyboard input and don something, The input still follows the normal route, you just get notified about it.

I used this function to hook the 4th and 5th buttons on my mouse to start and stop media player, so when people pestered me at work I could pause my tunes.

MSDN - SetWindowsHookEx function

StackOverflow - Example that might work

| improve this answer | |

We can't help you with the getting of a mouse button or keyboard button state in Windows. That is about as far outside the scope of this site as you can get.

However the emulating of a mouse so that the Arduino sends mouse click events we can help with.

To do that you will need to get an Arduino that is based around a chip that can directly speak USB - that means an ATMega32U4 based board, such as the Arduino Leonardo.

These boards have the Mouse object by default, which you can use to send clicks:

void setup() {

void loop() {

How you start and stop the clicking is up to you - maybe send a simple instruction through serial will be the simplest way. You will need an application on Windows that captures the required events from your keyboard or mouse and sends whatever signal you decide on to the Arduino.

| improve this answer | |
  • The poster already solved this part: "What I have created so far (it works) is an Arduino being sent serial data via a C++ application that when receives a '@' character triggers the auto clicker code". The question being asked is the part about getting the input events, which you seem to want to ignore. – Chris Stratton Jul 20 '17 at 15:49
  • @ChrisStratton There is nothing in the question that says the Arduino generates HID mouse reports. Only that it triggers the mouse click code. For all we know (especially as it's tagged "serial") it just sends instructions back to his windows program to say "click the mouse now". – Majenko Jul 20 '17 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.