1

I would like to know if there is a way to type things with Python using the win32api module. For example, if I want to type in the phrase "Happy Pi Day" into Microsoft Word every three seconds, I would have something like import time

while 1:
    #types Happy Pi Day
    time.sleep(3)

However, I do not know what the command is for the "type" function.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
eddybob123
  • 121
  • 3

2 Answers2

1

Is using win32api module a hard requirement? If not, you can use this:

https://code.google.com/p/pywinauto/

Then its easy (more examples here...):

from pywinauto import application
app = application.Application.start("notepad.exe")
app.notepad.TypeKeys("%FX")
0

The type function is keyboard here is a link to help with that https://www.geeksforgeeks.org/keyboard-module-in-python/ and to have something typed repeatedly you have this code

import pyautogui

import time
 
time.sleep(10)
 
for line in open("auto file.txt", "r"):
 
    pyautogui.typewrite(line)
     
    pyautogui.press("enter")

here is a link https://www.askpython.com/python/examples/auto-type-text-using-python

Buzz
  • 1,102
  • 1
  • 9
  • 24
Supreme
  • 1
  • 2