Advertisement
Lorenzo501

Time Saver (redundant Screenshot+ snippets).ahk

Dec 4th, 2024
86
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     PrintScreen = SCREENSHOT+
  2.         Quick-press to use native fn, double-press to save to desktop as well & long-press to take screenshot or keep previous on demand, saving either one to desktop.
  3.  
  4.  
  5. *PrintScreen::
  6. {
  7.     static _ := OnClipboardChange(HandleClipChanged), hasScreenshotInClipboard := false, latestScreenshotTime := 0, dialogCountdown
  8.     pressStartTime := A_TickCount
  9.     shouldTakeNewScreenshot := 0
  10.  
  11.     loop
  12.     {
  13.         Sleep(10)
  14.  
  15.         if (!GetKeyState("PrintScreen", "P"))
  16.         {
  17.             ; PrintScreen Quick-Press. This takes a new screenshot
  18.             if (A_TickCount - latestScreenshotTime > 500)
  19.             {
  20.                 Send("{Blind}{PrintScreen}") ; Blind mode allows the native Win+PrtScn hotkey to save it in the `Screenshots` folder
  21.                 latestScreenshotTime := A_TickCount
  22.  
  23.                 return
  24.             }
  25.  
  26.             ; PrintScreen Double-Press. This saves the screenshot of the first press to desktop
  27.             break
  28.         }
  29.  
  30.         ; PrintScreen Long-Press. This conditionally takes a new screenshot and saves a screenshot to desktop
  31.         if (A_TickCount - pressStartTime > 750)
  32.         {
  33.             ; To identify a long-press and to execute the default action for long-press
  34.             shouldTakeNewScreenshot := "OK"
  35.  
  36.             break
  37.         }
  38.     }
  39.  
  40.     ; Auto-saving any existing screenshot that is currently in the clipboard on long-press, w/ the option to take a new screenshot instead
  41.     if (shouldTakeNewScreenshot := "OK" && hasScreenshotInClipboard) ;DllCall("IsClipboardFormatAvailable", "UInt", CF_BITMAP := 2))
  42.     {
  43.         dialogCountdown := 8
  44.         HookEvent(EVENT_OBJECT_CREATE, HandleCreatedDialogEvent)
  45.         shouldTakeNewScreenshot := MsgBox("Auto-saving in 8 seconds..", "Existing image in clipboard detected!", "0x40000 T8") ; Saves "OK" or "Timeout"
  46.         Sleep(200) ; Waiting for the dialog close animation to end
  47.     }
  48.  
  49.     if (shouldTakeNewScreenshot = "OK")
  50.     Send("{PrintScreen}"), latestScreenshotTime := A_TickCount
  51.  
  52.     RunWait("PowerShell.exe -Command `"$img = get-clipboard -format image; $img.save('" A_Desktop "\screenshot " A_Now ".jpg')`"",, "Hide")
  53.     TrayTip("Saved to desktop", "Screenshot taken", 0x34)
  54.     SetTimer(HideTrayTip, -4000)
  55.     KeyWait("PrintScreen") ; Prevents the printscreen hotkey from triggering again while it's still pressed down
  56.  
  57.     HandleClipChanged(*) => hasScreenshotInClipboard := A_TickCount - latestScreenshotTime < 1000
  58.  
  59.     HandleCreatedDialogEvent(hWinEventHook, event, hWnd, *)
  60.     {
  61.         try
  62.             if (WinGetClass(hWnd) = "#32770")
  63.             {
  64.                 DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  65.                 DllCall("EnableMenuItem", "Ptr", DllCall("GetSystemMenu", "UInt", hWnd, "Int", 0), "UInt", SC_CLOSE := 0xF060, "UInt", MF_GRAYED := 0x00000001)
  66.                 ControlMove(24,, 150,, "Button1", hWnd)
  67.                 ControlSetText("Take New Screenshot", "Button1", hWnd)
  68.                 SetTimer(() => UpdateDialogTime(hWnd), 1000)
  69.             }
  70.  
  71.         UpdateDialogTime(hWnd)
  72.         {
  73.             try ControlSetText("Auto-saving in " (--dialogCountdown) " seconds..", "Static1", hWnd)
  74.             catch
  75.                 SetTimer(, 0)
  76.         }
  77.     }
  78. }
Advertisement
Comments
  • Lorenzo501
    18 days
    # text 2.21 KB | 0 0
    1. SCREENSHOT+ DOUBLE-PRESS SEEMS TO DO THE SAME AS LONG-PRESS, WHICH SHOULDN'T HAPPEN ACCORDING TO MY MULTI-LINE COMMENT AT THE TOP OF THE SCRIPT. LONG-PRESS REPEATEDLY ONLY SHOWED TRAYTIP BUT DIDNT SAVE SCREENSHOT IN CLIPBOARD (B/C NOTHING GOT PASTED IN PAINT WHEN I TRIED) NOR ON DESKTOP. Long-press only works when it already has a screenshot in clipboard.. then it'll show the traytip and also a dialog, and then it'll save to desktop successfully <.< quick-press w/ nothing in clipboard at first, WOULD SHOW THERE BEING AN EXISTING SCREENSHOT, then dialog and traytip, and successfully saves to desktop.. SO IT STILL NEEDS SOME CHANGES!
    2. |
    3. long-press with an image from the snipping tool in the clipboard saves that to desktop but shows no msgbox about there being an image in the clipboard. the "existing image in clipboard detected" after double-press is clearly just it detecting the screenshot of the first-press.
    4.  
    5. [ALSO I MIGHT WANNA ADD A TIP MENTIONING THAT IT CAN BE USED STRAIGHT AFTER YOU'VE GOT A SNIP IN THE CLIPBOARD, TO SKIP PAINT. AND DON'T USE * SYMBOL BUT MAKE #PrntScrn AND PrtnScrn ABOVE EACHOTHER USING THE SAME HOTKEY CODE OFC, THIS WAY YOU CAN MENTION USING Ctrl+PrtnScrn TO MAKE A NON-DELAYED PRINTSCREEN. BECAUSE SUSPECT THE DOUBLE-PRESS NEEDING A 500 MS DELAY TO SEE IF THERE WAS A 2ND PRESS
    6.  
    7. OR PERHAPS I CAN FIRST CHECK IF THERE'S ALREADY AN IMAGE IN THE CLIPBOARD AND IF SO, THEN TEMPORARILY COPY THE CLIPBOARD IMAGE INTO A VARIABLE, MAKE SCREENSHOT AND IF THERE'S A 2ND PRESS, IT'LL JUST ADD THE VARIABLE TO A_CLIPBOARD AND SAVE TO THE DESKTOP, LIKE IT NEVER MADE A NEW SCREENSHOT, AND WHEN THERE'S NO 2ND PRESS, THEN IT JUST KEEPS THE NEW SCREENSHOT. I MIGHT WANNA CHECK HOW MANY MILLISECONDS IT TAKES THOUGH, TO SEE IF IT'S HELPFUL AT ALL]
    8.  
    9. [ON 2ND THOUGHT IDK, IS FINE TO MAKE IT WORK WITH THE * SYMBOL IF IT DOESN'T ALREADY, BUT I DON'T WANT TO REMEMBER TO USE THE WINDOWS KEY.. I'LL FORGET THAT ANYWAY, AND HAVING BOTH HOTKEYS EXPLAINED WOULD STILL NOT BE IDEAL <.<" JUST TRY TO MAKE IT WORK HOW IT WAS EXPLAINED ALREADY FOR THE PRINTSCREEN DOUBLE-PRESS]
    10.  
    11. And consider using Win+PrtScrn for saving clipboard image to desktop (to skip the dialog). Don't forget adding it to the tray icon tooltip and multi-line comment
Add Comment
Please, Sign In to add comment
Advertisement