Make python automation in current window

I am trying to make a simple python script that can use the keyboard to write / execute commands.

Example: open Photoshop and do the following: "select all and delete, then save" (Ctrl + a, delete, control + s) every 1 second.

Example 2: open taskmanager (control + alt + del) using the N key to go to the N partition being processed and use the final task (alt + e) ​​every few minutes ...

Also, to create a function while the python script is running, if I press alt + f1 (for example), it executes (control + alt + del)

+8
python
source share
2 answers

To do this, you need to integrate with your own messaging interfaces. Sikuli is a good testing tool and therefore (as suggested by @juxhin) a reasonable candidate if you can limit yourself to Jython.

However, if you cannot live with it, you may need a different solution for Linux and Windows. For example:

  • Linux: Listening to global keyboard shortcuts in python on Linux
  • Windows: Install a global hotkey with Python 2.6 (note that some answers are not limited to 2.6)
+2
source share

You can try SikuliX . It is an education-based framework that can be used with Python (through Jython), Ruby (through JRuby), and Java (through the optional Java API).

It is very convenient to automate certain behaviors on your screen, for example, open Photoshop, click areas on the screen, or enter using the key. For example:

//Using Java API, however the idea is the same for Python Screen screen = new Screen() screen.type(new Pattern("some-image.png"), "keyboard"); 

In Python:

 def changed(event): print "something changed in ", event.region for ch in event.changes: ch.highlight() # highlight all changes sleep(1) for ch in event.changes: ch.highlight() # turn off the highlights 

with selectRegion ("select region to observe") as r: # any change in r exceeding 50 pixels will cause the changed function onChange (50, changed) to observe (background = True)

wait (30) # another way to observe for 30 seconds r.stopObserver ()

This is quite a bit of work, but it allows you to create very reliable scripts that perform the necessary actions. You can also pass console output back to your Python script through subprocess to change the behavior of scripts based on the environment.

Rest is limited by your imagination.

Note: not everything should be done with SikuliX, infact I would not recommend doing everything. Just certain things that may require specific behavior on your screen.

If you are strictly on Ubuntu, you can also watch Xpresser


Update

So, I worked with AutoIt and PyAutoIt and will sincerely think that they are suitable tools for what you want to achieve, as they can be very effective for certain applications.

0
source share

All Articles