AutoHotkey Community

It is currently May 26th, 2012, 2:46 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: January 28th, 2009, 6:17 pm 
Offline

Joined: September 26th, 2008, 6:09 pm
Posts: 82
Location: France
I have, with Firefox, a script that use parts like :
.....................
clipboard = ; Start off empty
Send, {CTRLDOWN}c{CTRLUP}
ClipWait, 10 ; Wait 10 s for the clipboard to contain text.
..................
Do I need to add
Sleep, 100
(or other values) instructions before and/or after the Send instruction to leave time to AHK and Windows to process the clipboard ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2009, 6:30 pm 
Code:
clipboard =
send ^c
msgbox, %clipboard%

its an instant for me, no need sleep in between
(tested on 100 lines of text)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2009, 6:40 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
1. use code tags

Code:
clipboard = ; Start off empty
Send, {CTRLDOWN}c{CTRLUP}
ClipWait, 10 ; Wait 10 s for the clipboard to contain text.


;could be
Code:
clipboard = ; Start off empty
Send, ^c
ClipWait, 10 ; Wait 10 s for the clipboard to contain text.
if ErrorLevel
{
    MsgBox, The attempt to copy text onto the clipboard failed after 10 seconds.
;or do something else here if theres an error.
    return
}
;continue your code.

return


As per the delay questino after "send" to wait for ahk you dont need. ahk is fast

_________________
-=Raz=-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2009, 7:14 pm 
Offline

Joined: September 26th, 2008, 6:09 pm
Posts: 82
Location: France
1) Ok : " ahk is fast"
but is the processing of clipboard by Windows as fast ?
If Windows is too slow and try to empty the clipboard after AHK has filed it there is a problem ! Are the 2 separate process Windows and AHK interlocked ?

2)Send, ^c
is shorter than
Send, {CTRLDOWN}c{CTRLUP}
As I am lazy, this is very good ! Thanks...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2009, 7:19 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Also you can do something like this to preserve the clipboard's data:
Code:
ClipboardBackup := Clipboard ;or should it be ClipboardAll?
Clipboard =
Send ^c
Clipwait, 10
ClipboardData := Clipboard
Clipboard := ClipboardBackup
In this example ClipboardData contains the copied text and the windows clipboard is the same as before.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2009, 11:25 am 
Offline

Joined: September 26th, 2008, 6:09 pm
Posts: 82
Location: France
Frankie you are right :
ClipboardData := Clipboard
is a good precaution against the change of clipboard content by an other application.
BTW : is the clipboard variable of ahk common with Windows (e.g. a pointer to the Windows area) or a copy of it ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2009, 3:38 pm 
clipboard is a globe value, which means the whole computer read clipboard var as the same thing, so for example, u can do this:
Code:
clipboard = abc
send ^v


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2009, 6:27 pm 
Offline

Joined: September 26th, 2008, 6:09 pm
Posts: 82
Location: France
I think that you have partly missed my point :
If AHK directly write in the windows data area of the clipboard, all is fine. If AHK call a windows process (to write in the clipboard) that has a priority lower than AHK, AHK may execute its next instruction before the windows process has executed its job of putting "abc" in the clipboard in the previous example. In this case you are in trouble !
You need to know the source of AHK to answer...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2009, 7:30 pm 
all ahk commands are call to a system process in order to execute the window API function
so if u have worries on "saving a variable", then every single command is unreliable according to the trouble u suggest


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2009, 7:31 pm 
o forgot, u might be really interested in the ahk source
Here:
http://www.autohotkey.com/download/Auto ... source.exe


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2009, 7:49 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
AutoHotkey calls a function in the Win32 API, which should not return until the clipboard is set up. You should not need to sleep after setting the clipboard data.

Often the script will need to rest after sending Ctrl+C, since if it doesn't, the process you are sending Ctrl+C to won't have time to modify the clipboard. In some cases AutoHotkey might sleep automatically, but in this case it doesn't matter, as ClipWait will sleep until the clipboard has data. It is not necessary to use Sleep before ClipWait, as long as the timeout of ClipWait is sufficient.

However, you may need to Sleep after sending Ctrl+V before resetting the clipboard to its previous value. I found that on my old Athlon XP 3000+ (2.2GHz) it was not necessary, but after upgrading to a Core 2 Duo (2.4GHz), the script would frequently reset the clipboard before the other application had processed Ctrl+V.

This also depends on the method used: it happened more often than not with SendInput, but never with SendEvent or ControlSend. SendInput is otherwise my preferred method.
Quote:
all ahk commands are call to a system process in order to execute the window API function
On the contrary, some commands are implemented with C run-time functions (which may in turn use OS features), and a few others purely affect program logic, and do not use any Windows API. Additionally, I think nigelle was suggesting AutoHotkey might call an external process (i.e. an executable file), whereas in nearly every case AutoHotkey does not do this, so will not suffer from process priority issues. Commands like Run, Reload and Edit launch external processes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2009, 1:52 pm 
Offline

Joined: September 26th, 2008, 6:09 pm
Posts: 82
Location: France
Thanks Lexikos. This clarify my problems...
I'll add (solved) in the title of the post in few days.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: G. Sperotto, patgenn123 and 19 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