HID Mouse without Mouse.h

I have a project in Embedded Systems subject in mu univ. where I'm tasked to make a HID mouse using 'Arduino Leonardo' without 'Mouse.he'.
I tried address the problem programmatically using the SetCursorPos(x,y) function from windows.h for windows.
And something like this in linux:

// Construct the xdotool command to move the mouse cursor
   char command[100];
   sprintf(command, "xdotool mousemove %d %d", x, y);

   // Execute the xdotool command
   system(command);

But I don't think the arduino have the ability to execute commands in the terminal. so I've used up all my ideas and now I'm stuck in a dead end.
Thank you all for your time
(P.S. : I'm more of a developer than an electrical engineer, that why i tried using programming, I don't have solid bases in embedded systems)

Welcome to the forum

Is there any restriction on using the techniques used by the Mouse library for which you have the source ?

1 Like

I appreciate the warm welcome!

Yeah the teacher specifically instructed us to use neither 'Mouse.h' nor Arduino IDE cause it'll render the project too easy and pointless.

I'll figure out how to use arduino-cli later, for now it's more important to find an alternative way beside 'Mouse.h'

Two ideas

  1. Enable mousekeys.

Linux and MacOS have similar features.

Use Keyboard.h on Leonardo to send arrow keys to move the mouse cursor.

  1. Send x,y to PC over USB serial port.
Serial.print(x);
Serial.print(',');
Serial.println(y);

On PC, read x, y from USB serial port.
Run xdotool to fake mouse activity using x,y values.

1 Like

I'm sure it's not forbidden to analyse the mouse library to see how these things work. Just don't copy the code.

Further the datasheet of the 32U4 (and possibly a number of application notes) will be your friend.

If the teacher does not want you to use the Ardiono IDE, I think it's unlikely that he will be thrilled if you use the Arduino CLI :rofl:

This is plain software development and not electrical engineering :wink:

1 Like

rename Mouse.h to foo.h
use VS Code & plattformio plugin as IDE.

The requirements will be fulfilled.
Your next homework will get formulated better.

2 Likes

I'm sorry for the late reply,
That the solution I'm using currently, I'm using pyautogui to move the mouse after reading the x and y values sent by the arduino board.
But it's not the solution he wanted, I need to code it using raw C language using avr as if I'm coding a the Atmega32u4 itself

I'm sorry for the late reply,

Yeah I just realized that :man_facepalming: , If i only have enough time, enough free time or enough background in coding raw C using avr that might have been much easier. :man_facepalming:

Yeah I just found out that i can use something like avrdude or winavr to upload my code to the arduino board.
and after using avrdude to upload my code (.hex file) to board, its port stops being recognized :man_facepalming: :man_facepalming:

Well... this is the first time, in my four years of learning software development, that I need to read a microcontroller datasheet and figure out how to manipulate ports, UART, and stuff. :man_facepalming:. I guess my country's educational system is failing :laughing:

I'm sorry for the late reply,

I'm sure that this is a smart idea, but i know for sure he's gonna ask about the foo.h and its source :laughing:

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