Using Windows 10 64bit
I'm trying to learn how to code in python and I decided to make my first program a simple bot for a game.
The game is a downloadable game.
The goal is for my mouse to click a button at coordinates (200, 200)
I have tried many different ways to get this to work.
I've tried...
PyAutoGui
pywin32
ctypes
PyAutoGui implementation
pyautogui.click(200, 200)
pywin32 implementation
import win32api, win32con
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(10,10)
Any ideas? From what I understand I need to use a low level driver?
I just don't understand how to emulate it as if a real mouse was clicking
try pyautogui.mouseDown() or pyautogui.mouseUp() instead...
info: https://automatetheboringstuff.com/chapter18/
Make sure, that you set the raw input checkbox in game settings for the mouse. I had the same issue with CSGO
Not sure if this will work with your game but you can use PyUserInput.
Related
I will like to know which python library I can use for detecting changes to the mouse pointer state. Say a change from "arrow" to "hand". I have looked at pyhook, pyautogui, pynput, pywin32, pynput. These may have functions for detecting mouse movements and clicks but none dedicated to detecting cursor icon change. I know this can be implemented because i have code implementing it in C++ but just not python. Looking forward to the communities response.
Here is my problem. I developed a tkinter GUI for my project. However I am stuck with tkinter limitations. I developed python gui to create a virtual view for a red table as below. The window does not have any border or title. It is just put on the a picture background which is outside of the code.
However as you can see it is not lively enough for me. I want it to look like this:
Is there a way to do this in tkinter? I tried transparent backgrounds, however in Ubuntu transparent background with visible object is not possible. Also You cannot make different window shapes other than rectangle. What is your suggestions? Should I use another library. I really need an expert opinion about this.
Transparent background reference
Different window shape other than rectangle
My environment : Ubuntu 16.04 Python 3.5.2
You can't specifically change the shape of a Tkinter Window, but you can create a canvas and design your own shape (then add your buttons and labels on this canvas if needed).
You can also take a look at PyQt or Kivy, but if you are confortable with Tkinter go with Canvas.
So to solve my issue I found a python library wxPython:
You can check this link it creates Wx non rectangular shape
It creates the the window using inheritence. I tried selected answer and It solved my question.
Btw I tried QTPython, Kivy, tkinter. Non of them had straight example such wxPython.
I want to write something like a taskbar/dock/panel(like tint2,...) with pyQt5.
I know how to write regular GUI applications with it, but my tiling window manager(herbstluftwm) maximizes my panels and openbox makes them resizable etc.
My question : How can I make pyQt show my application as a panel instead of a window? I haven't found anything about that in the documentation.
Thank you.
Thanks to musicamente's help, i could find that the function setWindowFlags() is what I need. It allows to change the behavior of a window.
A website explaining this function is https://pythonprogramminglanguage.com/pyqt5-window-flags/
When using tkinter to create a more modern looking application, I looked to MS Word to inspire my design. Then I noticed that only when I'm using the application on a High DPI device that it looks so terrible.
Is there a way to compensate and make it look just as crisp?
NOTE: "Don't use tkinter" is not on the table.
The best solution I have found for this is to create a custom widget using the WCK (Widget Construction Kit). Text displayed using this is automatically Anti-Aliased.
Try typing this at the beginning of your code
try:
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
except:
pass
I think this will solve your problem.
The goal of the program i'm trying to write is a bot that can click and play flash games and press keys inside a window webpage even when I do not have the window selected. My question is very similar to this. What I want to know is how to use win32, selenium, and PIL to take screenshots, analyze the screenshots, and click and press buttons accordingly from the bot. I've looked through the win32api documentation and found little about how to click inside a window in the background.
If someone could give a link to someone who has done this before or just a little nudge in the right direction would be amazing!
pywinauto is even simpler, but it may not recognize Flash controls. The code should just look a bit shorter:
import pywinauto
app = pywinauto.Application().connect(path='process_name.exe')
app.MainDialog.click_input(coords=(953, 656))
To check which controls are visible:
app.MainDialog.print_control_identifiers()
P.S. If you work with Python 3.x, this clone is compatible with Py3.
If your goal is detecting and interacting with images on screen, you might want to take a look at Sikuli. This is exactly what it does. Sikuli automates anything you see on the screen. It uses image recognition to identify and control GUI components. It is especially useful when there is no easy access to a GUI's internal or source code. More info here.