Script moving the mouse on a virtual machine - python

I prepared a script which does some operation on a web page, recognize colors and simulate mouse click and keyboard send keys while running. It works fine.
The problem is that I want it to run on a virtual machine (I'm trying greencloudvps) and it works fine as long as have my eyes on it.
As soon as I close the "remote desktop connection" tool, the script crashes, because (I guess) there is no more a monitor where to move the mouse.
I use the following Python code:
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
Is there any solution?
UPDATE:i tried to run my script also on Amazon virtual machine but i got the same problem. Which could be the solution?
Basically I need to click with mouse, read pixel colors and send skeys with keyboard automatically on a virtual machine even when I don’t witness the session, using python

Related

Handling remote (RDP) mouse clicking via Python

I am using pyautogui to automate some mouse clicking in a script that I created.
This script needs to perform one click to log into a program, nothing else (besides other non-clicking stuff). The idea is that the script will run on a remote Win10 PC via a task scheduler every day at, lets say, at 11PM.
My script works perfectly when run on my own PC but I am running into issues with how to handle the remote RDP resolution to correctly identify the mouse position to click. Furthermore, the script will run on a remote PC that might not have "active user" logged in and I am not even sure if this mouse clicking approach will work. How to identify correctly the "resolution" of the remote PC?
Could you help me?
Thanks.
Pyautogui can be used to interact with remote system the same way a human can by opening the RDP or VNC window identifying elements inside of it and then directly interacting with them. This works but you're now expecting two systems to be in sufficiently consistent state for the automation to work. This does have the advantage that you don't need to know the resolution of the remote system just what the interactable elements look like when rendered through the RDP client on your system.

HID devices for virtual machines

I've been playing some crypto games and to boost my farming I've been using a bot that controls the mouse to farm my resources.
The bot is built in python and it uses the main hid device to work.
I've been thinking in using VM's to run the bots with the games, but it made me run into a question.
Is it possible to emulate a virtual mouse cursor or something similar to run inside the VM?
This way i wouldn't need to let mt pc sitting farming and not utilizing it and the vm would run the bot and the virtual mouse to farm my cryptos.
Is it possible to emulate HID devices for VMs?
Thank you all in advance.
You can use pyautogui to simulate mouse clicks. You can run the python script inside the VM and then let it run in the background and you can freely use the mouse outside VM.
Usage is simple
import pyautogui
pyautogui.click(100, 100)
To know more about mouse functions refer to the docs https://pyautogui.readthedocs.io/en/latest/mouse.html

How to start a python script after booting in Raspbian?

I made an app in Thonny that when I run it, shows a camera connected to RPI and shows the image in an interface. You can also use the keyboard to do some things in the interface, take photos, etc.
I always execute it using thonny (run button), but now, I am trying to autostart the program in python when Raspbian ends its starting (after a shutdown or reboot).
I tried to do it in 3 ways:
autostart
lxde-pi/autostart
crontab
But it doesn't work. It starts Raspbian, but nothing more. Any ideas or code to do it?
Thanks a lot.
This might be a bit late for #mash_10, but for anyone else who lands here my solution that auto fires a bash script on the home folder. To add new automatic startups I just add code to my personal bash script. This works on Buster rpi.
Details are in my answer here How to automatically launch python file once GUI has loaded on Raspbian Pixel

sending mouse/keyboard events on remote desktop

So I am trying to set up a Continuous integration environment using Jenkins.
One of the build step requires a series of mouse actions/movements to accomplish a task in Excel. I have already written a python script using the ctypes library to do this.
The script works perfectly fine if I run it either through Jenkins or on the server itself when I am actively logged in to the server using remote desktop connection, but as soon as I minimize/close the connection and then run the script from Jenkins, it seems the mouse events never get executed. Is there something I can add to the script to make this work? Thanks for any help you can provide.

Run terminal command as startup reacts different from manually (linux raspberry pi)

Here's a short description of what I have:
I have to raspberry pi's in a local net work. I one of them I have a .py script named watchdog.py that starts a stream and then uses a sshpass command to the other pi to display the video stream.It also has some signaling LEDs a some push buttons for control
the problem is:
If I open a terminal and run the watchdog.py script in the GUI everything runs as it should be. So I thought of running it as a service as boot and installed upstart and made it run as a service (successfully I think). The thing is. If I boot the pi and then press the button to start the streams,they wont play on the other Pi, the LEDs ligh up and all the buttons work. And even the CPU load behaves the same way, but i still don't video nor audio. I have thought of trying automatically open a terminal (LXterminal) widow and run the python scrip on that window. but I didn't want the streaming raspberry pi also booting into gui (tough I guess I would mind if that makes the whole thing work).This little thing i making the whole project useless.
What are you using to play the streams? Depending on how you boot up the second Raspberry it might not have started some daemons for audio/video playback?!
You should (if you're not already doing) write a log (import logging ;)) and write a logfile which you can track for errors.
answer moved from OP's question itself:
I found a way that seems to work so far. instead of running the python script as a service I tried running it as cron job at reboot, and it worked. now it all works straight from reboot and I have Audio and video.

Categories

Resources