GetKeyState

Ask gaming related questions (AHK v1.1 and older)
Nuarcad
Posts: 3
Joined: 17 Oct 2017, 03:02

GetKeyState

17 Oct 2017, 03:14

Hello, I have been trying, unsuccessfully, to make a speed clicker for idle games the likes of cookie clicker.
As I like to make my own code, I had been trying that at first, but as I quickly noticed that the AHK script language had many specifities I had never encountered so I quickly turned to seeking finished scripts.
I found such scrips, yet none worked the way I desired, and those that claimed they did, did not work at all.

Here is what I wanted : A script that clicks repeatedly on a loop, as I pressed "LButton"
After some messing around and re-writing code, I found out that GetKeyState didn't work properly for me.
If I write

while (GetKeyState("LButton","P"))
{
code here
}
Nothing triggers at all.

If however I enter
while (GetKeyState("LButton"))
{
code here
}

The code triggers Once.

Is my use of "While" wrong? Or am I right in assuming that the parameter "P" for detecting whether my Left Mouse Button is held down doesn't work?

Is there an alternative to GetKeyState?

Update: Might this be a driver issue? AHK is the only application where this is an issue, however:
If I use MButton as a trigger instead of LButton, it works perfectly. Wether using "P" or not.
Anyone have a clue about this?
Last edited by Nuarcad on 17 Oct 2017, 05:20, edited 1 time in total.
User avatar
Reloaded
Posts: 283
Joined: 25 Aug 2017, 08:48

Re: GetKeyState

17 Oct 2017, 05:11

Hi :)

Code: Select all

RButton::										;Enter here your Key 
    While GetKeyState("RButton", "P"){     				;And here again but let the "P" ! 
 
;Start here.									;Enter here your Code 
}
return
 
Hope it Help.
Nuarcad
Posts: 3
Joined: 17 Oct 2017, 03:02

Re: GetKeyState

17 Oct 2017, 05:22

Reloaded wrote:Hi :)

Code: Select all

RButton::										;Enter here your Key 
    While GetKeyState("RButton", "P"){     				;And here again but let the "P" ! 
 
;Start here.									;Enter here your Code 
}
return
Hope it Help.
Thank you for your reply, this is very close to what I ended up with.
As I just updated on my first post however, I am starting to suspect drivers to be involved, as the Middle mouse button seems to work just fine, but the left mouse button does not.
User avatar
Reloaded
Posts: 283
Joined: 25 Aug 2017, 08:48

Re: GetKeyState

17 Oct 2017, 05:26

Nuarcad wrote:
Reloaded wrote:Hi :)

Code: Select all

RButton::										;Enter here your Key 
    While GetKeyState("RButton", "P"){     				;And here again but let the "P" ! 
 
;Start here.									;Enter here your Code 
}
return
Hope it Help.
Thank you for your reply, this is very close to what I ended up with.
As I just updated on my first post however, I am starting to suspect drivers to be involved, as the Middle mouse button seems to work just fine, but the left mouse button does not.
Np for this im here :) head up !
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: GetKeyState

17 Oct 2017, 07:00

Starting your code with while (GetKeyState("LButton")) will produce intermittent results, depending on the state of the mouse button at the exact instant you run the script.
If it hits the first line when the mouse button is not pressed, it would do nothing. If it hits the line while the mouse button is pressed, it would enter the loop and not leave until the mouse button is released.
Nuarcad
Posts: 3
Joined: 17 Oct 2017, 03:02

Re: GetKeyState

17 Oct 2017, 07:48

I see, however any GetKeyState of the left button of my mouse seems compromised, whereas other keys works just fine. (Asides from the lack of parameters in the code if I don't check button state)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 70 guests