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 

'send ^v' does not always paste correct clipboard contents

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



Joined: 01 Apr 2009
Posts: 68

PostPosted: Wed Apr 01, 2009 7:58 pm    Post subject: 'send ^v' does not always paste correct clipboard contents Reply with quote

Im seeing some strange behavior trying to automate a paste operation to send a large volume of text at once. I am using essentially

Code:

Clipboard = [LARGE TEXT]
Send ^v


and seeing the text that is pasted is not the text I assigned to clipboard, rather the previous contents of the clipboard. To clarify, more code; I have created the following method included in my library:

Code:

SendClip(output)
{
   ClipBackup = %ClipboardAll%
   clipboard =
   success = 0
   
   Sleep 100
   clipboard = %output%
   
   ;ClipWait, 2
   ;if (ErrorLevel = 0)
   ;{
   ;   success = 1
   ;}
   
   Loop
   {
      Sleep 100
      if (clipboard = output)
      {
         success = 1
         break
      }
      if (A_Index > 20)
      {
         break
      }
   }
   
   if (success)
      SendInput ^v
      
   clipboard = %ClipBackup%
   ClipBackup =   
   return %success%
}


You can see that I had originally tried using the recommended ClipWait, but switched to a loop process to try ensure that the contents of the clipboard are the text i intend to send. This loop is breaking with success = 1, despite the fact that when I 'Send ^v' the wrong text is pasted. Every once in a while, i'll get the correct paste. I've tried to 'FileAppend' the current contents of the clipboard to a file just before sending ^v to manually double check the value, and it always seems correct.

It looks like windows isn't being given the latest value of the clipboard at assignment time, but internally 'clipboard' evaluates to its correct assigned value. This would explain why AHK thinks everything is correct, but when i try to do a system paste, the value is incorrect.

Has anyone run into this or have any ideas? Are there any better methods for sending large volumes of text at once, without using the clipboard and without waiting for 'Send' to send the keystrokes individually?
Back to top
View user's profile Send private message
sinkfaze n-l-i
Guest





PostPosted: Wed Apr 01, 2009 8:25 pm    Post subject: Reply with quote

Try this:


Code:
SendClip(output)
{
   ClipBackup = %ClipboardAll%
   clipboard =
   success = 0
   
   Sleep 100
   clipboard = %output%
   
   ;ClipWait, 2
   ;if (ErrorLevel = 0)
   ;{
   ;   success = 1
   ;}
   
   Loop
   {
      Sleep 100
      if (clipboard = output)
      {
         success = 1
         break
      }
      if (A_Index > 20)
      {
         break
      }
   }
   
   if (success)
      SendInput ^v
   Sleep, 300   
   clipboard = %ClipBackup%
   ClipBackup =   
   return %success%
}
Back to top
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