Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Class] WinClip - direct clipboard manipulations


  • Please log in to reply
94 replies to this topic
ParticleMan
  • Members
  • 32 posts
  • Last active: Jan 22 2013 03:40 AM
  • Joined: 04 Dec 2011

well, if GetOpenClipboardWindow() returned anything != 0, the tooltip will be shown 100%, it can't be any rarely


It works rarely for me, that's all I can say. Would it perform more predictably if it were to call OpenClipboard() before GetOpenClipboardWindow() (and of course CloseClipboard() later)?

it would be nice if you can describe any way to reproduce your problem on practice with code example


I'm working on getting a reproducible example but the problem is too intermittent. That AHK tends to need kludging with Sleep, which optimal duration varies widely, is a fundamental issue or limitation.

mparsons
  • Members
  • 5 posts
  • Last active: Feb 11 2012 08:27 PM
  • Joined: 22 Jan 2012
Any chance you could add the ability to put HTML formatted text on the clipboard?

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
class has been updated, check the first post for info

Any chance you could add the ability to put HTML formatted text on the clipboard?

done in the last update

MiddleFinger
  • Members
  • 7 posts
  • Last active: Mar 26 2012 05:03 PM
  • Joined: 07 Feb 2012
How about retreiving the rtf in the clipboard BTW thanks for the html

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010

How about retreiving the rtf in the clipboard BTW thanks for the html

done :)

Update 7/02/2012
Added following methods to retrieve or set RTF format:
GetRTF(),iGetRTF
SetRTF( text ),iSetRTF( text )



MiddleFinger
  • Members
  • 7 posts
  • Last active: Mar 26 2012 05:03 PM
  • Joined: 07 Feb 2012
Very nice thanks a heap

  • Guests
  • Last active:
  • Joined: --
@Deo: WinClip() looks interesting. I note you can save a clipboard to a file already, but how about storing it in other formats say base64 or other text format, see my post here <!-- m -->http://www.autohotke...440.html#510440<!-- m -->
the idea would be to allow one to store the clipboard history in a/one plain text file rather than individual binary clipboard files. It would also make storing clipboard data in a psuedo database (say xml or csv) possible which is what I'm after eventually.

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
hi
sure, you can do whatever you want with binary data you get from
dataSize := WinClip.Snap( data )
or, in case of instantiated WinClip object
wc := new WinClip
wc.iSnap()
dataSize := wc.iGetData( Data )
for example, you can convert this into transportable hash, like this
hash := ByteToHash( data, dataSize )

ByteToHash(ByRef pbData,dwLen)
{
	if (dwLen < 1)
		return 0
	if pbData is integer
		ptr := pbData
	else
		ptr := &pbData
	SetFormat,integer,Hex
	loop,%dwLen%
	{
		num := numget(ptr+0,A_index-1,"UChar")
		hash .= substr((num >> 4),0) . substr((num & 0xf),0)
	}
	SetFormat,integer,D
	return hash
}
to convert it back, you can use this function
HashToByte(sHash,ByRef ByteBuf)
{
	if (sHash == "" || RegExMatch(sHash,"[^\dABCDEF]") || mod(StrLen(sHash),2))
		return 0
	BufLen := StrLen(sHash)/2
	VarSetCapacity(ByteBuf,BufLen,0)
	loop,%BufLen%
	{
		num1 := (p := "0x" . SubStr(sHash,(A_Index-1)*2+1,1)) << 4
		num2 := "0x" . SubStr(sHash,(A_Index-1)*2+2,1)
		num := num1 | num2
		NumPut(num,ByteBuf,A_Index-1,"UChar")
	}
	return BufLen
}


Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
to encode bytes to base64, use this functions:
b64Encode( ByRef buf, bufLen )
{
	DllCall( "crypt32\CryptBinaryToStringA", "ptr", &buf, "UInt", bufLen, "Uint", 1, "Ptr", 0, "UInt*", outLen )
	VarSetCapacity( outBuf, outLen, 0 )
	DllCall( "crypt32\CryptBinaryToStringA", "ptr", &buf, "UInt", bufLen, "Uint", 1, "Ptr", &outBuf, "UInt*", outLen )
	return strget( &outBuf, outLen, "CP0" )
}

b64Decode( b64str, ByRef outBuf )
{
	DllCall( "crypt32\CryptStringToBinaryW", "ptr", &b64str, "UInt", 0, "Uint", 1, "Ptr", 0, "UInt*", outLen, "ptr", 0, "ptr", 0 )
	VarSetCapacity( outBuf, outLen, 0 )
	DllCall( "crypt32\CryptStringToBinaryW", "ptr", &b64str, "UInt", 0, "Uint", 1, "Ptr", &outBuf, "UInt*", outLen, "ptr", 0, "ptr", 0 )
	return outLen
}
for example:
dataSize := WinClip.Snap( data )
b64string := b64Encode( data, dataSize  )
to put data back to clipboard:
b64Decode( b64string, clipBuf )
WinClip.Restore( clipBuf )


  • Guests
  • Last active:
  • Joined: --
Thanks Deo, you're the AHK Clipboard Master! :D
I'll start experimenting over the weekend...

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
lol, thanks!

getitdone12
  • Members
  • 3 posts
  • Last active: Feb 17 2012 06:23 AM
  • Joined: 10 Feb 2012
I have made a GUI that always displays what is in my clipboard.
Now I looking to expand some capibilities.
I am thinking this is possible something that could be very useful!

Have you thought about displaying or making available the inner clipboard.
Maybe the command / method is there and I don't see it. :)

Sure you would be able to send the inner to the clipboard and it would show, but why not make it so that you could see, 'Preview' the inner?

Usually I am a lurker. So if I did this incorrect forgive me.

Example
iSnap() ;Copies the clipboard to innerclipboard
;other work here
;other work here
;other work here
;hmmm I don't remember what is in the innerclipboard. 
Msgbox, %iDisplay() ;Display what is in the innerclipboard
ipaste() ;oh yes this is what I want paste it.
I am liking what I see so far :O

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
hi
if under "display" you mean any data, you may get it through different "iGet*" methods like
iGetText
iGetFiles
iGetHTML
iGetRTF
iGetBitmap
Or
iGetFormats to get all formats available
or, if you need to know that specified format presented on clipboard
iHasFormat

iHasFormat accept any integer or string format. You can see standard formats values at the bottom of WinClip.ahk :)

getitdone12
  • Members
  • 3 posts
  • Last active: Feb 17 2012 06:23 AM
  • Joined: 10 Feb 2012
ok I see now.
Kind of like this

#Include WinClipAPI.ahk
#Include WinClip.ahk
;wc := new WinClip
wc1:=new WinClip
wc2:=new WinClip

f1::
wc1.iCopy()
gosub, update
return

f2::
wc2:=new WinClip
wc2.iCopy()
gosub, update
return

f3::
wc1.iPaste()
gosub, update
return

F4::
wc2.iPaste()
gosub, update
return

update:
Gui, Destroy
preview1 := wc1.iGetText()
preview2 := wc2.iGetText()
Gui, add , text, ,1: %preview1%
Gui, add, text, , 2: %preview2%
gui, show, , preview
return
[Edit]
Great!

Now I just need a better understanding of Arrays..........
Thank you

PS The documentation regarding the formats is really good. At least for me.
I think I am going to sticking to CF_OEMTEXT. This is a great feature.
Thank you. Again

  • Guests
  • Last active:
  • Joined: --

to encode bytes to base64, use this functions

@Deo: Thanks man, it really works well!