How can I send real time xy mouse coordinates from a desktop to an arduino?

ah ok, it's open now

Perfect.
The python file is on the right, this is where you write the code that you want to save.
You can think of the left as a terminal for the python program.

Start by saving the python file as py_duino_mouse in a new folder called python n your documents folder.

ok done, thank you for your help by the way :smiley:

use this code then?

No worries. I teach python. I start with students less than 10 and see them through college.
I'm happy to help you figure this out if you're willing to try for yourself first.
Please read the page I sent for the basic code.
You can use the
print()
function to output variables to the terminal.

# This is a comment
# This is like the loop function in Arduino C++
while True:
    # Indent your code inside a loop instead of using brackets

Sounds good thank you, I will work on this and keep you updated. Kudos!

Combine it with the code I just gave you
Do not copy the chevrons >>>

ok sounds good

I whipped up a timed, non-blocking version of the code. I'll guide you to doing the same tomorrow after I see your attempt.

1 Like

success

Thoroughly comment the code so we know what everything does.

Absolutely! Each "window" has it's own XY based on the edges of that window.
Paul

just like a map would show you. Different map, different values for X and Y.

But that's not how piautogui's position function works, it returns the screen position of the mouse, not the relative window position.

So, you could hide all the windows and still get the same values?
Paul

Yes

That is NOT what the OP originally asked for help with.
Paul

One of us is off base. Let's figure out who so OP can get the best help.

It's become clear that by cursor OP meant the mouse pointer.
What I've helped him with so far is to build a python script that captures the mouse pointer position on the screen repeatedly.
From here I plan on helping OP to understand how to do non-blocking timing and to send the mouse pointer data in 4 bytes to his Arduino over a serial connection.
Then in the Arduino program to translate the mouse pointer position to a change vector for the stepper motor and to execute the change in non-blocking code while continuing to receive updated mouse pointer position data.

If I've missed the point please help me to understand where.

I think the OP was referring to the window of a game program. Your scheme will work perfectly if the OP can determine the positions of the 4 sides of his active window and ignore any cursor positions outside of those limits.
Of course, that means the window size and position on the screen cannot be changed.
Paul

1 Like

Awesome point.
When OP check back in we can clear that up and if necessary, I can adjust the python script strategy to account for that.