Replacing key while GetKeyState - I have no idea what's wrong

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dontetris
Posts: 3
Joined: 20 Sep 2017, 07:18

Replacing key while GetKeyState - I have no idea what's wrong

20 Sep 2017, 07:39

Hi everyone,


I was trying to do this in the past one hour, I give up, I have no idea where this is wrong, could someone help me out please?
The goal is that if I hold down left shift and press space meanwhile, space acts as if I pushed space and "c" together (and the pushed shift button keeps working of course)... So Shift+Space+C will be pushed together.

This is my script:

Code: Select all

$Space::
Send +{Space}

while GetKeyState("LShift", "P") && GetKeyState("Space", "P")
{
Send {Space}c
}
return
Any idea where this is wrong? Thanks in advance.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Replacing key while GetKeyState - I have no idea what's wrong

20 Sep 2017, 07:54

Code: Select all

Send +{Space}

while GetKeyState("LShift", "P") && GetKeyState("Space", "P")
GetKeyState("LShift", "P") will always be false, as you are checking the physical state of the key, and shift is never physically pressed.
Even if you removed the "P", it would not work, as by the time Send +{Space} finishes executing, shift is no longer held.

Just use while GetKeyState("Space", "P")
dontetris
Posts: 3
Joined: 20 Sep 2017, 07:18

Re: Replacing key while GetKeyState - I have no idea what's wrong

20 Sep 2017, 08:02

evilC wrote:

Code: Select all

Send +{Space}

while GetKeyState("LShift", "P") && GetKeyState("Space", "P")
GetKeyState("LShift", "P") will always be false, as you are checking the physical state of the key, and shift is never physically pressed.
Even if you removed the "P", it would not work, as by the time Send +{Space} finishes executing, shift is no longer held.

Just use while GetKeyState("Space", "P")
Maybe I explained it wrong, I do actually press SHIFT (and hold it down).
So when I hold down shift and press space, I would like it to be space+c instead of just space, otherwise (when I'm not pressing shift) I want it to act like normal space.
dontetris
Posts: 3
Joined: 20 Sep 2017, 07:18

Re: Replacing key while GetKeyState - I have no idea what's wrong

20 Sep 2017, 08:56

evilC wrote:$Space:: will not trigger if you hold shift and then hit space...

You want $+Space:: or $*Space::

Thanks, much better :) One slight problem left, I only need one "space+c" pressed, but this script presses it at least 3-4 times, can I limit to one somehow?

This is the current one then:

Code: Select all

$+Space::
Send +{Space}

while GetKeyState("LShift", "P") && GetKeyState("Space", "P")
{
Send {Space}c
}
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, mikeyww, Spawnova and 353 guests