Variable not keeping value between hotkeys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
erose524

Variable not keeping value between hotkeys

13 Dec 2017, 13:01

(I asked the same question before, but I'm going to rephrase it better)

I'm trying to write a program that will save your mouse position to a file after you hit a specific hotkey, and then have another bit of code that reads the file and moves the mouse to each position listed in the file, and clicks. I've got most things working but I've run into an issue. Everytime you hit the first hotkey I mentioned, want I want to happen is a variable adds 1 to its self (used later in the code) but when I call on the variable in the second hotkey, the variable is blank. How do I fix this issue?
Here is the code so far.
Spoiler
Can someone tell me what I'm doing wrong? I'm very new to this program, and there is most likely an obvious solution. Please help.
John316
Posts: 13
Joined: 15 Dec 2017, 08:53

Re: Variable not keeping value between hotkeys

15 Dec 2017, 13:28

I'm not sure why this works but it seems the Spress variable needs to be Global in the Dkey() function. This worked for me...

Code: Select all

s::SKey()
d::DKey()

SKey(){
Global SPress += 1
MsgBox, %SPress%
MouseGetPos, xpos, ypos 
FileAppend, 
(
%xpos%

), Xcords.txt

FileAppend, 
(
%ypos%

), Ycords.txt
}


DKey(){
Global SPress 	;<--- I added this line here
Loop, %SPress%
{
Global DLine += 1
FileReadLine, cordX, Xcords.txt, %DLine%
FileReadLine, cordY, Ycords.txt, %DLine%
MouseMove, %cordX%, %cordY%, 5
}

}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb and 299 guests