| View previous topic :: View next topic |
| Would such a variable be useful to you? |
| No, I'd rather always use clipboard variables |
|
33% |
[ 1 ] |
| Yes, it would be more efficient |
|
66% |
[ 2 ] |
|
| Total Votes : 3 |
|
| Author |
Message |
instantrunoff
Joined: 13 Jan 2008 Posts: 63
|
Posted: Mon Apr 21, 2008 12:41 am Post subject: New Variable for Selected Content in Foremost Window |
|
|
It would be nice to have a variable such as A_Highlighted that would allow replacing the following:
| Code: |
>!k:: ; Look selection up in Wikipedia
gosub backupclip
Run, http://en.wikipedia.org/wiki/Special:Search?search=%Clipboard%
gosub restoreclip
Return
backupclip:
ClipSaved := ClipboardAll ; Save the entire clipboard to a variable of your choice.
clipboard = ; clear clipboard
Send, ^c
ClipWait, 1
IfEqual, ErrorLevel, 0
return
else
{
gosub restoreclip
exit
}
restoreclip:
Clipboard := ClipSaved ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved = ; Free the memory in case the clipboard was very large.
return
|
With something like this:
| Code: | | >!k::Run http://en.wikipedia.org/wiki/Special:Search?search=%A_Highlighted% |
I think for the A_Highlighted variable to be more reliable and refer to the foremost window that might not be active, there might have to be fancier coding that the above AHK workaround.
Last edited by instantrunoff on Mon Apr 21, 2008 1:38 pm; edited 2 times in total |
|
| Back to top |
|
 |
Spymaster101
Joined: 22 Mar 2008 Posts: 2
|
Posted: Mon Apr 21, 2008 1:28 am Post subject: |
|
|
that actually sounds good, this would mean that there would be no need to copy it to the clipboard.  |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 753 Location: London, UK
|
Posted: Mon Apr 21, 2008 1:37 am Post subject: |
|
|
I think in the meantime a function wrapping the workaround would work best as this is used fairly regulary.
Something like.
| Code: | ^r::Run,% "http://www.google.co.uk/search?source=ig&hl=en&rlz=&q=" copyhighlighted()
copyhighlighted(){
Clipsaved:=ClipboardAll
Clipboard:=""
Send,^c
Clipwait,1
temp:=Clipboard
Clipboard:=Clipsaved
Return temp
} | *Untested
This would reduce code length in multiple calls, although I agree a hardcoded solution would probably work much better. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle
Last edited by Superfraggle on Mon Apr 21, 2008 10:33 pm; edited 1 time in total |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2359 Location: Australia, Qld
|
Posted: Mon Apr 21, 2008 9:19 am Post subject: |
|
|
| Spymaster101 wrote: | that actually sounds good, this would mean that there would be no need to copy it to the clipboard.  | In that case, how would A_Highlighted work? Copying to the clipboard is the most compatible method available.
| Superfraggle wrote: | | ...although I agree a hardcoded solution would probably work much better. | Other than allowing built-in variable syntax, how could it work better? |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 753 Location: London, UK
|
Posted: Mon Apr 21, 2008 6:51 pm Post subject: |
|
|
Lexicos, I just thought a hard coded version would allow for easier calling. I.e no need to force expression mode.
And I thought it would probably perform slightly faster. I was under the impression that the direct coding of such a feature would perform slightly quicker. Although I bow down to your greatness so correct me if im wrong  _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2359 Location: Australia, Qld
|
Posted: Mon Apr 21, 2008 10:13 pm Post subject: |
|
|
The inclusion of ClipWait makes it likely that both will perform very similarly. The overhead of six lines of script (and a function call) is negligible.
It would be more convenient and maybe faster, but not any more functional. It would still rely on ^c copying something to the clipboard. (Btw, maybe ClipWait should have a timeout...) |
|
| Back to top |
|
 |
|