How to use the control_click function with pyautoit? - python

I am trying to simulate mouseclicks with python, without using my actual mouse. I have found the autoit library and the control_click function seems to do exactly what I want. However, I am not really sure how to use the parameters? I have read through so many posts and not a single one helped me really out. This is the best I have so far:
autoit.control_click("Bluestacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]", click=1,x=500,y=500)
The error that I get: autoit.autoit.AutoItError: send click message failed
I have tried to use the AutoIt3 Window Info program, but the text where the controlID is supposed to be is just a blank box...what am I supposed to do?

Related

Code to listen for changes in a pywinauto Listbox

I'm using pywinauto to interact with the window of an old game - specifically the dedicated server GUI. I've been able to connect to it with:
app = Application(backend="uia").connect(path=r"C:\Program Files (x86)\___.exe")
Using a loop, I'm able to read each line in a Listbox in a specific window using:
for i in dlg.ListBox.descendants():
print (i.window_text())
The Listbox behaves as like a console output area and I've also been able to write commands to the Edit (input) field which appear in the Listbox.
All of this is great considering I didn't think it would be easy at all!
However, the last part of what I'd like to do is proving more difficult...
I want to listen for changes in the list box so I can react to them and write different responses back into the Listbox. So for example, when a player joins the server, I want my code to know that a new line has appeared in the Listbox (so I can write a custom welcome message to the Edit field).
I have tried to look at listener scripts but I feel a bit out of my depth and can't seem to find a simple code example that could help me accomplish this. Does anyone have any ideas where I could look or what I could use?
Even better... would anyone be able to provide some sample code for me to re-work?

Python: how to create multiple threads running at the same time

I am creating a game using Python and tkinter, and when I tried to add some music, the function making the music stopped the rest of the script (and also the window).
So I need to create a new thread I think to play the audio and keep the window working...
I tried some things making errors, not running, or stopping the window, I currently have :
window.after(2000,showText,"Text 1")
window.after(2000,playSound,"Sound 1.wav")
window.after(7000,showText,"Text 2")
Important detail : the playSound function returns nothing, so nothing needs to wait for it.
I also don't know much about programming in Python, I prefer using LUAU.
Try using the module threading. I found this article very useful for understanding the core concepts and setting up my first multithreaded program
I found another article telling exactly how to make it work and it now works.
The article is probably in french, but I give the link : http://www.xavierdupre.fr/app/teachpyx/helpsphinx/c_parallelisation/thread.html

_tkinter.TclError: invalid command name ".entry#"

I've been coding in python using tkinter and came across an exception from the tinter library.
Since I don't know exactly what the error means, it is hard for me to debug my program. I was wondering if someone could outline the error and suggest what may have caused it, so that I know what to look for when debugging my program. _tkinter.TclError: invalid command name ".entry#" (The hash represents a number).
I have an image showing the navigation through my program that causes the error if it helps.
Basically, the program will only let me view a sub-menu in the "record" section once, each time I run it, when it should let me enter them as many times as I need to.
You should include the error as text and not as unreadable image.
Based on the error message, you're trying to call .get() on an Entry that doesn't exist anymore. Maybe the parent window has been destroyed/closed and the entry is not there anymore. Or maybe it is just a context thing... hard to tell without the code.
If you can't figure out, please edit your question and add a MCVE, then I will edit my answer with more specific information.

Programming MEL/Python Script textField to receive all script editor output

I'm trying to figure out a way to get the script editors output to write to a textField control in Maya for a custom-made window. Essentially, I'm trying to rewrite the commandline function without having the separator or input options.
I'm having a bit of difficulty figuring out what to do, since there seems to be not clear information in Maya's documentation - can I get a few pointers in the right direction?
the cmdScrollFieldReporter and cmdScrollFieldExecuter controls do most of the work for creating the script listener -- see if those do what you need before trying to invent something new.

Python widget/cursor detection?

Beginner python learner here. I have a question that I have tried to Google but I just can't come up with the proper way to ask in just a few words (partly because I don't know the right terminology.)
How do I get python to detect other widgets? For example, if I wanted a script to check and see when I click my mouse if that click put focus on an entry widget on a (for example) website. I've been trying to get it to work in Tkinter and I can't figure out even where to begin.
I've seen this:
focus_displayof(self)
Return the widget which has currently the focus on the
display where this widget is located.
But the return value for that function seems to be some ambiguous long number I can't decipher, plus it only works in its own application.
Any direction would be much appreciated. :)
Do you mean inside your own GUI code, or some other application's/website's?
Sounds like you're looking for a GUI driver, or GUI test/automation driver. There are tons of these, some great, some awful, many abandoned. If you tell us more about what you want that will help narrow down the choices.
Is this for testing, or automation, or are you going to drive the mouse and button yourself and just want something to observe what is going on under the hood in the GUI?
>How do I get Python to detect other widgets?
On a machine, or in a browser? If in a machine, which platform: Linux/Windows (which)/Mac?
If in a browser, which browser (and major version)?
> But the return value for that function seems to be some ambiguous long number I can't decipher
Using longs as resource handles is par for the course, although good GUI drivers also work with string/regex matching on window and button names.
> plus it only works in its own application.
What do you mean, and what are you expecting it to return you? You should be able to look up that GUI object and access its title. Look for a GUI driver that works with window and button names.
Here is one list, read it through and see what sounds useful. I have used AutoIt under Win32, it's great, widely-used and actively-maintained; it can be called from Python (via subprocess).
Here are comparisons by the author of PyWinAuto on his and similar tools. Give a read to his criticisms of its structure from 2010. If none of these is what you want, at least you now have the vocabulary to tell us what would be...

Categories

Resources