0

I am a student and a novice in python. For a project I have to read and write to the Microsoft Office Word GUI using Python. I know it would be easier writing and reading directly to file with python- docx but it can't be helped. (A la programmers perspective not user perspective) The supervisor wants it that way.

I found following threads which aren't that helpful because I don't know C and how it connects to Ctype. Interact with other programs using Python Obtain Active window using Python

The typing and standard input part is easy and I have it nearly implemented. The problem is making the MSWord GUI the active window while pynput is running. I have no clue.

from pynput import keyboard
from pynput.keyboard import Controller, Key

def press_enter(start_number): # The event listener will be running in this block
    keyboardinput = Controller()
    with keyboard.Events() as events:
        for event in events:
            if event.key == keyboard.Key.esc:
                break
            elif event.key == keyboard.Key.enter:
                #doing some things when enter is typed
            else:
                print('Received event {}'.format(event))

Could somebody point me in the right direction which libraries and docs I have to read?

Al Lex
  • 11
  • 1
  • If you're going to use Python you can go with win32com to control the likes of MS Word. Have a search on "python win32com microsoft word". It only works if you're running Windows though. On Mac or Linux I don't believe there is a way to control the GUI/application. – scanny Oct 25 '21 at 15:54

0 Answers0