Are there any libraries for Python to simulate keyboard action? - python

The problem I have is that I have this Python script to launch a application. After the application is launched (the GUI is shown on screen), I want to make it de-activated. It can be done manually by activating another window, or minimizing this app, or pressing the Show Desktop key for WindowsXP.
So is there any way that I can do this by Python? Core or 3rd party library would be all ok.
Thanks!

Take a look at SendKeys. It is in the pypi, so you can install it via easy_install.

You can use pywin32 to send a minimize event.

I've used AutoIt (via it's COM interface) a lot of times

Related

Is there an easy way to use pyautogui?

I made a python program with pyautogui. I want to release this to my friends. But they seldom want to download python and pyautogui. I wanna know how to run this without downloading these programs. Or can you explain me an easier way to use pyautogui for my friends (without using pip).
You can create a standalone application so that they can run it on their device.
for Windows you can use Py2exe
for MacOs you can use Py2app

Equivalent of pywinauto library for debian

I'm looking for an equivalent Python library that will work when I run my script on Raspberry Pi. I'm under the impression that pywinauto only works on windows machine.
I want to control some inputs to a GUI launched by my script, using my script. Apart from pywinauto I have no idea how to do this. I thought about using command line to control the software directly, but if there is a simpler way I would really appreciate knowing about it.
Thanks for your time.
ATSPI is an Linux accessibility technology to obtain GUI text/rectangle properties programmatically. See how to find and run ATSPI registry daemon and how to enable ATSPI for the most popular types of GUI apps. Usually it's
$ /usr/libexec/at-spi-registryd &
There is a Python bindings for ATSPI. See this answer for details:
How to install pyatspi?
The pyatspi package has too many dependencies like pygobject etc. It also requires some compilation during installation steps. We think this is not user friendly so we decided to use libatspi.so directly (without any dependencies). This work status can be tracked here: https://github.com/pywinauto/pywinauto/pull/449
There is no exact deadline for pywinauto 0.7.0 with this feature (it's a hobby project), but I would say this summer sounds realistic.

Making python terminal user interface

I'm trying to make terminal user interface with python which I will use it as post installation script for min linux os. But I don't want to use ncurses or urwid because it feels like overkill. I'm looking more in whiptail or screen direction. But I don't know is it better to call ui terminal rendering from python subprocess or to use it with python bindings like pythondialog, here are the reasons for my doubts.
Is whiptail/screen available on every minimal linux image... subprocess should be better suited for my program.
pythondialog requires installation of python3-dialog package. Since I want to make a postinstallation program for linux min image I want to use dependencies as little as possible.
What would you suggest for my problem?
Maybe npyscreen is what you are looking for, but i havent tried it. It just installed for me in fresh 2.7 virtualenv with zero dependencies - EDIT: sorry no, it runs on top of ncurses.
I've had a similar notion about ncurses or urwid. You might want to try:
prompt toolkit - focus on UI, comes with tons of examples
asciimatics - handy for UI and animations, also with a bunch of helpful examples
Both have a responsive and active community.

Automate downloading a file in Firefox using Python

I'm researching about pywinauto and pywin32. I want to write a script to automate downloading a file in Firefox. When downloading a file in Firefox, it will show a popup to ask you to open or save the file, and you have to choose an option and follow steps. How can I locate controls (items) on this popup by using pywinauto or pywin32?
You should investigate selenium ide. You can use that and Python to automate much of firefox. The forums there should point you in the right direction. This downloading issue is a persistent one.
good luck!
pywinauto installation has an example (SaveFromFirefox.py) related to this:
http://pywinauto.googlecode.com/hg/pywinauto/docs/getting_started.html
You might check out Project SIKULI from MIT. With it you can write macros by taking screenshots. The project screenshots make the entire process look dead easy. It's Python-based, too, so it may be the write tool for the job.
Also, if you have control of the computer in question, you may be able to check the box in the download popup that says "Do this every time" (or whatever the exact wording is). Perhaps that will be enough to make the job simpler?
For latest Firefox version you can use pywinauto 0.5.x (just download and run python setup.py install or run pip install pywinauto). SaveFromFirefox.py was adapted for Win7.
Useful tips:
app.Dialog.PrintControlIdentifiers() will print all possible access names for the controls on a dialog.
SWAPY is a GUI helper for the controls hierarchy inspection and code generation for pywinauto.
app.Dialog.ControlName.WrapperObject(). ... will give you the most useful list of methods available for the control. In a production code the WrapperObject() call can be omitted.

Is there a way to make a Python console application flash in the taskbar in Windows?

Is there a way to make my Python console application's window flash in the Windows taskbar, to get a user's attention?
My script will be run exclusively in a relatively homogeneous Windows environment, so I don't care about detecting whether a particular API is present, or whether a solution is cross-platform or not (of course cross-platform is better for future reference... but I don't need it for this application).
This is the simplest solution I could come up with:
import ctypes
ctypes.windll.user32.FlashWindow(ctypes.windll.kernel32.GetConsoleWindow(), True )
Flashing the taskbar in Windows is accomplished using the FlashWindowEx API function (Python API help).
I haven't tried this myself, but it should be possible to call this function from Python using PyWin32 (Python for Windows extensions) that can either by installed manually or by installing ActivePython.

Categories

Resources