#n:: Send +{PrintScreen} FileAppend, %ClipboardAll%, Screen.jpg returnbut when I open this file later, it's all black. Why is it so?
How to save a screen shot with AHK?
Started by
Benny-D
, Feb 17 2011 07:54 PM
10 replies to this topic
I use this short script to save a screen shot:
#1
-
Posted 17 February 2011 - 07:54 PM
Saving a Screen capture as a immage is more complicated than that. See Screen Capture with Transparent Windows and Mouse Cursor for an example.
#2
-
Posted 17 February 2011 - 08:21 PM
Thank you for this link, None! I am studying it at the moment.
#3
-
Posted 17 February 2011 - 08:49 PM
I Use This Code Here. I Forgot Where Which Topic I Got it From. But You Do Need IrfanView With It.
Just Edit Where IrfanView is Located and where you want to Place The ScreenShot.
PrintScreen:: ifnotexist, C:\Users\Administrator\Desktop ; Location Of The Saved Capture fileCreateDir, C:\Users\Administrator\Desktop ; Location Of The Saved Capture Run, "C:\Program Files (x86)\IrfanView\i_view32.exe" /capture=0 /convert=C:\Users\Administrator\Desktop\capture_$U(`%Y-`%m-`%d_`%H`%M`%S).png ; Location Of IrfanView.exe and Location Of The Saved Capture return ; /capture=0 takes a screenshot of the whole desktop ; /capture=1 takes a screenshot of the active window ; /capture=2 takes a screenshot of the client area of the active window
Just Edit Where IrfanView is Located and where you want to Place The ScreenShot.
#5
-
Posted 18 February 2011 - 09:41 AM
#6
-
Posted 18 February 2011 - 09:49 AM
No no no, the point of using Irfanview is to NOT write any AHK code at all. :? It already comes with its own screenshot utility, that's what I was saying.
Open Irfanview and go to Options -> Capture/Screenshot (or just press C while Irfanview is active). A GUI pops up in which you can select what parts of the screen to capture, what hotkey to trigger it with, what folder to save the files in, and what format, dimensions, compression and so forth to save them as. It's much more comprehensive than anything you'd knock together with AHK and, as I said, it works inside games. (Getting screenshot utilities to work inside games is apparently quite complicated because you need to intercept frames from the GPU etc etc).
Open Irfanview and go to Options -> Capture/Screenshot (or just press C while Irfanview is active). A GUI pops up in which you can select what parts of the screen to capture, what hotkey to trigger it with, what folder to save the files in, and what format, dimensions, compression and so forth to save them as. It's much more comprehensive than anything you'd knock together with AHK and, as I said, it works inside games. (Getting screenshot utilities to work inside games is apparently quite complicated because you need to intercept frames from the GPU etc etc).
#7
-
Posted 18 February 2011 - 11:25 AM
Well With a AHK Script Like this. There's No Point In Opening IrfanView At All. =)
#8
-
Posted 18 February 2011 - 11:35 AM
Well With a AHK Script Like this. There's No Point In Opening IrfanView At All. =)
I guess that only matters if you want to spend time writing code instead of taking screenshots.
#9
-
Posted 18 February 2011 - 11:42 AM
In the <!-- m -->http://www.autohotke...pic.php?t=49950<!-- m --> thread we made some progress to something like this. There are several versions.
My version requires some more files (like Splash.ahk for the splashimgs).
I am planning on releasing the script to non-AHK users too. [Edit] ScreenClip can now be copied to clipboard, saved as a file or uploaded. In all cases the results will go to your clipboard (as links in the latter cases). Hotkeys are Leftclick (copied), Shift+Click (saved) Ctrl+Click (upload).
AHK Library requirements: Splash.ahk <!-- m -->http://www.autohotke...php?t=33506<!-- m -->
Files: AHK or EXE (EXE will work even if you don't have the library).
If you do not already have a scriptstarter, I recommend AppStarter [DOWNLOAD .exe] which is the second script in the first post of <!-- m -->http://www.autohotke...pic.php?t=65119<!-- m -->.
And to prove the awesomeness of my script, I will count the time it takes to ScreenClip this sentence.
5 seconds, including typing out the <img>-tag and pasting the link.
My version requires some more files (like Splash.ahk for the splashimgs).
I am planning on releasing the script to non-AHK users too. [Edit] ScreenClip can now be copied to clipboard, saved as a file or uploaded. In all cases the results will go to your clipboard (as links in the latter cases). Hotkeys are Leftclick (copied), Shift+Click (saved) Ctrl+Click (upload).
AHK Library requirements: Splash.ahk <!-- m -->http://www.autohotke...php?t=33506<!-- m -->
Files: AHK or EXE (EXE will work even if you don't have the library).
If you do not already have a scriptstarter, I recommend AppStarter [DOWNLOAD .exe] which is the second script in the first post of <!-- m -->http://www.autohotke...pic.php?t=65119<!-- m -->.
; Script working name: ScreenClipping (to ImageShack) ; Language: English ; Platform: Windows 7 ; Version author: Sumon (find me at AHK forums, www.autohotkey.com/forum) ; Original author(s): Learning one, Zonanic: See http://www.autohotkey.com/forum/viewtopic.php?t=49950 thread ;**************************** ; Script Function: Upon holding a hotkey (Leftclick), drag the mouse to capture a picture which is copied to your clipboard. ; Upon holding (Ctrl+click), upload picture to imageshack and get the link in your clipboard. The picture will also be saved in the PrintScreen folder, and the link in Data\ScreenClippingUploadedIMGs.txt ; Upon holding (Shift+click), save the image as a file. ;**************************** ; AHK Library requirements: Splash.ahk (http://www.autohotkey.com/forum/viewtopic.php?t=18040), httpQuery.ahk (http://www.autohotkey.com/forum/viewtopic.php?t=33506) #SingleInstance force SetBatchLines, 10ms FileInstall, data/screenclipping_help.txt, data/screenclipping_help.txt IfNotExist, PrintScreen { FileCreateDir, PrintScreen } /* If there're hotkeys here: Commentating out the hotkey, since I launch it from another script - NOTE TO SELF: Reenable (+ the "ExitApp") before posting on AHK forums */ ; ======== Hotkeys ======== Hotkey, LButton, CopyClip Hotkey, ^LButton, ImageshackClip Hotkey, +LButton, ImageSaveClip Hotkey, LButton, Off Hotkey, ^LButton, Off Hotkey, +LButton, Off Hotkey, LButton, On ; These will be disabled again once you have clicked-and-dragged Hotkey, ^Lbutton, On Hotkey, +LButton, On Splash_On("Click and drag to copy the area to your clipboard.`nShift-click and drag to create a file`nCtrl+click and drag to create a file and upload it to Imageshack automatically.") return ;===ScreenClipping LEFT ("Copy to clipboard") ========================================================================= CopyClip: /* If (FileExist("screen.bmp")) FileRecycle, screen.bmp FileAppend,, screen.bmp */ Splash_Off() ; We don't wanna capture any splashtext CoordMode, Mouse ,Screen MouseGetPos, MX, MY Gui, +AlwaysOnTop -caption +Border +ToolWindow +LastFound WinSet, Transparent, 80 Gui, Color, lime While, (GetKeyState("LButton", "p")) { MouseGetPos, MXend, MYend Send {control up} w := abs(MX - MXend) h := abs(MY - MYend) If ( MX < MXend ) X := MX Else X := MXend If ( MY < MYend ) Y := MY Else Y := MYend Gui, Show, x%X% y%Y% w%w% h%h% Sleep, 10 } Hotkey, Lbutton, Off Hotkey, ^LButton, Off Hotkey, +Lbutton MouseGetPos, MXend, MYend Gui, Destroy If ( MX > MXend ) { temp := MX MX := MXend MXend := temp } If ( MY > MYend ) { temp := MY MY := MYend MYend := temp } Area = %MX%, %MY%, %MXend%, %MYend% Sleep, 100 ; if omitted, GUI sometimes stays in picture CaptureScreenLeft(Area) ; Saves selected area without cursor in Clipboard. Splash_On("Copied to clipboard") ; FOR LATER - gonna insert a preview here Gosub, Exit Return ;===Hotkeys CTRL+CLICK (Copy to Imageshack, get link) ========================================================= ImageSaveClip: ImageSaveClip = True ImageshackClip: Splash_Off() ; We don't wanna capture any Splashtext CoordMode, Mouse ,Screen MouseGetPos, MX, MY Gui, +AlwaysOnTop -caption +Border +ToolWindow +LastFound WinSet, Transparent, 80 Gui, Color, purple While, (GetKeyState("LButton", "p")) { MouseGetPos, MXend, MYend Send {control up} w := abs(MX - MXend) h := abs(MY - MYend) If ( MX < MXend ) X := MX Else X := MXend If ( MY < MYend ) Y := MY Else Y := MYend Gui, Show, x%X% y%Y% w%w% h%h% Sleep, 10 } Hotkey, Lbutton, Off Hotkey, ^LButton, Off Hotkey, +LButton, Off MouseGetPos, MXend, MYend Gui, Destroy If ( MX > MXend ) { temp := MX MX := MXend MXend := temp } If ( MY > MYend ) { temp := MY MY := MYend MYend := temp } Area = %MX%, %MY%, %MXend%, %MYend% Sleep, 100 ; if omitted, GUI sometimes stays in picture CaptureScreen(Area) ; Saves selected area without cursor in Clipboard /* * Create folder. */ IfNotExist, PrintScreen { FileCreateDir, PrintScreen } /* * Reset counter. */ countLoop := 1 /* * Repeat until we have unused name for file. */ loopFileName: /* * Reset string. */ countLoopString := countLoop /* * Add leading zeroes to string. */ loopStringAddZeroes: if (StrLen(countLoopString) < 4) { countLoopString := "0" countLoopString Goto, loopStringAddZeroes } /* * Form the name of new file. */ newFileName := "PrintScreen\img_" countLoopString ".jpg" /* * Check if file name is taken. */ IfExist, % newFileName { countLoop++ Goto, loopFileName } /* * Capture screenshot. */ CaptureScreen(Area, False, newFileName, 100) If (ImageSaveClip = "True") ; If we just wanted to save an image, we are done now :) { Splash_On("DONE! File saved as " . newFileName) Slash = \ ClipBoard:= A_ScriptDir Slash newFileName Gosub, Exit } SplashImage, %NewFileName%, b, CAPTURED! - uploading...,, %NewFileName% ; START OF UPLOAD, Upload function from AHK forums -> HTTPQuery, @ http://www.autohotkey.com/forum/viewtopic.php?t=33506, modified by author Sumon image = %NewfileName% FileGetSize,size,%image% SplitPath,image,OFN FileRead,img,%image% VarSetCapacity(placeholder,size,32) boundary := makeProperBoundary() post:="--" boundary "`ncontent-disposition: form-data; name=""MAX_FILE_SIZE""`n`n" . "1048576`n--" boundary "`ncontent-disposition: form-data; name=""xml""`n`nyes`n--" . boundary "`ncontent-disposition: form-data; name=""fileupload""; filename=""" . ofn """`nContent-type: " MimeType(img) "`nContent-Transfer-Encoding: binary`n`n" . placeholder "`n--" boundary "--" headers:="Content-type: multipart/form-data, boundary=" boundary "`nContent-Length: " strlen(post) DllCall("RtlMoveMemory","uInt",(offset:=&post+strlen(post)-strlen(Boundary)-size-5) ,"uInt",&img,"uInt",size) size := httpQuery(result:="","http://www.imageshack.us/index.php",post,headers) VarSetCapacity(result,-1) ; Gui,Add,Edit,w800 h600, % result ; Gui,Show StringGetPos, LinkPos, Result, <image_link> StringGetPos, LinkPosEnd, Result, </image_link> LinkLength := (LinkPosEnd-LinkPos-12) StringMid, LinkText, Result, LinkPos+13, %LinkLength% ; MsgBox, RESULT picture is in %LinkText% ClipBoard = %LinkText% FileAppend, `n%Linktext%, Data/ScreenClippingUploadedIMGs.txt ; GuiClose: ; GuiEscape: ; ExitApp makeProperBoundary(){ Loop,26 n .= chr(64+a_index) n .= "0123456789" Loop,% StrLen(A_Now) { Random,rnd,1,% StrLen(n) Random,UL,0,1 b .= RegExReplace(SubStr(n,rnd,1),".$","$" (round(UL)? "U":"L") "0") } Return b } MimeType(ByRef Binary) { MimeTypes:="424d image/bmp|4749463 image/gif|ffd8ffe image/jpeg|89504e4 image/png|4657530" . " application/x-shockwave-flash|49492a0 image/tiff" @:="0123456789abcdef" Loop,8 hex .= substr(@,(*(a:=&Binary-1+a_index)>>4)+1,1) substr(@,((*a)&15)+1,1) Loop,Parse,MimeTypes,| if ((substr(hex,1,strlen(n:=RegExReplace(A_Loopfield,"\s.*"))))=n) Mime := RegExReplace(A_LoopField,".*?\s") Return (Mime!="") ? Mime : "application/octet-stream" } ; START OF "Include" part (HttpQuery) ; Requires httpQuery to be in your standard library OR to be included ; httpQuery-0-3-5.ahk httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="") { ; v0.3.5 (w) Sep, 8 2008 by Heresy & derRaphael / zLib-Style release ; updates Aug, 28 2008 ; currently the verbs showHeader, storeHeader, and updateSize are supported in httpQueryOps ; in case u need a different UserAgent, Proxy, ProxyByPass, Referrer, and AcceptType just ; specify them as global variables - mind the varname for referrer is httpQueryReferer [sic]. ; Also if any special dwFlags are needed such as INTERNET_FLAG_NO_AUTO_REDIRECT or cache ; handling this might be set using the httpQueryDwFlags variable as global global httpQueryOps, httpAgent, httpProxy, httpProxyByPass, httpQueryReferer, httpQueryAcceptType , httpQueryDwFlags ; Get any missing default Values defaultOps = (LTrim Join| httpAgent=AutoHotkeyScript|httpProxy=0|httpProxyByPass=0|INTERNET_FLAG_SECURE=0x00800000 SECURITY_FLAG_IGNORE_UNKNOWN_CA=0x00000100|SECURITY_FLAG_IGNORE_CERT_CN_INVALID=0x00001000 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID=0x00002000|SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE=0x00000200 INTERNET_OPEN_TYPE_PROXY=3|INTERNET_OPEN_TYPE_DIRECT=1|INTERNET_SERVICE_HTTP=3 ) Loop,Parse,defaultOps,| { RegExMatch(A_LoopField,"(?P<Option>[^=]+)=(?P<Default>.*)",http) if StrLen(%httpOption%)=0 %httpOption% := httpDefault } ; Load Library hModule := DllCall("LoadLibrary", "Str", "WinINet.Dll") ; SetUpStructures for URL_COMPONENTS / needed for InternetCrackURL ; http://msdn.microsoft.com/en-us/library/aa385420(VS.85).aspx offset_name_length:= "4-lpszScheme-255|16-lpszHostName-1024|28-lpszUserName-1024|" . "36-lpszPassword-1024|44-lpszUrlPath-1024|52-lpszExtrainfo-1024" VarSetCapacity(URL_COMPONENTS,60,0) ; Struc Size ; Scheme Size ; Max Port Number NumPut(60,URL_COMPONENTS,0), NumPut(255,URL_COMPONENTS,12), NumPut(0xffff,URL_COMPONENTS,24) Loop,Parse,offset_name_length,| { RegExMatch(A_LoopField,"(?P<Offset>\d+)-(?P<Name>[a-zA-Z]+)-(?P<Size>\d+)",iCU_) VarSetCapacity(%iCU_Name%,iCU_Size,0) NumPut(&%iCU_Name%,URL_COMPONENTS,iCU_Offset) NumPut(iCU_Size,URL_COMPONENTS,iCU_Offset+4) } ; Split the given URL; extract scheme, user, pass, authotity (host), port, path, and query (extrainfo) ; http://msdn.microsoft.com/en-us/library/aa384376(VS.85).aspx DllCall("WinINet\InternetCrackUrlA","Str",lpszUrl,"uInt",StrLen(lpszUrl),"uInt",0,"uInt",&URL_COMPONENTS) ; Update variables to retrieve results Loop,Parse,offset_name_length,| { RegExMatch(A_LoopField,"-(?P<Name>[a-zA-Z]+)-",iCU_) VarSetCapacity(%iCU_Name%,-1) } nPort:=NumGet(URL_COMPONENTS,24,"uInt") ; Import any set dwFlags dwFlags := httpQueryDwFlags ; For some reasons using a selfsigned https certificates doesnt work ; such as an own webmin service - even though every security is turned off ; https with valid certificates works when if (lpszScheme = "https") dwFlags |= (INTERNET_FLAG_SECURE|SECURITY_FLAG_IGNORE_CERT_CN_INVALID |SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE) ; Check for Header and drop exception if unknown or invalid URL if (lpszScheme="unknown") { Result := "ERR: No Valid URL supplied." Return StrLen(Result) } ; Initialise httpQuery's use of the WinINet functions. ; http://msdn.microsoft.com/en-us/library/aa385096(VS.85).aspx hInternet := DllCall("WinINet\InternetOpenA" ,"Str",httpAgent,"UInt" ,(httpProxy != 0 ? INTERNET_OPEN_TYPE_PROXY : INTERNET_OPEN_TYPE_DIRECT ) ,"Str",httpProxy,"Str",httpProxyBypass,"Uint",0) ; Open HTTP session for the given URL ; http://msdn.microsoft.com/en-us/library/aa384363(VS.85).aspx hConnect := DllCall("WinINet\InternetConnectA" ,"uInt",hInternet,"Str",lpszHostname, "Int",nPort ,"Str",lpszUserName, "Str",lpszPassword,"uInt",INTERNET_SERVICE_HTTP ,"uInt",0,"uInt*",0) ; Do we POST? If so, check for header handling and set default if (Strlen(POSTDATA)>0) { HTTPVerb:="POST" if StrLen(Headers)=0 Headers:="Content-Type: application/x-www-form-urlencoded" } else ; otherwise mode must be GET - no header defaults needed HTTPVerb:="GET" ; Form the request with proper HTTP protocol version and create the request handle ; http://msdn.microsoft.com/en-us/library/aa384233(VS.85).aspx hRequest := DllCall("WinINet\HttpOpenRequestA" ,"uInt",hConnect,"Str",HTTPVerb,"Str",lpszUrlPath . lpszExtrainfo ,"Str",ProVer := "HTTP/1.1", "Str",httpQueryReferer,"Str",httpQueryAcceptTypes ,"uInt",dwFlags,"uInt",Context:=0 ) ; Send the specified request to the server ; http://msdn.microsoft.com/en-us/library/aa384247(VS.85).aspx sRequest := DllCall("WinINet\HttpSendRequestA" , "uInt",hRequest,"Str",Headers, "uInt",Strlen(Headers) , "Str",POSTData,"uInt",Strlen(POSTData)) VarSetCapacity(header, 2048, 0) ; max 2K header data for httpResponseHeader VarSetCapacity(header_len, 4, 0) ; Check for returned server response-header (works only _after_ request been sent) ; http://msdn.microsoft.com/en-us/library/aa384238.aspx Loop, 5 if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest ,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1) break If (headerRequest=1) { VarSetCapacity(res,headerLength:=NumGet(header_len),32) DllCall("RtlMoveMemory","uInt",&res,"uInt",&header,"uInt",headerLength) Loop,% headerLength if (*(&res-1+a_index)=0) ; Change binary zero to linefeed NumPut(Asc("`n"),res,a_index-1,"uChar") VarSetCapacity(res,-1) } else res := "timeout" ; Get 1st Line of Full Response Loop,Parse,res,`n,`r { RetValue := A_LoopField break } ; No Connection established - drop exception If (RetValue="timeout") { html := "Error: timeout" return -1 } ; Strip protocol version from return value RetValue := RegExReplace(RetValue,"HTTP/1\.[01]\s+") ; List taken from http://en.wikipedia.org/wiki/List_of_HTTP_status_codes HttpRetCodes := "100=Continue|101=Switching Protocols|102=Processing (WebDAV) (RFC 2518)|" . "200=OK|201=Created|202=Accepted|203=Non-Authoritative Information|204=No" . " Content|205=Reset Content|206=Partial Content|207=Multi-Status (WebDAV)" . "|300=Multiple Choices|301=Moved Permanently|302=Found|303=See Other|304=" . "Not Modified|305=Use Proxy|306=Switch Proxy|307=Temporary Redirect|400=B" . "ad Request|401=Unauthorized|402=Payment Required|403=Forbidden|404=Not F" . "ound|405=Method Not Allowed|406=Not Acceptable|407=Proxy Authentication " . "Required|408=Request Timeout|409=Conflict|410=Gone|411=Length Required|4" . "12=Precondition Failed|413=Request Entity Too Large|414=Request-URI Too " . "Long|415=Unsupported Media Type|416=Requested Range Not Satisfiable|417=" . "Expectation Failed|418=I'm a teapot (RFC 2324)|422=Unprocessable Entity " . "(WebDAV) (RFC 4918)|423=Locked (WebDAV) (RFC 4918)|424=Failed Dependency" . " (WebDAV) (RFC 4918)|425=Unordered Collection (RFC 3648)|426=Upgrade Req" . "uired (RFC 2817)|449=Retry With|500=Internal Server Error|501=Not Implem" . "ented|502=Bad Gateway|503=Service Unavailable|504=Gateway Timeout|505=HT" . "TP Version Not Supported|506=Variant Also Negotiates (RFC 2295)|507=Insu" . "fficient Storage (WebDAV) (RFC 4918)|509=Bandwidth Limit Exceeded|510=No" . "t Extended (RFC 2774)" ; Gather numeric response value RetValue := SubStr(RetValue,1,3) ; Parse through return codes and set according informations Loop,Parse,HttpRetCodes,| { HttpReturnCode := SubStr(A_LoopField,1,3) ; Numeric return value see above HttpReturnMsg := SubStr(A_LoopField,5) ; link for additional information if (RetValue=HttpReturnCode) { RetMsg := HttpReturnMsg break } } ; Global HttpQueryOps handling if strlen(HTTPQueryOps)>0 { ; Show full Header response (usefull for debugging) if (instr(HTTPQueryOps,"showHeader")) MsgBox % res ; Save the full Header response in a global Variable if (instr(HTTPQueryOps,"storeHeader")) global HttpQueryHeader := res ; Check for size updates to export to a global Var if (instr(HTTPQueryOps,"updateSize")) { Loop,Parse,res,`n If RegExMatch(A_LoopField,"Content-Length:\s+?(?P<Size>\d+)",full) { global HttpQueryFullSize := fullSize break } if (fullSize+0=0) HttpQueryFullSize := "size unavailable" } } ; Check for valid codes and drop exception if suspicious if !(InStr("100 200 201 202 302",RetValue)) { Result := RetValue " " RetMsg return StrLen(Result) } VarSetCapacity(BytesRead,4,0) fsize := 0 Loop ; the receiver loop - rewritten in the need to enable { ; support for larger file downloads bc := A_Index VarSetCapacity(buffer%bc%,1024,0) ; setup new chunk for this receive round ReadFile := DllCall("wininet\InternetReadFile" ,"uInt",hRequest,"uInt",&buffer%bc%,"uInt",1024,"uInt",&BytesRead) ReadBytes := NumGet(BytesRead) ; how many bytes were received? If ((ReadFile!=0)&&(!ReadBytes)) ; we have had no error yet and received no more bytes break ; we must be done! so lets break the receiver loop Else { fsize += ReadBytes ; sum up all chunk sizes for correct return size sizeArray .= ReadBytes "|" } if (instr(HTTPQueryOps,"updateSize")) Global HttpQueryCurrentSize := fsize } sizeArray := SubStr(sizeArray,1,-1) ; trim last PipeChar VarSetCapacity(result,fSize+1,0) ; reconstruct the result from above generated chunkblocks Dest := &result ; to a our ByRef result variable Loop,Parse,SizeArray,| DllCall("RtlMoveMemory","uInt",Dest,"uInt",&buffer%A_Index%,"uInt",A_LoopField) , Dest += A_LoopField DllCall("WinINet\InternetCloseHandle", "uInt", hRequest) ; close all opened DllCall("WinINet\InternetCloseHandle", "uInt", hInternet) DllCall("WinINet\InternetCloseHandle", "uInt", hConnect) DllCall("FreeLibrary", "UInt", hModule) ; unload the library return fSize ; return the size - strings need update via VarSetCapacity(res,-1) } ; END OF "Include" part ; END OF UPLOAD SplashImage, Off ; HEY! This actually means that you ARE done uploading! :) Splash_On("DONE! Link is in your clipboard.`n" . LinkText) GoSub, Exit return ; === Extra subroutines ====================== SplashOff2000: SetTimer, SplashOffNow, -2000 Return SplashOff4000: SetTimer, SplashOffNow, -4000 Return SplashOffNow: SplashImage, Off SplashTextOff return ; Change if you want to have it running constantly - esc is a common key Exit: Sleep 1500 ExitApp return ;===Functions========================================================================== CaptureScreenLeft(aRect) { StringSplit, rt, aRect, `,, %A_Space%%A_Tab% LnL := rt1 ; Since CaptureScreen (for fileupload) used s LnT := rt2 LnW := rt3 - rt1 LnH := rt4 - rt2 LznW := rt5 LznH := rt6 LmDC := DllCall("CreateCompatibleDC", "Uint", 0) LhBM := CreateDIBSectionLeft(LmDC, LnW, LnH) LoBM := DllCall("SelectObject", "Uint", LmDC, "Uint", LhBM) LhDC := DllCall("GetDC", "Uint", 0) DllCall("BitBlt", "Uint", LmDC, "int", 0, "int", 0, "int", LnW, "int", LnH, "Uint", LhDC, "int", LnL, "int", LnT, "Uint", 0x40000000 | 0x00CC0020) DllCall("ReleaseDC", "Uint", 0, "Uint", LhDC) DllCall("SelectObject", "Uint", LmDC, "Uint", LoBM) DllCall("DeleteDC", "Uint", LmDC) SetClipboardDataLeft(LhBM) } CaptureScreen(aRect = 0, bCursor = False, sFile = "", nQuality = "") { If !aRect { SysGet, nL, 76 SysGet, nT, 77 SysGet, nW, 78 SysGet, nH, 79 } Else If aRect = 1 WinGetPos, nL, nT, nW, nH, A Else If aRect = 2 { WinGet, hWnd, ID, A VarSetCapacity(rt, 16, 0) DllCall("GetClientRect" , "Uint", hWnd, "Uint", &rt) DllCall("ClientToScreen", "Uint", hWnd, "Uint", &rt) nL := NumGet(rt, 0, "int") nT := NumGet(rt, 4, "int") nW := NumGet(rt, 8) nH := NumGet(rt,12) } Else If aRect = 3 { VarSetCapacity(mi, 40, 0) DllCall("GetCursorPos", "int64P", pt) DllCall("GetMonitorInfo", "Uint", DllCall("MonitorFromPoint", "int64", pt, "Uint", 2), "Uint", NumPut(40,mi)-4) nL := NumGet(mi, 4, "int") nT := NumGet(mi, 8, "int") nW := NumGet(mi,12, "int") - nL nH := NumGet(mi,16, "int") - nT } Else { StringSplit, rt, aRect, `,, %A_Space%%A_Tab% nL := rt1 nT := rt2 nW := rt3 - rt1 nH := rt4 - rt2 znW := rt5 znH := rt6 } mDC := DllCall("CreateCompatibleDC", "Uint", 0) hBM := CreateDIBSection(mDC, nW, nH) oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM) hDC := DllCall("GetDC", "Uint", 0) DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020) DllCall("ReleaseDC", "Uint", 0, "Uint", hDC) If bCursor CaptureCursor(mDC, nL, nT) DllCall("SelectObject", "Uint", mDC, "Uint", oBM) DllCall("DeleteDC", "Uint", mDC) If znW && znH hBM := Zoomer(hBM, nW, nH, znW, znH) If sFile = 0 SetClipboardData(hBM) Else Convert(hBM, sFile, nQuality), DllCall("DeleteObject", "Uint", hBM) } CaptureCursor(hDC, nL, nT) { VarSetCapacity(mi, 20, 0) mi := Chr(20) DllCall("GetCursorInfo", "Uint", &mi) bShow := NumGet(mi, 4) hCursor := NumGet(mi, 8) xCursor := NumGet(mi,12) yCursor := NumGet(mi,16) VarSetCapacity(ni, 20, 0) DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni) xHotspot := NumGet(ni, 4) yHotspot := NumGet(ni, 8) hBMMask := NumGet(ni,12) hBMColor := NumGet(ni,16) If bShow DllCall("DrawIcon", "Uint", hDC, "int", xCursor - xHotspot - nL, "int", yCursor - yHotspot - nT, "Uint", hCursor) If hBMMask DllCall("DeleteObject", "Uint", hBMMask) If hBMColor DllCall("DeleteObject", "Uint", hBMColor) } Zoomer(hBM, nW, nH, znW, znH) { mDC1 := DllCall("CreateCompatibleDC", "Uint", 0) mDC2 := DllCall("CreateCompatibleDC", "Uint", 0) zhBM := CreateDIBSection(mDC2, znW, znH) oBM1 := DllCall("SelectObject", "Uint", mDC1, "Uint", hBM) oBM2 := DllCall("SelectObject", "Uint", mDC2, "Uint", zhBM) DllCall("SetStretchBltMode", "Uint", mDC2, "int", 4) DllCall("StretchBlt", "Uint", mDC2, "int", 0, "int", 0, "int", znW, "int", znH, "Uint", mDC1, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", 0x00CC0020) DllCall("SelectObject", "Uint", mDC1, "Uint", oBM1) DllCall("SelectObject", "Uint", mDC2, "Uint", oBM2) DllCall("DeleteDC", "Uint", mDC1) DllCall("DeleteDC", "Uint", mDC2) DllCall("DeleteObject", "Uint", hBM) Return zhBM } Convert(sFileFr = "", sFileTo = "", nQuality = "") { If sFileTo = sFileTo := A_ScriptDir . "\screen.bmp" SplitPath, sFileTo, , sDirTo, sExtTo, sNameTo If Not hGdiPlus := DllCall("LoadLibrary", "str", "gdiplus.dll") Return sFileFr+0 ? SaveHBITMAPToFile(sFileFr, sDirTo . "\" . sNameTo . ".bmp") : "" VarSetCapacity(si, 16, 0), si := Chr(1) DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0) If !sFileFr { DllCall("OpenClipboard", "Uint", 0) If DllCall("IsClipboardFormatAvailable", "Uint", 2) && (hBM:=DllCall("GetClipboardData", "Uint", 2)) DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", hBM, "Uint", 0, "UintP", pImage) DllCall("CloseClipboard") } Else If sFileFr Is Integer DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", sFileFr, "Uint", 0, "UintP", pImage) Else DllCall("gdiplus\GdipLoadImageFromFile", "Uint", Unicode4Ansi(wFileFr,sFileFr), "UintP", pImage) DllCall("gdiplus\GdipGetImageEncodersSize", "UintP", nCount, "UintP", nSize) VarSetCapacity(ci,nSize,0) DllCall("gdiplus\GdipGetImageEncoders", "Uint", nCount, "Uint", nSize, "Uint", &ci) Loop, % nCount If InStr(Ansi4Unicode(NumGet(ci,76*(A_Index-1)+44)), "." . sExtTo) { pCodec := &ci+76*(A_Index-1) Break } If InStr(".JPG.JPEG.JPE.JFIF", "." . sExtTo) && nQuality<>"" && pImage && pCodec { DllCall("gdiplus\GdipGetEncoderParameterListSize", "Uint", pImage, "Uint", pCodec, "UintP", nSize) VarSetCapacity(pi,nSize,0) DllCall("gdiplus\GdipGetEncoderParameterList", "Uint", pImage, "Uint", pCodec, "Uint", nSize, "Uint", &pi) Loop, % NumGet(pi) If NumGet(pi,28*(A_Index-1)+20)=1 && NumGet(pi,28*(A_Index-1)+24)=6 { pParam := &pi+28*(A_Index-1) NumPut(nQuality,NumGet(NumPut(4,NumPut(1,pParam+0)+20))) Break } } If pImage pCodec ? DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage, "Uint", Unicode4Ansi(wFileTo,sFileTo), "Uint", pCodec, "Uint", pParam) : DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pImage, "UintP", hBitmap, "Uint", 0) . SetClipboardData(hBitmap), DllCall("gdiplus\GdipDisposeImage", "Uint", pImage) DllCall("gdiplus\GdiplusShutdown" , "Uint", pToken) DllCall("FreeLibrary", "Uint", hGdiPlus) } CreateDIBSectionLeft(LhDC, LnW, LnH, Lbpp = 32, ByRef LpBits = "") { NumPut(VarSetCapacity(Lbi, 40, 0), Lbi) NumPut(LnW, Lbi, 4) NumPut(LnH, Lbi, 8) NumPut(Lbpp, NumPut(1, Lbi, 12, "UShort"), 0, "Ushort") NumPut(0, Lbi,16) Return DllCall("gdi32\CreateDIBSection", "Uint", LhDC, "Uint", &Lbi, "Uint", 0, "UintP", LpBits, "Uint", 0, "Uint", 0) } CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "") { NumPut(VarSetCapacity(bi, 40, 0), bi) NumPut(nW, bi, 4) NumPut(nH, bi, 8) NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort") NumPut(0, bi,16) Return DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0) } SaveHBITMAPToFile(hBitmap, sFile) { DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi) hFile:= DllCall("CreateFile", "Uint", &sFile, "Uint", 0x40000000, "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 0, "Uint", 0) DllCall("WriteFile", "Uint", hFile, "int64P", 0x4D42|14+40+NumGet(oi,44)<<16, "Uint", 6, "UintP", 0, "Uint", 0) DllCall("WriteFile", "Uint", hFile, "int64P", 54<<32, "Uint", 8, "UintP", 0, "Uint", 0) DllCall("WriteFile", "Uint", hFile, "Uint", &oi+24, "Uint", 40, "UintP", 0, "Uint", 0) DllCall("WriteFile", "Uint", hFile, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44), "UintP", 0, "Uint", 0) DllCall("CloseHandle", "Uint", hFile) } SetClipboardDataLeft(hBitmap) { DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi) LhDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44)) LpDIB := DllCall("GlobalLock", "Uint", LhDIB) DllCall("RtlMoveMemory", "Uint", LpDIB, "Uint", &oi+24, "Uint", 40) DllCall("RtlMoveMemory", "Uint", LpDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44)) DllCall("GlobalUnlock", "Uint", LhDIB) DllCall("DeleteObject", "Uint", LhBitmap) DllCall("OpenClipboard", "Uint", 0) DllCall("EmptyClipboard") DllCall("SetClipboardData", "Uint", 8, "Uint", LhDIB) DllCall("CloseClipboard") } SetClipboardData(hBitmap) { DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi) hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44)) pDIB := DllCall("GlobalLock", "Uint", hDIB) DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40) DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44)) DllCall("GlobalUnlock", "Uint", hDIB) DllCall("DeleteObject", "Uint", hBitmap) DllCall("OpenClipboard", "Uint", 0) DllCall("EmptyClipboard") DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB) DllCall("CloseClipboard") } Unicode4Ansi(ByRef wString, sString) { nSize := DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0) VarSetCapacity(wString, nSize * 2) DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize) Return &wString } Ansi4Unicode(pString) { nSize := DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0) VarSetCapacity(sString, nSize) DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize, "Uint", 0, "Uint", 0) Return sString } /* *==================================================================================== * END OF FILE *==================================================================================== */
And to prove the awesomeness of my script, I will count the time it takes to ScreenClip this sentence.
5 seconds, including typing out the <img>-tag and pasting the link.
#10
-
Posted 18 February 2011 - 12:28 PM
Check this AHK code to autosave without using IrfanView. Uses MSPaint, and no additional scripts to install. Pretty straight forward and easy code. Customizable folder and file name. Currently filename is timestamp.
http://www.littletec...-autosave.html
#11
-
Posted 04 April 2014 - 09:19 PM