Simulate key presses with one hotkey Topic is solved

Ask gaming related questions (AHK v1.1 and older)
acnl
Posts: 95
Joined: 25 Nov 2017, 09:04

Simulate key presses with one hotkey

Post by acnl » 31 May 2023, 18:55

Hello! I would like help in creating an ahk script that simulates two different key press processes whenever I press the alt+a hotkey.

When I press alt+a, I would like the following sequence to process first:

Send +{F3}
Send F4
Move mouse to stored position 1
Send LButton
Send F3

And if I press alt+a again:

Send +{F3}
Send F2
Move mouse to stored position 2
Send Lbutton
Send F3

Pressing alt+a will simply go back and forth between these two processes. The stored positions are mouse cursor positions, exactly where the mouse cursor pointer is located.

To get stored position 1, I would like Send +{F2} to record the mouse cursor position 1 whenever it is pressed. It only has to save the most recently recorded position.

To get stored position 2, I would like Send +{F4} to record the mouse cursor position 2 whenever it is pressed. It only has to save the most recently recorded position.

I made my own version of this ahk but it was terrible. It was not accurate at all. Sometimes the process would click the wrong thing or inputs would not go through. If you could please help, I would greatly appreciate it. Thank you!

User avatar
mikeyww
Posts: 27072
Joined: 09 Sep 2014, 18:38

Re: Simulate key presses with one hotkey

Post by mikeyww » 31 May 2023, 19:12

Code: Select all

#Requires AutoHotkey v1.1.33
CoordMode Mouse

!a::
If on := !on {
 Send +{F3}{F4}
 MouseMove x1, y1
} Else {
 Send +{F3}{F2}
 MouseMove x2, y2
}
Send {LButton}{F3}
Return

+F2::
MouseGetPos x1, y1
SoundBeep 1500
Return

+F4::
MouseGetPos x2, y2
SoundBeep 1200
Return

acnl
Posts: 95
Joined: 25 Nov 2017, 09:04

Re: Simulate key presses with one hotkey

Post by acnl » 31 May 2023, 20:07

@mikeyww

Thanks for your help.

For some reason it works when I record the two mouse positions in the same location, but when I split them up into different locations, it doesn't work. I am not sure why this is happening because the code is very straightforward.

User avatar
mikeyww
Posts: 27072
Joined: 09 Sep 2014, 18:38

Re: Simulate key presses with one hotkey  Topic is solved

Post by mikeyww » 31 May 2023, 20:24

Test in Notepad. Use only this script with no additional code. Copy and paste all of the code that is posted. Close other scripts.

Testing just the mouse moves is simple, as follows.

Code: Select all

#Requires AutoHotkey v1.1.33
CoordMode Mouse

!a::
If on := !on {
 ; Send +{F3}{F4}
 MouseMove x1, y1
} Else {
 ; Send +{F3}{F2}
 MouseMove x2, y2
}
; Send {LButton}{F3}
Return

+F2::
MouseGetPos x1, y1
SoundBeep 1500
Return

+F4::
MouseGetPos x2, y2
SoundBeep 1200
Return
I generally find "it doesn't work" to be a non-statement: it says nothing about what happens, or what doesn't happen. What happens? Nothing? Something?

acnl
Posts: 95
Joined: 25 Nov 2017, 09:04

Re: Simulate key presses with one hotkey

Post by acnl » 31 May 2023, 23:49

This worked perfectly. thank you!

Post Reply

Return to “Gaming Help (v1)”