Move mouse through Arduino with python

Dear community,
I am currently working on a python script which should move the mouse with the Arduino

one of the code I found is
arduino.write((moveX + ':' + moveY + 'x').encode())
If I put in for moveX/Y = 100 it moves by for example 186x and 189y

Does anyone has a solution for that. And also I want to make a smooth mouse movement and not that it snaps ok that position. Would be great if anyone could help me out with that issue

I think that yu have to explain better.

I suspect that that writes data from the PC to the Arduino. Does your Arduino have a screen on which you want to move a mouse pointer?

as you are mentioning python.
Do you want to move the mouse-pointer on a PC running windows?

If the final purpose is to move a mouse on a Windows-Computer without the need of
special user-input realised by an arduino the straight-forward solution is Autohotkey.

Autohotkey is a scripting language with which you can do almost everything
keystrokes, mouse-moves , detecting pixel-colors on the screen etc. etc.
AutoHotkey Downloads?

best regards Stefan

So what I'm trying to do is object detection clicker. For fun I tried it in a game where you have to click blue balls that pop up. Getting the coordinates of that is not the issue. If I put that coordinates in the function though it just moves my mouse down and not to the direction where I want to mouse to be. Could you help me with that issue?

still have to clarify a few things:
objects to click on that are on an extra LCD connected to an arduino or

objects to click on that are on the screen of a windows-PC?

Do these objects always have the same position on the screen?

are these objects moving over the screen?
if the objects are moving over the screen how will you detect this changing position on the screen with the arduino?

If the objects have a fixed position I really recommend to use autohotkey

otherwise you have to describe in much more detail how the whole thing shall work
best regards Stefan

The objects can move without a problem. I use pythonp to detected the location of it. I use opencv to do it. Only think I need is to move the mouse cursor on my screen to move to the detected object. I have all the code already just not a really working one where I can put in x and y move the mouse to the detected object

You are not answering the questions asked.

you want to use an arduino to move a mouse-pointer on a windows-PC screen to certain coordinates xy. The coordinates were given by a python-code somehow working together with openCV.
I'm pretty sure that python can do mouse-moves too
So I did a qoogling ( a quick googling) and found this
How do I move the mouse in Python?


Bildergebnis für python move mouse to xy

This code uses moveTo() function, which takes x and y coordinates, and an optional duration argument. This function moves your mouse pointer from it's current location to x, y coordinate, and takes time as specified by duration argument to do so.

Do you mind to explain why the python-code has to send the coordinates to an arduino over a serial interface and the arduino is acting as a HID-mouse moving the mouse-pointer?

For getting this setup to work:
Even me as a potential distant supporter of you I would ask for
If you put the mouse-pointer to a defined position let's say x = 500 y = 400 and the let run the arduino a code that moves the mouse to a defined position let's say x = 700 y = 800
where is the the mouse-pointer located after executing this one single time?

With just posting a such poor and way too short piece of information as:

Nobody will be able to help you.
This is not just "can somebody post the cheatcode for entering platinum-level"

You have to provide much more information.

One of the really important things is to post your complete arduino-sketch

There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

I know that the mouse moves from the point where it was placed before. That's why I placed it in the top left corner of the screen to get the starting position of x/y= 0. Using move to() x= 700 and y = 800 it should also move to 700 and 800. The reason why I don't use something like pyautogui is that it isn't able move the mouse in a 3d room. Like normal on screen is possible but this is not what I'm looking for. I know that I can make the mouse move with moveTo() command but I want to write everything into python and not into the Arduino IDE since that variables changes every time for x/y. That's why I need a command that works in Python and moves the mouse on my screen.

Your screen IS 2D and stays 2D. There is absolutely nothing 3D on a 2D-screen

So this means you are asking for

python-code.

You will get much better and quicker answers about python-code in a

python-forum

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