AutoHotkey Community

It is currently May 27th, 2012, 3:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: March 20th, 2010, 2:31 am 
Offline

Joined: November 4th, 2008, 10:25 pm
Posts: 222
Location: Memphis, TN
Can anyone tell me why the clipboard data is not being returned and stored in this code?
Code:
^1::
   Clip_1 := Clip_Catch()
   Return

!1::
   Clip_Send(Clip_1)
   Return

Clip_Catch() {
   
   cliphold = %clipboardall%
   Clipboard =
   SendInput, ^c
   ClipWait, 10, 1
      if errorlevel
         {
            MsgBox clip error
         }
   MsgBox %clipboard%
   Temphold = %clipboardall%
   Clipboard = %Cliphold%
   cliphold =
   Return Temphold
}

Clip_Send(var) {

   if var
      {
         cliphold = %clipboardall%
         Clipboard = %var%
         ClipWait, 10, 1
            if errorlevel
               {
                  MsgBox clip error
               }
         SendInput, ^v
         sleep, 200
         Clipboard = %Cliphold%
         cliphold =
      }
   Else
      {
         MsgBox no value
      }
}


If i write this code outside of a function it works perfectly. Do i have a syntax error that i don't see?

Thanks so much for the help! :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 20th, 2010, 7:23 am 
Code:
^1::
        Clip_1 := Clip_Catch()
         tooltip, % "Clip1: " Strlen(Clip_1),50,50, 2
          Return
!1::
   Clip_Send(Clip_1)
   Return

Clip_Catch() {
   
   cliphold = %clipboardall%
   Clipboard =
   SendInput, ^c
   ClipWait, 10, 1
      if errorlevel
         {
            MsgBox clip error
         }
   MsgBox %clipboard%
/*  This is the line that is causing the failure
   Temphold = %clipboardall%
     you can use either
         Temphold = %clipboard%  ; <- this may alter the contents due to auto-trim
     or preferably
         Temphold := clipboard ; <- this avoids any auto-trim action
*/
         Temphold := clipboard ; <- tested and it works
         tooltip, % "Temphold: " Strlen(Temphold),20,20, 1
   Clipboard = %Cliphold%
   cliphold =
   Return Temphold
}

Clip_Send(var) {

   if var
      {
         cliphold = %clipboardall%
         Clipboard = %var%
         ClipWait, 10, 1
            if errorlevel
               {
                  MsgBox clip error
               }
         SendInput, ^v
         sleep, 200
         Clipboard = %Cliphold%
         cliphold =
      }
   Else
      {
         MsgBox no value
      }
}

The problem (as colored in the above code) is that when you assign clipboardall to a variable, it in essence becomes a "special" binary variable containing all the clipboard inforamtion (including markers for the type of data) which cannot be passed in the return statement.

Quote:
Variables to which ClipboardAll has been assigned are in binary format and thus will appear as gibberish when displayed with MsgBox or similar. Also, altering a binary-clipboard variable (by means such as StringReplace) will revert it to a normal variable, resulting in the loss of its clipboard data.
This is what is happening when you Return Temphold. If you really need true clipboardall contents (but I see no reason, as you are then using SendInput...), you could declare Temphold as global variable that you could then access outside the function.

I placed a couple of tooltips in the above to see the size of the vars.
Quote:
StringLen may be used to discover the total size of a variable to which ClipboardAll has been assigned.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 10:53 am 
Offline

Joined: November 4th, 2008, 10:25 pm
Posts: 222
Location: Memphis, TN
Thank you so much alhab.

I knew I was missing some single line in the help file. :lol:

ps: I do need the full contents of the clipboard as i am just using the windows clipboard as a catalyst to get this data out of AHK by means of sending a paste.

Again, thank you so much.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn and 29 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group