Script Help

Ask gaming related questions (AHK v1.1 and older)
AHKwin
Posts: 9
Joined: 18 Feb 2018, 01:49

Script Help

24 Oct 2021, 20:39

Hello all, Im needing a little bit of help with my script.

In the beginning I was having an issue with the numbers 1 and 2 being sent without modifiers, so I added down and up to it, and it seems to have corrected it.

Code: Select all

$4::
    Send, {4}
    Sleep, 1
    Send, {Ctrl down}{Alt down}{1}{Ctrl up}{Alt up}
    Sleep, 1
    Send, {Ctrl down}{Alt down}{2}{Ctrl up}{Alt up}
    Sleep, 1
    Send, {0}
Return
but further down the script i have

Code: Select all

$!4::
  While GetKeyState("4","P") && GetKeyState("Alt","P")
    Send, !{4}
    Send, ^{8}
Return
and now this goes off when I press 4, Im assuming because of the earlier part of the script with down/up.

Is there perhaps a workaround for this? I added ctrl down and up to the 2nd part, but that did not solve the problem.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script Help

25 Oct 2021, 05:07

A While block would need to be enclosed in braces. Try the following in Notepad with no other code, and no other scripts running.

Code: Select all

$4::
SoundBeep, 1500
SetKeyDelay, 25, 25
Send 4^!1^!20
Return

$!4::
SoundBeep, 1000
SetKeyDelay, 25, 25
While GetKeyState("4", "P") & GetKeyState("Alt", "P")
 Send !4^8
Return
AHKwin
Posts: 9
Joined: 18 Feb 2018, 01:49

Re: Script Help

25 Oct 2021, 19:02

$4::
SoundBeep, 1500
SetKeyDelay, 25, 25
Send 4^!1^!20
Return

$!4::
SoundBeep, 1000
SetKeyDelay, 25, 25
While GetKeyState("4", "P") & GetKeyState("Alt", "P")
Send !4^8
Return
This worked much better, so couple of questions.

Should I just add the set keydelay to the top of my original script?
If I understand the setkeydelay the first one is keydelay and the 2nd part is how long its held down? Im used to just seeing SetKeyDelay 500, not with the 2nd option.
AHKwin
Posts: 9
Joined: 18 Feb 2018, 01:49

Re: Script Help

25 Oct 2021, 20:01

One other question, if I apply the setkeydelay to the top of the script and then also apply a different setkeydelay setting to individual keys which will be priority?
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script Help

25 Oct 2021, 20:17

It's all explained here: SetKeyDelay.
Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).
So you have a choice. Put it at the top for a global effect, or just put it in a thread for a local effect. The local setting will override others.
AHKwin
Posts: 9
Joined: 18 Feb 2018, 01:49

Re: Script Help

26 Oct 2021, 19:52

mikeyww wrote:
25 Oct 2021, 20:17
It's all explained here: SetKeyDelay.
Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).
So you have a choice. Put it at the top for a global effect, or just put it in a thread for a local effect. The local setting will override others.
ah i overlooked that looking at the setkeydelay wiki, the global vs local. thank you!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 39 guests