Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PrintScreen = SCREENSHOT+
- 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.
- *PrintScreen::
- {
- static _ := OnClipboardChange(HandleClipChanged), hasScreenshotInClipboard := false, latestScreenshotTime := 0, dialogCountdown
- pressStartTime := A_TickCount
- shouldTakeNewScreenshot := 0
- loop
- {
- Sleep(10)
- if (!GetKeyState("PrintScreen", "P"))
- {
- ; PrintScreen Quick-Press. This takes a new screenshot
- if (A_TickCount - latestScreenshotTime > 500)
- {
- Send("{Blind}{PrintScreen}") ; Blind mode allows the native Win+PrtScn hotkey to save it in the `Screenshots` folder
- latestScreenshotTime := A_TickCount
- return
- }
- ; PrintScreen Double-Press. This saves the screenshot of the first press to desktop
- break
- }
- ; PrintScreen Long-Press. This conditionally takes a new screenshot and saves a screenshot to desktop
- if (A_TickCount - pressStartTime > 750)
- {
- ; To identify a long-press and to execute the default action for long-press
- shouldTakeNewScreenshot := "OK"
- break
- }
- }
- ; Auto-saving any existing screenshot that is currently in the clipboard on long-press, w/ the option to take a new screenshot instead
- if (shouldTakeNewScreenshot := "OK" && hasScreenshotInClipboard) ;DllCall("IsClipboardFormatAvailable", "UInt", CF_BITMAP := 2))
- {
- dialogCountdown := 8
- HookEvent(EVENT_OBJECT_CREATE, HandleCreatedDialogEvent)
- shouldTakeNewScreenshot := MsgBox("Auto-saving in 8 seconds..", "Existing image in clipboard detected!", "0x40000 T8") ; Saves "OK" or "Timeout"
- Sleep(200) ; Waiting for the dialog close animation to end
- }
- if (shouldTakeNewScreenshot = "OK")
- Send("{PrintScreen}"), latestScreenshotTime := A_TickCount
- RunWait("PowerShell.exe -Command `"$img = get-clipboard -format image; $img.save('" A_Desktop "\screenshot " A_Now ".jpg')`"",, "Hide")
- TrayTip("Saved to desktop", "Screenshot taken", 0x34)
- SetTimer(HideTrayTip, -4000)
- KeyWait("PrintScreen") ; Prevents the printscreen hotkey from triggering again while it's still pressed down
- HandleClipChanged(*) => hasScreenshotInClipboard := A_TickCount - latestScreenshotTime < 1000
- HandleCreatedDialogEvent(hWinEventHook, event, hWnd, *)
- {
- try
- if (WinGetClass(hWnd) = "#32770")
- {
- DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
- DllCall("EnableMenuItem", "Ptr", DllCall("GetSystemMenu", "UInt", hWnd, "Int", 0), "UInt", SC_CLOSE := 0xF060, "UInt", MF_GRAYED := 0x00000001)
- ControlMove(24,, 150,, "Button1", hWnd)
- ControlSetText("Take New Screenshot", "Button1", hWnd)
- SetTimer(() => UpdateDialogTime(hWnd), 1000)
- }
- UpdateDialogTime(hWnd)
- {
- try ControlSetText("Auto-saving in " (--dialogCountdown) " seconds..", "Static1", hWnd)
- catch
- SetTimer(, 0)
- }
- }
- }
Advertisement
Comments
-
- 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!
- |
- 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.
- [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
- 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]
- [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]
- 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