AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Clipboard data not returned in function

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
godsstigma



Joined: 04 Nov 2008
Posts: 222
Location: Memphis, TN

PostPosted: Sat Mar 20, 2010 1:31 am    Post subject: Clipboard data not returned in function Reply with quote

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! Smile
Back to top
View user's profile Send private message
alhab
Guest





PostPosted: Sat Mar 20, 2010 6:23 am    Post subject: Re: Clipboard data not returned in function Reply with quote

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.
Back to top
godsstigma



Joined: 04 Nov 2008
Posts: 222
Location: Memphis, TN

PostPosted: Sat Mar 20, 2010 9:53 am    Post subject: Reply with quote

Thank you so much alhab.

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

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group