I'm trying to send keystrokes to a PowerPoint slideshow in Python, in order to advance the slideshow automatically. I would like to send the VK_RIGHT
and VK_LEFT
messages.
I'm using win32gui.FindWindow
to find the Powerpoint window by its title, then try to send message to the window handle with:
win32api.SendMessage(windowhandle, win32con.WM_KEYDOWN, win32con.VK_RIGHT, 0))
While this works for other applications like Notepad, it doesn't seem to work on the main window. For Notepad it works actually on its child window, so I've tried with Powerpoint children windows:
win32gui.EnumChildWindows
and I cycle them to send the same message to every child window, but it doesn't seem to work either.
The LRESULT
of the win32api.SendMessage
is always 0 (it is 1 with the Notepad).
Any idea why this happens?
An alternative (and probably better) solution would be to use COM32, which happens to be included in win32api.
You can use this library for office for reference.
An Example to open up a powerpoint and view the next slide:
app = win32com.client.Dispatch("PowerPoint.Application")
objCOM = app.Presentations.Open(FileName="path_to_file", WithWindow=1)
objCOM.SlideShowWindow.View.Next()
Source: https://medium.com/@chasekidder/controlling-powerpoint-w-python-52f6f6bf3f2d
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.