win32 screen captures
Robin Becker
robin at jessikat.fsnet.co.uk
Fri Aug 10 04:28:16 EDT 2001
I saw earlier that someone had a sendkeys in python using wsh scripting
(via win32com). I would like to do screen capture, but there seems to be
an explicit ban on {PRTSC}.
Has anyone managed to use PIL and win32com to do screen captures?
Also the sendkeys command and control is un-robust. Is there a native
win32com way to do this and perhaps wait on the windows/events I
initiate before doing the capture?
import win32api
import win32com.client
def sendkeys(k,app,delay=100):
'''
Note You can't use SendKeys to send keystrokes to an application that is not designed to run in Microsoft Windows.
Sendkeys also can't send the PRINT SCREEN key {PRTSC} to any application.
'''
win32api.Sleep(delay)
return app.SendKeys(k)
if __name__=='__main__':
import sys
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("Acrobat")
sk = lambda k, app=shell,delay=100: sendkeys(k,app,delay=delay)
win32api.Sleep(500)
shell.AppActivate("Adobe Acrobat")
win32api.Sleep(500)
sk('%fo',delay=500)
sk(sys.argv[1]+'{ENTER}',delay=500)
sk('%{PRTSC}',delay=1000)
--
Robin Becker
More information about the Python-list
mailing list