Example code on AHK website

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Example code on AHK website

28 Jun 2017, 15:40

Just noticed the second example on the AHK home page is this:

Code: Select all

 ; copy text to the clipboard, modify it, paste it back
  ^+k:: ; ctrl-shift-k
  ClipSave:=ClipboardAll ; store current clipboard
  Send ^c ; copy selected text
  clipboard:="<i>" clipboard "</i>" ; wrap it in html-tags
  Send ^v ; paste
  Clipboard:=ClipSave ; restore old clipboard content
  ClipSave:="" ; clear variable
  Return
This does not even work. But this does:

Code: Select all

 ; copy text to the clipboard, modify it, paste it back
  ^+k:: ; ctrl-shift-k
  ClipSave:=ClipboardAll ; store current clipboard
  Send ^c ; copy selected text
  clipboard:="<i>" . clipboard . "</i>" ; wrap it in html-tags **Needs "." to concatenate!?
  Send ^v ; paste
  Clipboard:=ClipSave ; restore old clipboard content
  ClipSave:="" ; clear variable
  Return
FWIW
try it and see
...
Guest

Re: Example code on AHK website

28 Jun 2017, 16:32

The . are not required and can be omitted as mentioned in the docs
variables wrote:Concatenate. The period (dot) operator is used to combine two items into a single string (there must be at least one space on each side of the period). You may also omit the period to achieve the same result (except where ambiguous such as x -y, or when the item on the right side has a leading ++ or --). When the dot is omitted, there should be at least one space between the items to be merged.
Source: https://autohotkey.com/docs/Variables.htm
At first I used the . but after a while you get used to it and omit them, saves valuable time in coding :lol:
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Example code on AHK website

28 Jun 2017, 16:39

AHK auto concatenates (.) are not needed in expression syntax when joining strings and variables but does require spaces.

That example should be using Clipwait after sending ^c to make it reliable.

I do prefer using (.) when joining strings and variables for readability.

my 2c
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: Example code on AHK website

28 Jun 2017, 19:45

Well, than I was wrong. I had tried the code without, and it didn't work. I added the (.)'s, and it worked. I'll have to try that again...
try it and see
...
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Example code on AHK website

29 Jun 2017, 00:56

this to me is a more reliable version of that example but may take up to meny lines for the frontpage

Code: Select all

 ; copy text to the clipboard, modify it, paste it back
^+k:: ; ctrl-shift-k
ClipSave:=ClipboardAll ; store current clipboard
clipboard := "" ; Clear the current clipboard (empty)
Send ^c ; copy selected text
Clipwait, 1 ; wait up to one second for the clipboard to NOT be empty
if (ErrorLevel) { ; check If the wait period expires.
    Clipboard := ClipSave ; restore old clipboard content
    ClipSave := "" ; clear the storing variable
    return ; return ( do nothing more )
} ; it did get data so continue from here...
clipboard:="<i>" clipboard "</i>" ; wrap it in html-tags
Send ^v ; paste
sleep 200 ; give the program time to process the ctrl+v pasting action
Clipboard:=ClipSave ; restore old clipboard content
ClipSave:="" ; clear variable
Return
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, RandomBoy, Rohwedder and 345 guests