GetKeyState not working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Psyless
Posts: 2
Joined: 15 Dec 2017, 05:21

GetKeyState not working

15 Dec 2017, 05:31

The code isn't working when using a Send loop, so I can't use any modifier keys

Code: Select all

GetKeyState, ctrl, Ctrl
GetKeyState, shift, Shift
GetKeyState, alt, Alt


Loop
{
if (ctrl = D or alt = D or shift = D)
	{
	Modifier = 1
	}
else
	{
	Modifier = 0
	}
}
return
This is the Send loop

Code: Select all

Loop
{
	if Modifier = 0
	{

		Send Joy1
		Sleep, 100
		if (BreakLoop = 1)
			{
			break
			}
	}
}
return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: GetKeyState not working

15 Dec 2017, 07:05

Code: Select all

GetKeyState, ctrl, Ctrl
GetKeyState, shift, Shift
GetKeyState, alt, Alt


Loop
{
if (ctrl = D or alt = D or shift = D)
the IF block only evaluates the state of the keys at the instant the script was run.
the value of your ctrl, shift and alt variables never changes.

Just do it all in the send loop:

Code: Select all

Loop
{
	if (!(GetKeyState("ctrl") || GetKeyState("alt") || GetKeyState("shift")))
	{

		Send Joy1
		Sleep, 100
		if (BreakLoop = 1)
			{
			break
			}
	}
}
return
Psyless
Posts: 2
Joined: 15 Dec 2017, 05:21

Re: GetKeyState not working

15 Dec 2017, 08:53

Thank you so much, I feel dumb for not thinking of that now
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: GetKeyState not working

15 Dec 2017, 08:58

Oh and FYI you cannot Send Joy1
You cannot alter how a game sees a physical joystick. This is not a limitation of AHK, basically nothing can.
All you can really do is drive a virtual joystick which mimics your real joystick, just with the required changes.
I have an AHK library for vJoy here: https://autohotkey.com/boards/viewtopic.php?t=5705

If you have no real joystick, are just trying to fake one, then it is all a lot simpler, and the library I linked will let you do that.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada, Rohwedder and 179 guests