How to get mouse position properly on keypress with autohotkey Receiving <Invalid Hotkey> Error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RagingBurner
Posts: 1
Joined: 11 May 2021, 20:35

How to get mouse position properly on keypress with autohotkey Receiving <Invalid Hotkey> Error

11 May 2021, 20:40

This is my first autohotkey script, and I'm trying to link up two different windows of an art program, so that when I pan one canvas, it pans the other. I would like it to be as pixel precise as possible, but I'm getting an error on Line 1 that says it's an invalid hotkey, I've tried moving the commas around, but I'm not sure what I'm doing wrong.

Here is my code. for purposes, I'll explain the button combinations.

Space + L Mouse Button together lets me pan the canvas, I need to know where the cursor is when I release one or the other.

LCtrl + Numpad5 disables click through on WindowTop which I use to overlay with transparency one Canvas over the other.

LCtrl + Tab switches between the two canvasses in the app

Code: Select all

Space & LMButton::MouseStartX = 0,
MouseStartY = 0,
MouseEndX = 0,
MouseEndY = 0,
MouseGetPos [MouseStartX, MouseStartY],
Space UP || LMButton UP::MouseGetPos [MouseEndX, MouseEndY],
BlockInput, On,
LCtrl & Numpad5,
LCtrl & TAB,
MouseClickDrag, M, MouseStartX, MouseStartY, MouseEndX, MouseEndY
LCtrl & TAB,
LCtrl & Numpad5,
BlockInput, Off
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to get mouse position properly on keypress with autohotkey Receiving <Invalid Hotkey> Error

12 May 2021, 00:02

a) check out the difference between a single line hotkey and a multiple line hotkey-syntax
b) don't use a trailing comma if defining numeric variables
c) don't use a conditional || OR if you wanna use two hotkeys triggering the same code section (at least I'm not aware of that option)
d) don't add the square brackets that way (they are used at AHK's help indicating optional parameters for a command, or for Arrays)

Code: Select all

Space & LMButton::
	MouseStartX = 0
	MouseStartY = 0
	MouseEndX = 0
	MouseEndY = 0
	MouseGetPos, MouseStartX, MouseStartY
	ToolTip % MouseStartX . "`n" . MouseStartY
	Sleep 4000
	ToolTip
Return

Space UP::
LMButton UP::
	MouseGetPos, MouseEndX, MouseEndY
	MouseClickDrag, M, MouseStartX, MouseStartY, MouseEndX, MouseEndY
Return
	.
	.
	.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ConnorMcLoud and 182 guests