Reputation: 11
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?
Upvotes: 1
Views: 264
Reputation: 141
You can send next/previous WM_COMMANDs to PowerPoint Viewer main window like this (in C++):
SendMessage (windowhandle, WM_COMMAND, 0x000106EF, 0); // next
SendMessage (windowhandle, WM_COMMAND, 0x000106EE, 0); // previous
I've done some investigation because I needed the same functionality recently and this works reliably for me. The commands are from the application's accelerator tables. There are many more, but nothing very useful.
Upvotes: 0
Reputation: 145
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
Upvotes: 0