LoginSignup
4
5

More than 5 years have passed since last update.

【Python】アプリケーションを起動し、キーボード入力する

Posted at

使用場面

コマンドプロンプト系のアプリケーションを起動し、毎回同じ入力をして、出力を得ている操作を自動化します。

準備

pyautogui の モジュールをインストール

qiita.rb
> pip install pyautogui

実行例

メモ帳を開いて、文章を入力します。
同じ要領で、コマンドプロンプト系のアプリケーションを操作する想定です。
アプリケーション起動までの待ち時間を設定しています。

qiita.rb

import subprocess
import time
import pyautogui

subprocess.Popen('C:/Windows/notepad.exe')

time.sleep(1) #1秒ウエイト

pyautogui.typewrite('Hello World!')
pyautogui.typewrite(['enter'])

pyautogui.typewrite(['enter'])
pyautogui.typewrite('Hello World!')

time.sleep(1) #1秒ウエイト

print('end')


4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5