[50 counts] Key transmission using Python for Windows

Introduction

I tried to automate the task of entering numbers from 1 to 50 into a web browser with Python.

environment

Made with Python3 on Windows. The required libraries are included in the Anaconda distribution from the beginning, but if it is installed from the Python official website and win32com.client cannot be imported, install the required libraries with the following command.

> pip install pypiwin32

script

sr50.py


import time
import win32com.client

def main():
    wshell = win32com.client.Dispatch('WScript.Shell')
    #Make the launched Firefox browser the active window
    wshell.AppActivate('Firefox')
    #for test
    #shell.AppActivate('Notepad')
    #Wait 1 second
    time.sleep(1)

    #50 loops
    for cnt in range(50):
        #Shift the counter value by 1
        cnt+=1
        #Wait 2 seconds for continuous input measures
        time.sleep(2)
        #For confirmation
        print(cnt)
        #50 count key output
        wshell.SendKeys(str(cnt) + '\n')


if __name__ == '__main__':
    main()

How to use

Open the SHOWROOM screen in your browser in advance and move the cursor to the text box. Then run the Python script below to start counting 50.

The browser is made for Firefox, but I think that it can be supported by other browsers by changing the argument of AppActivate.

Reference site

SHOWROOM What is SHOWROOM's "count"? Summary of the meaning and effect of 50 counts @IT Introduction to Windows Script Host for Windows Administrators

Recommended Posts

[50 counts] Key transmission using Python for Windows
Notes for using OpenCV on Windows10 Python 3.8.3.
Install Python (for Windows)
[Heroku] Memo for deploying Python apps using Heroku on Windows [Python]
Install dlib for Python (Windows)
[TouchDesigner] Tips for for statements using python
[Python] Reasons for overriding using super ()
[Python] Multiplication table using for statement
Mouse operation using Windows API in Python
Python development environment for macOS using venv 2016
Python project environment construction procedure (for windows)
Using venv in Windows + Docker environment [Python]
"Python AI programming" starting from 0 for windows
[python, multiprocessing] Behavior for exceptions when using multiprocessing
[Python] [Windows] Serial communication in Python using DLL
Tips for using python + caffe with TSUBAME
Notes for using python (pydev) in eclipse
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
2016-10-30 else for Python3> for:
python [for myself]
vprof --I tried using the profiler for Python
Python on Windows
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
Notes on installing Python3 and using pip on Windows7
python windows environment
Python pandas: Search for DataFrame using regular expressions
Build procedure for TensorFlow 2.4.0 (Windows10, CUDA11.1.1, cuDNN 8.0.5, Python 3.8.6)
Python installation (Windows)
Start using Python
Get note information using Evernote SDK for Python 3
Refined search for Pokemon race values using Python
Image Processing with Python Environment Setup for Windows
GCP Key Management Service + Python for secret information management
Notes for using TensorFlow on Bash on Ubuntu on Windows
Let's make a module for Python using SWIG
Installing TensorFlow on Windows Easy for Python beginners
Scraping using Python
A real way for people using python 3.8.0-2 from windows to work with multibyte characters
Let's analyze Covid-19 (Corona) data using Python [For beginners]
Initial settings for using Python3.8 and pip on CentOS8
Searching for pixiv tags and saving illustrations using Python
Directory structure for test-driven development using pytest in python
Key input that does not wait for key input in Python
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
Summary of tools for operating Windows GUI with Python
U ^ 2-Net for detecting objects of interest (Windows10, Python3.6)
Explore Alibaba Cloud Function Compute for DevOps using Python 3.0
PIL with Python on Windows 8 (for Google App Engine)
Procedure for building a CDK environment on Windows (Python)
I built a Wheel for Windows using Github Actions
Memo for building a machine learning environment using Python
[Introduction to Python] How to write repetitive statements using for statements
For those who can't install Python on Windows XP
About Python for loops
Key input in Python
Operate Redmine using Python Redmine
Python basics ② for statement
Fibonacci sequence using Python
python windows environment construction
Data analysis using Python 0
Python installation method Windows