Arduino Leonardo Mouse library not working edit: mouse library only comes into effect after I restart my computer [fixed]

So I bought an Arduino Leonardo in hopes of simulating a mouse. However, even after including all the necessary libraries, I couldn't seem to get any input at all.

#include <Mouse.h>

void setup() {
  Mouse.begin();
}

void loop() {
  Mouse.click();
}

Any help is appreciated. Thanks!

Welcome to the forum

What exactly did you expect the sketch to do ?

It is just as well that the sketch is not working else you would find it difficult to edit and upload a sketch with the mouse continually clicking its button

Be very careful when testing the mouse functions as it is easy to get stuck with the sketch continually moving or clicking the mouse

It would be sensible to have the mouse functions controlled by a switch, button or Serial input with the default being for them to be disabled

I just wanted to check out whether the Mouse library was working for me before I started to code, hence I wrote out the simple program

I had restarted my computer for another issue and somehow it had started working (spamming mouse clicks furiously), which is really weird

Thanks though

Well, that is what it is programmed to do

oh, I meant that it only worked after I restarted my computer, which was really weird

I did some further testing and found out that this is somehow reproducible on my side. I was testing the mouse movement function, and somehow it didn't want to work after I uploaded it

However, after I restarted my computer it started magically working again?? I'm quite confused

What else do you expecting with your code?
Are you really read the post #2?

Never mind, apparently you cannot send that many mouse clicks at once in a loop, that's why nothing was happening until a restart happened

just placed a delay within the setup function before clicking and it works fine now

thanks everyone

Didn't @UKHeliBob tell you the same thing in the first answer?

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