Click is not a function? Topic is solved

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
Posts: 3
Joined: 31 Jul 2020, 19:46

Click is not a function?

31 Jul 2020, 21:15

Hey folks! I'm switching from v1 to v2 because v1's syntax has been killing me for years now.

I'm currently in the process of rewriting the code and it looks many times better in v2: so much easier to use.

For now, it reminds me of Ruby, which is not the best syntax ever, but it's a lot better than ahk v1.

Anyhow, the question. I expect Click to be a function, accepting args as any function out there, but it refuses to behave like one.

I expect this to work:

Code: Select all

Click(W4Coords[1]+40, W4Coords[2]+40, 1)
instead, it does nothing. It requires me to either concat everything into one string, separating by ugly spaces or just skip the parentheses. I know they're optional, but they make code a lot more readable.

Another question is about string concat. Why demanding spaces around .? Effetively, you're making people use three chars for concat instead of one. Annoying. If dot is a problem, can we have an alias so that instead of using three chars, we could use one + for example?
Posts: 7185
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Click is not a function?  Topic is solved

01 Aug 2020, 00:58

Click is a function, and accepts args just as you show (or concatenated). For me, the following clicks on the first tab in SciTE. I do not see how your example could do nothing; if the array elements were not valid numbers, it would throw an exception. Otherwise, you should see the mouse move even if the coords are outside screen bounds, unless the mouse happens to already be at the destination.

Code: Select all

W4Coords := [0, 0]
Click(W4Coords[1]+40, W4Coords[2]+40, 1)
Some possibilities:
  • UAC could cause Click to do nothing if you use SendMode "Play" or the active window is running as admin, but it would not matter whether you concatenate the parameters or pass them separately.
  • Maybe this line in your script is not being executed (e.g. the required conditions weren't met, or a hotkey failed to work for whatever reason).
  • Maybe this version of your script was not executed (e.g. you forgot to save and/or reload, or an older version of the script was also running and somehow took precedence).
  • Maybe there is a bug in whatever AutoHotkey version you used. I tested with v2.0-a119.
  • Maybe some other program interfered, and by coincidence did not when you concatenated the parameters.

The topic of concatenation has come up a few times, and I currently have no intention of changing it. I am more likely to implement some form of string interpolation.

x.y is member access, in AutoHotkey and many common languages (although I think the concatenation operator came from PHP, which uses -> for member access). + is addition, and permits numeric strings. If you want to use just one character, use auto-concat (just use a space; however, sometimes the dot operator or parentheses are required, such as when concatenating with a unary operator). In some instances, Format might be more readable.

Return to “AutoHotkey v2 Help”

Who is online

Users browsing this forum: No registered users and 2 guests