Some interesting errors when defining hotkeys (v2.0-a111-06d0a13b, latest update) Topic is solved

Discuss the future of the AutoHotkey language
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Some interesting errors when defining hotkeys (v2.0-a111-06d0a13b, latest update)

19 Jun 2020, 01:06

*note: don't pay attention to the specific line, the entire code snippet only contained a #SingleInstance at top of script and then code snippet below that.

What I'm interested in is:

1: Why does Example 6 let the script successfully run, but not with Example 3?

2: Why does Example 3 throw a different error than Example 7?

3: Why does Example 8 let the script successfully run, but not with Example 7?

4: Why does Example 2 not let the script successfully run?

5: Why does Example 7 have a line of Exit in the debugger readout, but not in any other errors shown below?


I'm wondering why the inconsistencies and what the final verdict on how these will be able to be used in scripts? I do this this new direction of defining hotkeys with the curly braces.


I personally like this ability to put the curly bracket after the double-colons in my hotkey definition as it feels more like a function definition.

Code: Select all

like this e.g.:

#x::{
; code here
; code here
}



...okay, now some examples of what is working and what is not:

Example 1: this works

Code: Select all

#x::MsgBox( "test" )



Example 2: this code below throws the following error

Code: Select all

#x::{ MsgBox( "test" ) }

Code: Select all

Error:  This line does not contain a recognized action.

Specifically: { MsgBox( "test" ) }

	Line#
--->	003: {




Example 3: this code below throws the following error

Code: Select all

#x
#y::{ 
	MsgBox( "test" ) 
}

Code: Select all

Error at line 6.

Line Text: #x
Error: This line does not contain a recognized action.



Example 4: this works

Code: Select all

#x
#y::
{ 
	MsgBox( "test" ) 
}



Example 5: this works

Code: Select all

#x::
{ 
	MsgBox( "test" ) 
	MsgBox( "test" ) 
}



Example 6: this works

Code: Select all

#x::{ 
	MsgBox( "test" ) 
	MsgBox( "test" ) 
}



Example 7: this code below throws the following error

Code: Select all

NumpadHome::
NumpadEnd::
NumpadClear::
NumpadPgDn::
NumpadPgUp::
NumpadDel::
NumpadIns::{
	!GetKeyState( "NumLock", "T" ) ? MsgBox( "TURN ON NUMPAD", "NumLock Warning", "IconX T1" ) : ""
}

Code: Select all

Error:  Missing "key:" in object literal.

	Line#
	012: {
--->	012: { !GetKeyState( "NumLock", "T" ) ? MsgBox( "TURN ON NUMPAD", "NumLock Warning", "IconX T1" ) : "" }
	012: }
	013: Exit




Example 8: this works

Code: Select all

NumpadHome::
NumpadEnd::
NumpadClear::
NumpadPgDn::
NumpadPgUp::
NumpadDel::
NumpadIns::
{
	!GetKeyState( "NumLock", "T" ) ? MsgBox( "TURN ON NUMPAD", "NumLock Warning", "IconX T1" ) : ""
}
-TL
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Some interesting errors when defining hotkeys (v2.0-a111-06d0a13b, latest update)

19 Jun 2020, 01:37

Example 4 shouldn't work, example 7 should work. The other works or fails as expected. Based on what you wrote that is, I didn't run your code as I am AFK.

Example 3 and 4, Hotkeys should require ::, even when stacking.

Example 2,
blocks wrote: a statement may exist to the right of a brace (except the open-brace of the One True Brace style)
Edit, I guess 7 doesn't work due to
Continuation prefix: A line that starts with a comma or any other expression operator (except ++ and --) is automatically merged with the line directly above it
Cheers.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Some interesting errors when defining hotkeys (v2.0-a111-06d0a13b, latest update)  Topic is solved

19 Jun 2020, 02:31

I looked into it, the behaviour of example 7 is not unique for hotkeys, for example,

Code: Select all

if x {
	!GetKeyState( "NumLock", "T" ) ? MsgBox( "TURN ON NUMPAD", "NumLock Warning", "IconX T1" ) : ""
}
will fail similarly. It is due to expression operator !, at the beginning of the line, causing it to be merged with the line above. You can work around by enclosing the expression in (), for example.

Example 4, does yield an error, contrary to your statment.

Seems everything works as expected :thumbsup:

Cheers.
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Some interesting errors when defining hotkeys (v2.0-a111-06d0a13b, latest update)

19 Jun 2020, 19:37

Helgef wrote:
19 Jun 2020, 02:31
I looked into it, the behaviour of example 7 is not unique for hotkeys, for example,

Code: Select all

if x {
	!GetKeyState( "NumLock", "T" ) ? MsgBox( "TURN ON NUMPAD", "NumLock Warning", "IconX T1" ) : ""
}
will fail similarly. It is due to expression operator !, at the beginning of the line, causing it to be merged with the line above. You can work around by enclosing the expression in (), for example.

Example 4, does yield an error, contrary to your statment.

Seems everything works as expected :thumbsup:

Cheers.
Helgef,

Thanks for the explanation!

I must've been tired when i posted examples 3 and 4 last night. But this all makes sense. Thanks.
-TL

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 27 guests