AutoHotkey Community

It is currently May 26th, 2012, 4:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: April 1st, 2009, 8:58 pm 
Offline

Joined: April 1st, 2009, 8:32 pm
Posts: 71
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 9:25 pm 
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%
}


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], Miguel, notsoobvious, poserpro and 17 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