AutoHotkey Community

It is currently May 26th, 2012, 5:45 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: April 23rd, 2009, 1:32 am 
Forgive me, I'm new.

I'm trying to create hotstring auto replace that instead of typing uses clipboard and paste, which is more compatible with the software I'm using.

Also, returns are ignored so I have to have to separate the code in two or more parts with sendinput for the enter key in between pasting the code

Though, I'm having an issue where it oddly only uses the last clipboard = command for every instance of paste.

So here's a simple example of what I want to do

Code:
::HK-REF-::
clipboard = [ref]Xxxxxxxx xxxxxxxxx xxx xxxxxxx.
SendInput ^v
SendInput {Enter}
clipboard = <MC>Page X-X.
SendInput ^v
SendInput {Enter}
Return


Where most the time in Notepad, after I type special letters, instead of:

[ref]Xxxxxxxx xxxxxxxxx xxx xxxxxxx.
<MC>Page X-X.

I get:
<MC>Page X-X.
<MC>Page X-X.

If I add...
clipboard =
clipwait 0.5
...to the begining, it works in Notepad, but not in the software I need, it still repeats the last clipboard = text. Even if I create a new code, with random text to be pasted, it uses the last clipboard = for both paste. How is that possible? It's like it's going out of order. How can the ^v paste text that it shouldn't have ever sent to clipboard. Unless it happens the moment I launch script. Again, I'm new to this.

Or is there a way to send text to the clipboard and not lose returns?

[ Moderator!: Moved from Scripts and Functions ]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 1:33 am 
Dang it, sorry, I thought I was in the Ask For Help section


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 4:46 am 
Nevermind, this worked for me:

Code:
::HK-REF1-::
clipboard = [ref]Xxxxxxxx xxxxxxxxx xxx xxxxxxx.`r`n<MC>Page X-X.`r`n
SendInput ^v
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 6:16 am 
TimothyB wrote:
Dang it, sorry, I thought I was in the Ask For Help section

Enough said? ;)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 6:40 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5479
Location: the tunnel(?=light)
I'm glad you got it fixed, but I'll tell you what I think is happening anyway:

Code:
::HK-REF-::
clipboard = [ref]Xxxxxxxx xxxxxxxxx xxx xxxxxxx.
SendInput ^v
SendInput {Enter}
clipboard = <MC>Page X-X.
SendInput ^v
SendInput {Enter}
Return


You're pushing one set of data to the clipboard, sending Ctrl+v to paste, then sending new data to the clipboard and pasting again. AHK sends the Ctrl+v keystrokes only, it doesn't wait for the end program to recognize that it's being sent Ctrl+v and thus paste the data; it continues to work. So while the end program may have a slight delay in recognizing the Ctrl+v command, AHK has kept working and has already gotten to this point:

Code:
clipboard = <MC>Page X-X.


Before the program pastes the clipboard the first time. Hence you end up with that string being pasted twice.

The simplest way to work around that is to put a small Sleep period after the Ctrl+v command so AHK will wait briefly (hopefully long enough for the end program to catch up) and continue:

Code:
::HK-REF-::
clipboard = [ref]Xxxxxxxx xxxxxxxxx xxx xxxxxxx.
SendInput ^v
Sleep, 300
SendInput {Enter}
clipboard = <MC>Page X-X.
SendInput ^v
Sleep, 300
SendInput {Enter}
Return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 12:40 am 
Offline

Joined: March 5th, 2009, 7:59 pm
Posts: 23
I think I have similar problem with clipboard. Waiting 0,3s is a bit long.
Now I'm testing this to solve the problem:
Code:
clipboard=
clipboard=newcontent
ClipWait

Does it have any chance to solve the problem? Or - how does ClipWait work?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 2:35 am 
daroc,

I think clipwait will do nothing in your situation.

the clipboard is being updated very quickly by AHK, so quickly, in fact, that it is not waiting for the target program to "realize" that it has been sent the control-v, before AHK changes the clipboard.

the most sensible solution is to put together everything that needs to be "pasted" and paste it all at once; use `r`n for line breaks just as seen in timothyb's post.

you can add text to the clipboard using
clipboard .= "text to add goes inside quotation marks here because it is an expression"[/code]


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, BrandonHotkey, G. Sperotto, gamax92, Google Feedfetcher, Miguel, notsoobvious, rbrtryn and 74 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