I am making a bot at the moment using pyautogui. When I run it in pycharm, it clicks on wherever my mouse is after 10 seconds, but if I use it on google, it runs but does not click. here is the code:
import pyautogui
import time
time.sleep(10)
while True:
pyautogui.click()
does anyone know how to fix this (btw i'm using chromebook)
Related
I have a certain script that i want to run on the background. I know that similar questions have been asked but i am still having a hard time achieving this.
Here is my code
import pywinauto
from pywinauto import Application
import time
app = Application().start("notepad.exe")
#app = Application().connect(title="test.txt-Σημειωματάριο")
app.window().set_focus()
app.window().minimize()
time.sleep(2)
app.window().send_keystrokes("{ENTER}")
The above code is minmizing the notepad window but i cant see that enter was indeed pressed. Same goes for other keystrokes that i tried. What am i doing wrong?
I am quite the beginner and have the folloing problem: I am trying to automate a mouse movement and some key presses and the code works until I select the program window. (So I can run it and use it for every program I tried except the one I want to use it for). The code still runs but the mouse movement it should do does simply not happen and I don't know why.
I have tried it using win32api, win32con and pyautogui both failed. So is there any possibility to make the mouse movements more like real mouse movements? or does anyone have an idea why it might not work?
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
click(x, y)
and
pyautogui.click(x, y)
From the comments:
As the target application is running with administrator privileges, a nonprivileged program can't simulate events on it.
To work around that, run your script as administrator.
I have a programm that use pyautogui. There are some mouse moves, clicks etc. Computer goes to sleep mode and mouse moves doesn't work there. I want to programm auto waking up from sleep mode at time for my pyautogui script available. I find some answers with SetWaitableTimer() but can not to code it right. Sorry for my bad English.
According to THIS
You should use keyboard event which will make your computer active and doesn't let to go in sleep mode.
The code describes there was:
import pyautogui
import time
while True:
pyautogui.press('volumedown')
time.sleep(1)
pyautogui.press('volumeup')
time.sleep(5)
Hope it helps!
I was trying to make a bot for a game, which you can find here. You have to play games to get a tiny amount of bitcoin, like satoshis. Anyway, I as going to make a bot, but when I tried to click on the game window, it didn't do anything. Here is my code:
clicker.py
import pyautogui
while True:
x, y = pyautogui.position()
pyautogui.click(x, y, button='left')
I don't know what's going on, is it my code, or is it the website html? If it is the html, what should i change?
What may be happening is that when you run the program, your mouse clicks so fast that the site does not recognize the clicks. But anyways, how the program is supposed to stop? Your mouse will be clicking everywhere and you may not be able to close the Python window. Do something like this:
import pyautogui
from time import sleep
from threading import Thread
def click_function():
while True:
x, y = pyautogui.position()
pyautogui.click(x, y, button='left')
sleep(0.5) # an acceptable waiting time between one click and another
t = Thread(target=click_function)
t.daemon = True
t.start()
sleep(60)
# Here you put the amount of time you want the program
# to run, in seconds. This will ensure that the program
# stops sometime and you don't get stuck.
You can try adding sleep(n) at the beginning of the code. That is, you run the program, enter the site normally and point your mouse at the specific part where you want to click. Change the value of n to a considerable amount of time in seconds you can perform these tasks. If this doesn't work, you can try the Pynput module, which works similarly to PyAutoGUI.
Motivation
I'm going to use python to click the left mouse button to do some automation test.
My development & test environment
My local development machine(Win10) is left-handed for mouse. It means that I click the left button of my mouse to show the Mouse-Right-Click-Menu.
The test server is right-handed for mouse. I usually use TeamViewer to access the test server, and I don't need additional settings for mouse on the test server for my access. I mean, with TeamViewer, if I click left button of my mouse in the TeamViewer viewport, the Mouse-Right-Click-Menu is popped up on the test server.
Problem
I use pynput(https://pypi.org/project/pynput/) to click the mouse button. Here is a test code:
def simulate_left_click():
from pynput.mouse import Button, Controller
m = Controller()
m.press(Button.right)
On my local machine which is left-handed, this code does NOT pop Mouse-Right-Click-Menu, which is what I want, while on test server which is right-handed, this code pops Mouse-Right-Click-Menu. This inconsistent behavior of this code is annoying.
What I want to do
I want to write a function 'is_system_left_handed()', like this:
def simulate_left_click():
from pynput.mouse import Button, Controller
m = Controller()
if is_system_left_handed():
m.press(Button.right)
else:
m.press(Button.left)
My questions
How to implement the function 'is_system_left_handed()'? is it possible?
If it is not possible, is there any other python package available for this problem?
Thanks
Use GetSystemMetrics(SM_SWAPBUTTON) to detect if the Mouse-Buttons are swapped...
SM_SWAPBUTTON = 23
from win32api import GetSystemMetrics
print(GetSystemMetrics(SM_SWAPBUTTON))
PS:
Requires pywin32: python -m pip install pywin32