Electron microscopy
 
Automation of Mouse Movements and Clicks
(comparison among pyautogui, pygetwindow, pydirectinput, autoit, pynput, Quartz, platform, ctypes, uiautomation and Sikuli)
- Integrated Circuits -
- An Online Book -
Integrated Circuits                                                                                   http://www.globalsino.com/ICs/        


=================================================================================

 

Keyboard and mouse can be controlled by GUI (graphical user interface) automation. The programs used to directly control keyboard and mouse can be ultimate tools for automating tasks on a computer. These programs can control the applications by sending them virtual keystrokes and mouse clicks, similar to the actions someone is doing at the computer and interacting with the applications. Such technique is known as GUI automation. With such automation, the programs can do anything that a human user sitting at the computer can do with the keyboard and mouse. This GUI automation is similar to a programmed robotic arm, typing at keyboard, and move the mouse and track its position on the screen for us. This technique is especially useful for tasks that involve a lot of mindless clicking and keyboard typing with a high accuracy and high speed.

The pyautogui module has the functions for simulating mouse clicks and movements, scrolling the mouse wheel, and typing keyboard.

Table 4679. Mouse clicks.

Left click Right click Double click
Left click a specific position Right click a specific position Double click a specific position

Table 4679. move and (or) drag mouse.

Move mouse Scroll mouse Drag mouse

If the main stream libraries and tools are not working for automating mouse clicks and movements on the app, it suggests that the app has implemented strong security measures or restrictions that prevent standard Python libraries from interacting with it. In such cases, it becomes extremely challenging to automate mouse clicks and movements on the app using Python. You may need to explore alternative approaches or consider using specialized automation tools that are specifically designed to interact with difficult-to-control applications. In such cases, you can try the following solutions in sequence.

======================================================

Continuously clicks until Esc has been pressed: code:         
        Visit a webpage on an opened Chrome tab
    Output:    
        Visit a webpage on an opened Chrome tab

======================================================

pywinauto for automation. code:         
        Visit a webpage on an opened Chrome tab

======================================================

pygetwindow and pyautogui for automation. code:         
        Visit a webpage on an opened Chrome tab
     Output (Window below is brought to front):   
        Visit a webpage on an opened Chrome tab

======================================================

pydirectinput for automation. code:         
        Visit a webpage on an opened Chrome tab

======================================================

AAA: Mouse click and move with pynput. code:         
        Visit a webpage on an opened Chrome tab

======================================================

autoit for automation: autoit for automation: The `win_get_handle()` function is used to locate the application window by its title specified in `app_window_title`. code:         
        Visit a webpage on an opened Chrome tab
      Installation problem:  
        Visit a webpage on an opened Chrome tab

======================================================

Quartz for automation. code:         
        Visit a webpage on an opened Chrome tab
      pip install pyobjc-framework-Quartz, still has problem:  
        Visit a webpage on an opened Chrome tab

======================================================

Combination of platform and pyautogui for automation: The `platform` module is used to determine the current platform. Based on the current platform, you can add platform-specific code using `pyautogui` to perform mouse actions. However, the availability and functionality of platform-specific features in `pyautogui` may vary depending on the platform and the app you're trying to automate. It's important to ensure that you have the necessary permissions and legal rights to automate the target app. code:         
        Visit a webpage on an opened Chrome tab

======================================================

AAA: Some automation libraries involve using low-level operating system functions to simulate mouse events. One such library is `ctypes`, which allows you to access and call functions from shared libraries directly. Please note that this approach relies on low-level system functions and may have platform-specific dependencies. Additionally, it requires knowledge of the app's screen coordinates to accurately simulate mouse movements and clicks. code:         
        Visit a webpage on an opened Chrome tab

======================================================

AAA: Move and click on an application. code:         
        Visit a webpage on an opened Chrome tab

======================================================

uiautomation for automation: The `uiautomation` library relies on the Microsoft UI Automation framework, which means it may have dependencies on Windows and may not work on other operating systems. Additionally, using UI Automation can be more complex and requires a deeper understanding of the app's UI structure. code:         
        Visit a webpage on an opened Chrome tab
     Easy Timeout(10s):   
        Visit a webpage on an opened Chrome tab

======================================================

Sikuli for automation (needs an account for library installation). SikuliX, an open-source GUI automation tool that uses computer vision to identify and interact with elements on the screen. SikuliX allows you to write scripts using a combination of Python and a visual scripting language. However, SikuliX relies on image recognition and may have limitations in terms of accuracy and reliability. It's important to provide clear and distinct images for SikuliX to recognize and interact with. code:         
        Visit a webpage on an opened Chrome tab
    Problem due to incorrect installation:    
        Visit a webpage on an opened Chrome tab

==============================================

Sikuli again. code:         
        Visit a webpage on an opened Chrome tab

==============================================

 

 

 

=================================================================================