an Array of "ClipboardAll" contents Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

an Array of "ClipboardAll" contents

05 Jan 2019, 15:30

Hi
I wrote a simple code
I'd like to use some complex contents using Array
So, I tried "ClipboardAll" command but, failed to achieve my goal.

Code: Select all

myArray := [] 
SendInput, ^c
myContents := ClipboardAll      ;  just have an Alien character
;myContents := Clipboard		;  works fine but only with "Text" - I need "complex" contents
myArray.Push(myContents) 
...
..
.
Clipboard := myArray[1]
SendInput, ^v
any helps ?
ahk7
Posts: 572
Joined: 06 Nov 2013, 16:35

Re: an Array of "ClipboardAll" contents

05 Jan 2019, 15:47

You can try to convert the binary? data to "text" before storing it, see HashToByte and base64 below that post
https://autohotkey.com/board/topic/7467 ... /?p=488736
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

05 Jan 2019, 15:50

@ahk7
Wow thanks
I'll check it out

[EDIT]
Too much complex.......sighhhh...... is there any/some easy way ?
-actually, I have failed to find my purpose. ah.. some kind of array.
Last edited by IMEime on 05 Jan 2019, 16:02, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: an Array of "ClipboardAll" contents  Topic is solved

05 Jan 2019, 16:00

ClipboardAll is blank when used in ways other than those described above.
the ways being, direct assignment and FileAppend/Read
so i guess an alternative could be, u make a class wrapper that would keep track of, save and delete clip files, if ure okay with ur script generating a mega amount of such trash files
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

05 Jan 2019, 16:05

@swagfag
File.. Hmmm..
OK, I'll try. I have lots, lots of empty HDD/SSD spaces.
Thanks

You mean this one (it is from Help document);

Code: Select all

FileAppend, %ClipboardAll%, C:\Company Logo.clip ; The file extension does not matter.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

05 Jan 2019, 16:13

@swagfag
Wow..
Works fine.
I love this one.
Big Thanks
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: an Array of "ClipboardAll" contents

05 Jan 2019, 16:16

yes, FileAppend
idk what ure gonna be copying, but i dont think ud need much HDD space. i havent tested it myself, but if u for example copied a big file from explorer and saved that into a .clip, it will only keep track of it and not save and copy the actual data over twice
teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: an Array of "ClipboardAll" contents

06 Jan 2019, 06:23

Without using files:

Code: Select all

clipArr := []
k := 1
Return

$F1:: clipArr.Push( SaveClipboard() )
$F2::
   if !clipArr[1]
      Return
   SetClipboardData( clipArr[k++] )
   (k > clipArr.MaxIndex() && k := 1)
   Send ^v
   Return

SaveClipboard()  {
   static CF_ENHMETAFILE := 14
   clipContent := {}, clipFormat := 0
   DllCall("OpenClipboard", Ptr, 0)
   while clipFormat := DllCall("EnumClipboardFormats", UInt, clipFormat)  {
      hMem := DllCall("GetClipboardData", UInt, clipFormat, Ptr)
      if (clipFormat = CF_ENHMETAFILE)  {
         size := DllCall("GetEnhMetaFileBits", Ptr, hMem, UInt, 0, Ptr, 0)
         clipContent.SetCapacity(clipFormat, size)
         DllCall("GetEnhMetaFileBits", Ptr, hMem, UInt, size, Ptr, clipContent.GetAddress(clipFormat))
      }
      else  {
         pMem := DllCall("GlobalLock", Ptr, hMem, Ptr)
         size := DllCall("GlobalSize", Ptr, pMem)
         clipContent.SetCapacity(clipFormat, size)
         DllCall("RtlMoveMemory", Ptr, clipContent.GetAddress(clipFormat), Ptr, pMem, Ptr, size)
         DllCall("GlobalUnlock", Ptr, hMem)
      }
   }
   DllCall("CloseClipboard")
   Return clipContent
}

SetClipboardData(clipContent)  {
   static CF_ENHMETAFILE := 14, flags := (GMEM_ZEROINIT := 0x40) | (GMEM_MOVEABLE := 0x2)
   DllCall("OpenClipboard", Ptr, 0)
   DllCall("EmptyClipboard")
   for clipFormat in clipContent  {
      addr := clipContent.GetAddress(clipFormat), size := clipContent.GetCapacity(clipFormat)
      if (clipFormat = CF_ENHMETAFILE)  {
         hData := DllCall("SetEnhMetaFileBits", UInt, size, Ptr, addr, Ptr)
         DllCall("SetClipboardData", UInt, CF_ENHMETAFILE, Ptr, hData, Ptr)
         DllCall("DeleteEnhMetaFile", Ptr, hData)
      }
      else  {
         hMem := DllCall("GlobalAlloc", UInt, flags, Ptr, size, Ptr)
         pMem := DllCall("GlobalLock", Ptr, hMem, Ptr)
         DllCall("RtlMoveMemory", Ptr, pMem, Ptr, addr, Ptr, size)
         DllCall("SetClipboardData", UInt, clipFormat, Ptr, pMem, Ptr)
         DllCall("GlobalUnlock", Ptr, hMem)
      }
   }
   DllCall("CloseClipboard")
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: an Array of "ClipboardAll" contents

06 Jan 2019, 07:11

Nice one teadrinker, it works well it seems :thumbup:.
Spoiler
Cheers.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 01:48

teadrinker wrote:
06 Jan 2019, 06:23
Without using files:...
Wow, I just found it.

First of all.. Thanks !!

I'll try out.

bye
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 02:41

Can anybody tell me (if it is @teadrinker, it will be the best)
a little bit more about this line ?

Code: Select all

(k > clipArr.MaxIndex() && k := 1)
I can not understand it at all

Is it a assignment statement ? Assigning a value to a variable K ?
Or some kind of comparison statement ?
Or any other operations ?
Why it make an error if I remove parentheses around it ?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 02:48

it's an if statement. there's no reason to use this as opposed to a ternary
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 02:50

really ?
where is question mark "?" and colon ":" ??
Can you please make it a "formal" form ? I mean formal 'ternary' statement.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 03:25

Code: Select all

    (k > clipArr.MaxIndex() && k := 1)
     k > clipArr.MaxIndex() ?  k := 1
k := k > clipArr.MaxIndex() ?  1 : ""
all the same
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 04:16

@swagfag
A.mazing..
T.hanks Lot..
teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 07:15

swagfag wrote:
14 Jan 2019, 03:25

Code: Select all

    (k > clipArr.MaxIndex() && k := 1)
     k > clipArr.MaxIndex() ?  k := 1
k := k > clipArr.MaxIndex() ?  1 : ""
all the same
Not complitly.
See:

Code: Select all

clipArr := [1, 2, 3]
k := 2
(k > clipArr.MaxIndex() && k := 1)
MsgBox, % k

k := 2
k := k > clipArr.MaxIndex() ?  1 : ""
MsgBox, % k
As for this

Code: Select all

k > clipArr.MaxIndex() ?  k := 1
IMO this is semantically incorrect use of the ternary operator.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 07:21

incorrect use of the ternary operator
It is invalid, it currently yields silent failure in v1, in v2 you get a load time error :thumbup: .
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 07:52

hmmmm

Guys
I am not good at new (for me) 'ternary' statement
Of course I am good at old (for me) 'ternary' operator
Have a nice talking.

One thing, @teadrinker
thanks for your code
I just tested
It is not working
I do not know, Guess I did something wrong..

If I had some leisure time
I will post it in detail
At the moment..
I am kind of busy

regards

Just attach the codes I used;

Code: Select all

clipArr := []
k := 1

1:: 
Clipboard := ""
Sleep, 33
clipArr.Push(SaveClipboard())
SoundBeep
Return

2::
If !clipArr[1]
      Return
SetClipboardData( clipArr[k++] )
(k > clipArr.MaxIndex() && k := 1)
SendInput, ^v
SoundBeep
Return
teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: an Array of "ClipboardAll" contents

14 Jan 2019, 08:10

The call of clipArr.Push(SaveClipboard()) doesn't put data into Clipboard, it only saves data which is currently present in Clipboard. You need to add

Code: Select all

Send ^c
ClipWait, 1, 1
before.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], marypoppins_1 and 187 guests