Draygoes Posted January 22, 2018 Share Posted January 22, 2018 I am so lost on this that I don't actually know where to start, so I do not have any code at this time. I want to be able to save an image captured through PrtScn to a file. Obviously, I need to automate that task. If anyone could figure this out and perhaps turn it into a function (If you do not wish to make a function out of it, I understand. That part I can do on my own anyway.), you would make my day. I have never actually been to a point where I was this kind of lost before, so please bare with me. Thank you all for your time. Spoiler "If a vegetarian eats vegetables,What the heck does a humanitarian eat?" "I hear voices in my head, but I ignore them and continue on killing." "You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring." An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist. Link to comment Share on other sites More sharing options...
UEZ Posted January 22, 2018 Share Posted January 22, 2018 Something like this here? expandcollapse popup#include <GDIPlus.au3> #include <Clipboard.au3> _GDIPlus_Startup() Global $hMemoryBMP = 0, $hBmp, $hWnd = WinGetHandle(AutoItWinGetTitle()) HotKeySet("+!q", "_Exit") ;Shift+Alt+q to exit _ClipBoard_Open($hWnd) _ClipBoard_Empty() _ClipBoard_Close() Sleep(100) Do If Not _ClipBoard_Open($hWnd) Then ConsoleWrite("Could not open clipboard!!!" & @CRLF) _Exit() EndIf $hMemoryBMP = _ClipBoard_GetDataEx($CF_BITMAP) If $hMemoryBMP Then $sFile = FileSaveDialog("Save Bitmap from Clipboard", "", "Images(*.jpg;*.bmp;*.png;*.gif)") If @error Then ContinueLoop $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hMemoryBMP) If _GDIPlus_ImageSaveToFile($hBmp, $sFile) Then ConsoleWrite("Image was saved properly!" & @CRLF) Else ConsoleWrite("Image could not be saved!" & @CRLF) Endif _GDIPlus_ImageDispose($hBmp) _ClipBoard_Empty() $hMemoryBMP = 0 EndIf _ClipBoard_Close() Until False * Sleep(500) Func _Exit() ConsoleWrite("Finished!" & @CRLF) _GDIPlus_Shutdown() Exit EndFunc Press Shift+Alt+q to exit. aRandomGuy, Draygoes and Burgaud 3 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Draygoes Posted January 22, 2018 Author Share Posted January 22, 2018 (edited) Yes, exactly like that there. But there is one problem. I prtscn'd and then ran the script. It hung. I did not get the dialog or anything else. Not even through the console. It is simply stuck. Had to exit it through the tray icon. Thank you man, you are a life saver. 3 hours ago, UEZ said: Something like this here? expandcollapse popup#include <GDIPlus.au3> #include <Clipboard.au3> _GDIPlus_Startup() Global $hMemoryBMP = 0, $hBmp, $hWnd = WinGetHandle(AutoItWinGetTitle()) HotKeySet("+!q", "_Exit") ;Shift+Alt+q to exit _ClipBoard_Open($hWnd) _ClipBoard_Empty() _ClipBoard_Close() Sleep(100) Do If Not _ClipBoard_Open($hWnd) Then ConsoleWrite("Could not open clipboard!!!" & @CRLF) _Exit() EndIf $hMemoryBMP = _ClipBoard_GetDataEx($CF_BITMAP) If $hMemoryBMP Then $sFile = FileSaveDialog("Save Bitmap from Clipboard", "", "Images(*.jpg;*.bmp;*.png;*.gif)") If @error Then ContinueLoop $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hMemoryBMP) If _GDIPlus_ImageSaveToFile($hBmp, $sFile) Then ConsoleWrite("Image was saved properly!" & @CRLF) Else ConsoleWrite("Image could not be saved!" & @CRLF) Endif _GDIPlus_ImageDispose($hBmp) _ClipBoard_Empty() $hMemoryBMP = 0 EndIf _ClipBoard_Close() Until False * Sleep(500) Func _Exit() ConsoleWrite("Finished!" & @CRLF) _GDIPlus_Shutdown() Exit EndFunc Press Shift+Alt+q to exit. Yes, exactly like that there. But there is one problem. I prtscn'd and then ran the script. It hung. I did not get the dialog or anything else. Not even through the console. It is simply stuck. Had to exit it through the tray icon. Thank you man, you are a life saver. EDIT: My dumb butt placed my reply inside of your quote. EDIT TWice I ran it for a min, and it finally exited with an error. >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Draygoes\Desktop\savefileengine.au3" Could not open clipboard!!! Finished! >Exit code: 0 Time: 183 Ok, so I never learned the GDI+ Library. So this is very new territory for me. I WILL learn it later on, but I do wish to finish the project that I am currently working on in the next few hours. Edited January 22, 2018 by Draygoes Spoiler "If a vegetarian eats vegetables,What the heck does a humanitarian eat?" "I hear voices in my head, but I ignore them and continue on killing." "You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring." An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist. Link to comment Share on other sites More sharing options...
Draygoes Posted January 22, 2018 Author Share Posted January 22, 2018 Reading your code, it looks like Print Screen is not saving to clipboard. But it is, as I can copy to any image editor. Spoiler "If a vegetarian eats vegetables,What the heck does a humanitarian eat?" "I hear voices in my head, but I ignore them and continue on killing." "You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring." An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist. Link to comment Share on other sites More sharing options...
UEZ Posted January 22, 2018 Share Posted January 22, 2018 When I press the print screen key it popups with the save dialog window. Try with $hWnd = 0 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
mikell Posted January 22, 2018 Share Posted January 22, 2018 @UEZ Hello Is your code very different - I mean the concept - from this one here ? Link to comment Share on other sites More sharing options...
UEZ Posted January 22, 2018 Share Posted January 22, 2018 @mikell I don't think so. I had this function also in Windows Screenshooter implemented which can monitor the clipboard but in the core it is the same. To be honest I forgot your post and I posted nothing new or special. Reason is probably that I'm concentrated in coding with FB. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
x_bennY Posted January 22, 2018 Share Posted January 22, 2018 @UEZ the GDI master! hahaha nice code Link to comment Share on other sites More sharing options...
Draygoes Posted January 23, 2018 Author Share Posted January 23, 2018 (edited) 9 hours ago, UEZ said: When I press the print screen key it popups with the save dialog window. Try with $hWnd = 0 Would you be willing to elaborate? I cannot see where that would fit in your code... EDIT: I just tried to run that same code on my laptop and got the same result. It does not work. Edited January 23, 2018 by Draygoes Spoiler "If a vegetarian eats vegetables,What the heck does a humanitarian eat?" "I hear voices in my head, but I ignore them and continue on killing." "You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring." An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist. Link to comment Share on other sites More sharing options...
Draygoes Posted January 23, 2018 Author Share Posted January 23, 2018 What I ultimately needed to do was save a screenshot to a specified folder. Being able to save any image from the clipboard to file would simply be a bonus. I found a program that takes care of the main need just fine. Its called Nircmd, and taking a screen shot is one of many things it can do. Thank you all for your help and your time. All the helpful people here is one of the reasons that I love this place. I want to leave this open because a workable solution to the OP would still be helpful. Spoiler "If a vegetarian eats vegetables,What the heck does a humanitarian eat?" "I hear voices in my head, but I ignore them and continue on killing." "You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring." An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist. Link to comment Share on other sites More sharing options...
junkew Posted January 24, 2018 Share Posted January 24, 2018 (edited) Why get and save from the clipboard? I feel this function does it much better in one go https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_SaveImage.htm and maybe translate this vba Excel to AutoIt http://www.ms-office-forum.net/forum/sitemap/index.php?t-335549.html Edited January 24, 2018 by junkew Draygoes 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
careca Posted January 25, 2018 Share Posted January 25, 2018 (edited) Yeah, do you really need to retrieve a screenshot? Can't you just use a piece of code that screenshots and saves the file to where you want? Just take this as an example of an active window screenshot #include <ScreenCapture.au3> _ScreenCapture_SetJPGQuality(100);max image quality $scrFile = @DesktopDir & "\screenshot - " & @MDAY & @MON & @YEAR & '-' & @HOUR &@MIN& @SEC & ".jpg" _ScreenCapture_CaptureWnd($scrFile, "[ACTIVE]", -1, -1, -1, -1, 0) Edited January 25, 2018 by careca Draygoes 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Draygoes Posted January 26, 2018 Author Share Posted January 26, 2018 On 1/24/2018 at 10:34 AM, junkew said: Why get and save from the clipboard? I feel this function does it much better in one go https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_SaveImage.htm and maybe translate this vba Excel to AutoIt http://www.ms-office-forum.net/forum/sitemap/index.php?t-335549.html 2 hours ago, careca said: Yeah, do you really need to retrieve a screenshot? Can't you just use a piece of code that screenshots and saves the file to where you want? Just take this as an example of an active window screenshot #include <ScreenCapture.au3> _ScreenCapture_SetJPGQuality(100);max image quality $scrFile = @DesktopDir & "\screenshot - " & @MDAY & @MON & @YEAR & '-' & @HOUR &@MIN& @SEC & ".jpg" _ScreenCapture_CaptureWnd($scrFile, "[ACTIVE]", -1, -1, -1, -1, 0) I, had no idea these where a thing! Thanks all!!! Spoiler "If a vegetarian eats vegetables,What the heck does a humanitarian eat?" "I hear voices in my head, but I ignore them and continue on killing." "You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring." An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist. Link to comment Share on other sites More sharing options...
junkew Posted January 26, 2018 Share Posted January 26, 2018 ok combine it with a hotkey ctrl+q for example and increment the number of your screenshot to save somewhere or use timestamp https://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm Use this stuff frequently myself to just make a quick sequence of screenshots to explain the flow to people FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now