AutoHotkey Community

It is currently May 26th, 2012, 7:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: May 5th, 2009, 5:45 am 
Offline

Joined: March 25th, 2007, 7:55 am
Posts: 52
Location: northwest USA
I am trying to figure out how I can make something like
"SendInput, %MyTestVariable% work.

Here is a small experiment that I wrote that seems to select everything in my application instead of printing out the variable contents:

Quote:
:O:testme::
WinWait, ahk_class OpusApp
IfWinNotActive, ahk_class OpusApp, WinActivate, ahk_class OpusApp
WinWaitActive, ahk_class OpusApp
ClipSaved := ClipboardAll ;assign contents of clipboard to variable ClipSaved
clipboard = `[teststring`]`[url`=%clipboard%`]
TestVariable := ClipboardAll

SendInput, %TestVariable%
Clipboard := ClipSaved
return


The line "SendInput, %TestVariable%" is where everything seems to fall apart.

Any help would be appreciated.

_________________
Regards,

Alan Stancliff
My Web Site


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 5th, 2009, 7:22 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
What is the output from this in your code:

Code:
SendInput, %TestVariable%



Compared to what you were putting into the variable (or were supposed to be putting into the variable anyway)?

And I believe you could condense a step in that process that would also allow you to omit two other steps:

Code:
:O:testme::
WinWait, ahk_class OpusApp
IfWinNotActive, ahk_class OpusApp, WinActivate, ahk_class OpusApp
WinWaitActive, ahk_class OpusApp
;ClipSaved := ClipboardAll
TestVariable = `[teststring`]`[url=%clipboard%`]
SendInput, %TestVariable%
;Clipboard := ClipSaved
return

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2009, 10:20 am 
Offline

Joined: March 25th, 2007, 7:55 am
Posts: 52
Location: northwest USA
I've simplified this a bit further to try to sharpen up my question.

If I run this code:
Code:
:O:testme::
testvariable = this is a test
sendinput, %testvariable%
Return

and then type the trigger word "testme," what I get is the phrase "this is a test." This is what I would expect.


But if I change line 2 so that the code looks like this:
Code:
:O:testme::
testvariable := ClipboardAll
sendinput, %testvariable%
Return

and then cut my name "Alan" to the clipboard and type out my triggerword "testme," I get a tab and the letter À. I also get the same result when I type the word "Baloney."

So what's going on? What's getting assigned to "testvariable"? Is it the contents of the clipboard as I expected? If so, why aren't the contents being sent to the word processor when the line
Code:
sendinput, %testvariable%
runs?

Any help is appreciated.

_________________
Regards,

Alan Stancliff
My Web Site


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2009, 1:47 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Use Clipboard instead of ClipboardAll :!:

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2009, 2:38 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
HotKeyIt wrote:
Use Clipboard instead of ClipboardAll :!:


I was wondering the exact same thing...

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2009, 6:48 pm 
Offline

Joined: March 25th, 2007, 7:55 am
Posts: 52
Location: northwest USA
Hey HotKeyIt and SinkFaze

Thanks for the help. It is much appreciated That seems to have solved the problem.

I am still puzzled about something though.

In the online documentation, it says this:
Quote:
ClipboardAll contains everything on the clipboard (such as pictures and formatting). It is most commonly used to save the clipboard's contents so that the script can temporarily use the clipboard for an operation. When the operation is completed, the script restores the original clipboard contents as shown below:

Code:
ClipSaved := ClipboardAll   ; Save the entire clipboard to a variable of your choice.



So I still wonder what is getting put into my test variable with ClipboardAll, given that what I'm cutting is a line of text in my word processor.

_________________
Regards,

Alan Stancliff
My Web Site


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2009, 9:19 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I'm guessing this is the pertinent information a little further down the page:

Variables to which ClipboardAll has been assigned are in binary format and thus will appear as gibberish when displayed with MsgBox or similar.


SendInput would be attempting to display the contents of the variable the same as MsgBox would, hence the gibberish.

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2009, 10:07 pm 
Offline

Joined: March 25th, 2007, 7:55 am
Posts: 52
Location: northwest USA
sinkfaze wrote:
I'm guessing this is the pertinent information a little further down the page:

Variables to which ClipboardAll has been assigned are in binary format and thus will appear as gibberish when displayed with MsgBox or similar.


SendInput would be attempting to display the contents of the variable the same as MsgBox would, hence the gibberish.


Yup, SinkFaze,

That makes perfect sense.

Thanks for the feedback.

_________________
Regards,

Alan Stancliff
My Web Site


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 6th, 2009, 10:45 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Perhaps you've already figured out some of this, but I'd like to clarify a few things.

Since your original example doesn't "paste" before restoring the previous clipboard contents, you probably didn't need to assign to the clipboard at all:
Code:
:O:testme::
WinWait, ahk_class OpusApp
IfWinNotActive, ahk_class OpusApp, WinActivate, ahk_class OpusApp
WinWaitActive, ahk_class OpusApp

SendInput, `[teststring`]`[url`=%clipboard%`]
return
Sometimes (especially for large text) assigning to the clipboard and "pasting" is faster than sending the individual keystrokes with SendInput:
Code:
:O:testme::
WinWait, ahk_class OpusApp
IfWinNotActive, ahk_class OpusApp, WinActivate, ahk_class OpusApp
WinWaitActive, ahk_class OpusApp

ClipSaved := ClipboardAll ;assign contents of clipboard to variable ClipSaved
Clipboard = `[teststring`]`[url`=%clipboard%`]
SendInput, ^c
Clipboard := ClipSaved
return
The "WinWait" part of your script looks like something generated by AutoScriptWriter, but since it is missing a comma, WinActivate, ahk_class OpusApp is interpreted as the WinText parameter of IfWinNotActive rather than an actual command. If that part of the script is even necessary, it can be written more efficiently (and correctly):
Code:
WinWait, ahk_class OpusApp
IfWinNotActive ; Less error-prone than "IfWinNotActive,,, WinWaitActive"
    WinActivate
WinWaitActive
Quote:
So I still wonder what is getting put into my test variable with ClipboardAll, given that what I'm cutting is a line of text in my word processor.
Your word processor probably puts numerous formats on the clipboard - for instance: text, rich-text, HTML and the word processor's own format. ClipboardAll contains not only the data on the clipboard, but all required information, such as the format of each piece of data and the number of formats available.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, dmg, hd0202, krajan, over21, RaptorX, Xx7 and 63 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