Need help with executing different code when modifier is released Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
B1z2
Posts: 15
Joined: 15 Apr 2016, 11:39

Need help with executing different code when modifier is released

19 Feb 2018, 15:20

Hi,

Is there any way to archive this:

While holding alt and press down send 1, but when i release alt, send 2.

I tried fiddling with keywait and getkeystate, but couldn't figure how to do this.

Thanks! :D
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Need help with executing different code when modifier is released

19 Feb 2018, 15:23

Using a modifier alone on this is a bit weird, but you can try this:

Code: Select all

LAlt:: ; change to RAlt if you want right, or Alt if you want to try either
While GetKeyState("LAlt","P")
{
Send 1
Sleep 100
}
Send 2
return
B1z2
Posts: 15
Joined: 15 Apr 2016, 11:39

Re: Need help with executing different code when modifier is released

20 Feb 2018, 01:21

Exaskryz wrote:Using a modifier alone on this is a bit weird, but you can try this:

Code: Select all

LAlt:: ; change to RAlt if you want right, or Alt if you want to try either
While GetKeyState("LAlt","P")
{
Send 1
Sleep 100
}
Send 2
return

Hi,

I tried this script and it sends 1 repeatedly while i hold alt, what i would like is to send 1 only when i press down button, while holding alt, then when i release alt, send 2.

Code: Select all

Alt & Down:: 
While GetKeyState("Alt","P")
{
Send 1
Sleep 100
}
Send 2
return
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Need help with executing different code when modifier is released

20 Feb 2018, 09:29

Oh, Down as in the Down Arrow. I see.

The hotkey can be changed to !Down:: because ! is the Alt modifier.

Do you mean it should repeat sending 1 and repeat sending 2? I would change Send 2 into

Code: Select all

While GetKeyState("Down","P")
{
Send 2
Sleep 100
}
And it would end when you release Down.
B1z2
Posts: 15
Joined: 15 Apr 2016, 11:39

Re: Need help with executing different code when modifier is released

20 Feb 2018, 09:47

Exaskryz wrote:Oh, Down as in the Down Arrow. I see.

The hotkey can be changed to !Down:: because ! is the Alt modifier.

Do you mean it should repeat sending 1 and repeat sending 2? I would change Send 2 into

Code: Select all

While GetKeyState("Down","P")
{
Send 2
Sleep 100
}
And it would end when you release Down.
Sorry for not being clear enough :D

1. I press alt, then down button - 1 is sent for one time, not repeating.
2. Each time i press down button, while keeping alt button pressed down, 1 is sent.
3. Once i release alt button, 2 is sent.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Need help with executing different code when modifier is released  Topic is solved

20 Feb 2018, 11:21

I think this would work:

Code: Select all

!Down::Send 1
~Alt up::Send 2
Now I've tested it.

The potential problem is that Alt will send 2 if you didn't even press Alt+Down. So you may use this untested code:

Code: Select all

!Down::Send 1
~Alt up::
If (A_PriorHotkey="!Down")
   Send 2
return
B1z2
Posts: 15
Joined: 15 Apr 2016, 11:39

Re: Need help with executing different code when modifier is released

20 Feb 2018, 12:45

Exaskryz wrote:I think this would work:

Code: Select all

!Down::Send 1
~Alt up::Send 2
Now I've tested it.

The potential problem is that Alt will send 2 if you didn't even press Alt+Down. So you may use this untested code:

Code: Select all

!Down::Send 1
~Alt up::
If (A_PriorHotkey="!Down")
   Send 2
return
It works!

Thanks :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, mcd, Nerafius and 126 guests