Trouble getting first AHK V2 script working

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Trouble getting first AHK V2 script working

04 May 2024, 20:09

I have zillions of text shortcuts.
I have a massive file in V1.
I'm having trouble making work in V2.

This is what I have so far:

Code: Select all

::]ahk::
{
	tempClipboard := Clipboard
	Clipboard = 
	(
		#NoEnv ; Recommended setting for new AHK scripts. Makes sure AHK doesn't access empty variables.

		#SingleInstance force
		;===============================
		/*
		Put code details here.

		*/
		;===============================
		MsgBox, ,, AutoHotKey ##`%A_ScriptName`%## now loaded and ready to be used, 1.5

		; Start coding in the line below.
		^#F9::

		MsgBox Hey, there my first kinda function!

		Return

		^#F10::Reload ;<- Windows Key + F10 causes the script to reload itself

		^#F11::

		MsgBox, ,, AutoHotKey ##`%A_ScriptName`%## Code about to close, 2.5
		ExitApp ;<- Exit the app

		Return
	)

	SendInput ^v
	Sleep 200
	Clipboard := tempClipboard
	Return
}
When I want to create a new AHK file, I type ]ahk
And I get a ready made template.

What is wrong with what I have above?
Works OK in V1.

Thanks.
User avatar
mikeyww
Posts: 27200
Joined: 09 Sep 2014, 18:38

Re: Trouble getting first AHK V2 script working

04 May 2024, 20:12

Hello,

You are going to have to use v2 syntax for v2 scripts.

Read here: https://www.autohotkey.com/docs/v2/lib/A_Clipboard.htm

V2 uses expressions throughout, so you'll need to translate most of your statements into v2 syntax. The documentation shows you examples of nearly all of the v2 functions and statements.
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Re: Trouble getting first AHK V2 script working

04 May 2024, 20:36

Thanks

I've looked at the link you gave and came up with this to test:

Code: Select all

::]ahk::
{
	tempClipboard := ClipboardAll() 

    A_Clipboard := "
    (Join`s
        This text is placed on the clipboard,






        and will be pasted below by sending Ctrl+V.
    )"
	
	SendInput "^v"
	Sleep 200
	A_Clipboard := tempClipboard
}
The output comes out on one single line

What am I doing wrong?

Thanks
User avatar
mikeyww
Posts: 27200
Joined: 09 Sep 2014, 18:38

Re: Trouble getting first AHK V2 script working

04 May 2024, 20:46

What made you decide upon this code?

Code: Select all

Join`s
What is your belief about what it does?

Have you read the documentation section about it?
JoinString: Specifies how lines should be connected together. If this option is not used, each line except the last will be followed by a linefeed character (`n). If String is omitted, lines are connected directly to each other without any characters in between. Otherwise, specify for String a string of up to 15 characters. For example, Join`s would insert a space after each line except the last. Another example is Join`r`n, which inserts CR+LF between lines. Similarly, Join| inserts a pipe between lines. To have the final line in the section also ended by String, include a blank line immediately above the section's closing parenthesis.
Source: Scripts - Definition & Usage | AutoHotkey v2
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Re: Trouble getting first AHK V2 script working

04 May 2024, 21:01

>> What made you decide upon this code?
Oh :)
I used what they had on the example code they gave
I didn't read what it said

I now have:

Code: Select all

::]ahk::
{
	tempClipboard := ClipboardAll() 

    A_Clipboard := "
    (
        This text is placed on the clipboard,






        and will be pasted below by sending Ctrl+V.
    )"
	
	SendInput "^v"
	Sleep 200
	A_Clipboard := tempClipboard
}
That works fine

I did loooads of googling and asked ChatGPT and Gemini - couldn't find the answer - until you pointed it out

Thanks

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Albireo, gekunfei, Ragnar and 52 guests