Paste Image to Screen like Snipaste

Post your working scripts, libraries and tools
xml123
Posts: 7
Joined: 01 Jun 2020, 18:55

Paste Image to Screen like Snipaste

01 Jun 2020, 21:04

I wrote a script to implement the Paste function in Snipaste. Hope you like it!

How to use it:
Copy an image, then press F3 to display.

Hotkeys:
F3 to paste image (or text) in Clipboard to screen.
Mouse scroll to change size of the paste, middle button to reset size (only for image).
Ctrl+mouse scroll to change transparency of the paste, Ctrl+middle button to reset transparency.
Drag the paste to move it.
Double click to close.
Ctrl+Alt+3 to make paste unclickable (you can clickthrough the paste).
Shift+F3 to hide or show all paste.
Ctrl+F3 to close all paste.
Ctlr+Shift+F3 to exit script.

Notations:
How to copy an image
- take a screenshot (this is not included in this script. You can use the defalut hotkey of screenshot in Windows 10 Win+Shift+S or any other tool you like).
- copy image file from Explorer
- copy image from web browser, MS Office, etc.

You can also copy text to paste.

Before you change the size or transparency, you need to activate the paste.

You cannot click throught an opaque paste.

Code: Select all

#SingleInstance Force
#NoEnv

displayNum := 0
visibleState := true

F3::
	pasteToScreen(){
		if DllCall("IsClipboardFormatAvailable", "UInt", 1)
			displayText(Clipboard)
		If DllCall("IsClipboardFormatAvailable", "UInt", 2){
			if DllCall("OpenClipboard", "uint", 0) {
				hBitmap := DllCall("GetClipboardData", "uint", 2)
				DllCall("CloseClipboard")
			}
			displayImg(hBitmap)
		}
		if DllCall("IsClipboardFormatAvailable", "UInt", 15){
			imgFile := Clipboard
			if(hBitmap := LoadPicture(imgFile))
				displayImg(hBitmap)
		}
	}

displayText(text){
	global
	Gui, New, +hwndpasteText%displayNum% -Caption +AlwaysOnTop +ToolWindow -DPIScale
	local textHnd := pasteText%displayNum%
	Gui, Margin, 10, 10
	Gui, Font, s16
	Gui, Add, Text,, % text
	OnMessage(0x201, "move_Win")
	OnMessage(0x203, "close_Win")
	Gui, Show,, pasteToScreen_text
	transparency%textHnd% := 100
	displayNum++
}

displayImg(hBitmap){
	global
	Gui, New, +hwndpasteImg%displayNum% -Caption +AlwaysOnTop +ToolWindow -DPIScale
	local imgHnd := pasteImg%displayNum%
	Gui, Margin, 0, 0
	Gui, Add, Picture, Hwndimg%imgHnd%, % "HBITMAP:*" hBitmap
	OnMessage(0x201, "move_Win")
	OnMessage(0x203, "close_Win")
	Gui, Show,, pasteToScreen_img
	local img := img%imgHnd%
	ControlGetPos,,, width%imgHnd%, height%imgHnd%,, ahk_id %img%
	scale%imgHnd% := 100
	transparency%imgHnd% := 100
	displayNum++
}

move_Win(){
	PostMessage, 0xA1, 2
}

close_Win(){
	id := WinExist("A")
	transparency%id% := ""
	scale%id% := ""
	width%id% := ""
	height%id% := ""
	Gui, Destroy
}

#IfWinActive pasteToScreen

^WheelDown::
	decreaseTransparency(){
		id := WinExist("A")
		transparency%id% -= 5
		If (transparency%id% < 10)
			transparency%id% = 10
		transparency := transparency%id% * 255 // 100
		WinSet, Transparent, %transparency%, A
		tooltip, % "Opacity:" transparency%id% "%"
		SetTimer, RemoveToolTip, -500
	}

^WheelUp::
	increaseTransparency(){
		id := WinExist("A")
		transparency%id% += 5
		If (transparency%id% > 100)
			transparency%id% = 100
		transparency := transparency%id% * 255 // 100
		WinSet, Transparent, %transparency%, A
		tooltip, % "Opacity:" transparency%id% "%"
		SetTimer, RemoveToolTip, -500
	}

^MButton::
	resetTransparency(){
		id := WinExist("A")
		transparency%id% = 100
		WinSet, Transparent, 255, A
		tooltip, % "Opacity:" transparency%id% "%"
		SetTimer, RemoveToolTip, -500
	}

#IfWinActive pasteToScreen_img

~WheelDown::
	decreaseSize(){
		id := WinExist("A")
		img := img%id%
		scale%id% -= 10
		If (scale%id% < 10)
			scale%id% = 10
		WinGetPos,,, width, height
		width := width%id% * scale%id% // 100
		height := height%id% * scale%id% // 100
		GuiControl, MoveDraw, %img%, w%width% h%height%
		WinMove,,,,, width, height
		tooltip, % "Size:" scale%id% "%"
		SetTimer, RemoveToolTip, -500
	}

~WheelUp::
	increaseSize(){
		id := WinExist("A")
		img := img%id%
		scale%id% += 10
		WinGetPos,,, width, height
		width := width%id% * scale%id% // 100
		height := height%id% * scale%id% // 100
		GuiControl, MoveDraw, %img%, w%width% h%height%
		WinMove,,,,, width, height
		tooltip, % "Size:" scale%id% "%"
		SetTimer, RemoveToolTip, -500
	}

~MButton::
	resetSize(){
		id := WinExist("A")
		img := img%id%
		scale%id% = 100
		width := width%id%
		height := height%id%
		GuiControl, MoveDraw, %img%, w%width% h%height%
		WinMove,,,,, width, height
		tooltip, % "Size:" scale%id% "%"
		SetTimer, RemoveToolTip, -500
	}

#IfWinActive

^!3::
	toggleClickThroughState(){
		WinGet, id, List, pasteToScreen
		Loop, %id%
		{
			this_id := id%A_Index%
			WinSet, ExStyle, ^0x20, ahk_id %this_id%
		}
	}

+F3::
	toggleVisibleState(){
		global visibleState
		if(visibleState){
			WinGet, id, List, pasteToScreen
			Loop, %id%
			{
				this_id := id%A_Index%
				WinHide, ahk_id %this_id%
			}
			visibleState := false
		} else {
			DetectHiddenWindows, On
			WinGet, id, List, pasteToScreen
			Loop, %id%
			{
				this_id := id%A_Index%
				WinShow, ahk_id %this_id%
			}
			DetectHiddenWindows, Off
			visibleState := true
		}
	}

^F3::
	destroyAllPaste(){
		WinGet, id, List, pasteToScreen
		Loop, %id%
		{
			this_id := id%A_Index%
			SendMessage, 0x203,,,, ahk_id %this_id%
		}
	}

^+F3::ExitApp

RemoveToolTip:
	ToolTip
return
I use a dumb way to record the status of the paste windows due to my poor programming skill so there may be memory leakage. The performance is not great especially resize or hide/show. The default hotkeys are decided casually. Feel free to modify this script.
fenchai
Posts: 236
Joined: 28 Mar 2016, 07:57

Re: Paste Image to Screen like Snipaste

02 Jun 2020, 13:22

Sorry I don't understand by paste to screen. What do you mean by that? is it just pinning the screenshot taken by snipaste?
If that's so then you can just run a snipaste command to do that.
User avatar
SpeedMaster
Posts: 385
Joined: 12 Nov 2016, 16:09

Re: Paste Image to Screen like Snipaste

03 Jun 2020, 04:03

Amazing, works very well on win 7 and win 10. :bravo:
I've been looking for something like this for quite some time.
The options for this script could be greatly expanded. ;)

for example by offering an option to choose a file directly instead of using only the clipboard. (F4 = load a file)
like this:

Code: Select all

f4::
FileSelectFile, imgFile, 3
hBitmap := LoadPicture(imgFile)
displayImg(hBitmap)
return

Return to “Scripts and Functions”

Who is online

Users browsing this forum: FlowerBridge and 125 guests