The program that is being written uses many of the operations under Windows to check out a lot of information. See the operation of the Clipboard, think of the previous want to do a small program, then did not do, and now just finished writing.
Function: Press the Printscreen key to carry out the time, the data is saved in the shearing board inside, very inconvenient. For example, when the game cut a moment of the picture, but you can not quit the game save pictures, not convenient multiple times. And I do not like to install a variety of software, so prepare to write this tool.
Idea: One is a custom shortcut key, save. Considering the possibility of various conflicts, the cancellation. Then use press Printscreen, and then read the picture data from the Clipboard and save it. The idea is to first listen to the keyboard button, when the Printscreen button, read the Clipboard content, and finally save the picture to the specified location.
1 listening keyboard keys: Find information from the Internet, install Pywin32,pyhook. Link: http://sourceforge.net/projects/pyhook/,http://sourceforge.net/projects/pywin32/. Tutorial: Http://sourceforge.net/apps/mediawiki/pyhook/index.php?title=PyHook_Tutorial.
2 Read the Clipboard contents, also need pywin32. Documents in: [Pythonpath]\lib\site-packages\pywin32.chm, Online: http://timgolden.me.uk/pywin32-docs/index.html
Several of the formats given in the document are not picture-saved data, Google search "standard Clipboard Formats", Link: http://msdn.microsoft.com/en-us/library/windows/ Desktop/ff729168%28v=vs.85%29.aspx, all the formats, mostly 1-17.
Fortunately, there is a function in the document: Getpriorityclipboardformat, which can be returned from the Clipboard in a format from an iterator. So the manual input was found, and y is sometimes 6,win32con. Cf_tiff, it will be 2. Of course, there is no need to know what to do with the return data directly.
Mainly used in:
Openclipboard,closeclipboard,getpriorityclipboardformat,getclipboarddata, these functional documents are introduced, mainly speaking CloseClipboard, official documents , do not call CloseClipboard after placing the object in the Clipboard.
3 Save Picture:
To find here can directly use the PIL module, directly solve the problem, the above is too tortuous t_t.
You can use Imagegrab.grab () to capture the screen directly, or use Imagegrab.grabclipboard () to get the image from the Clipboard.
Finally becomes, listens the key, presses the Printscreen, uses the PIL to save. T_t don't feel as good as setting shortcuts, so you should use less memory.