Implement in a game that the character walks (GetKeyState two keys)

Ask gaming related questions (AHK v1.1 and older)
robozao
Posts: 4
Joined: 20 Apr 2024, 08:53

Implement in a game that the character walks (GetKeyState two keys)

Post by robozao » 20 Apr 2024, 12:09

Good morning, everyone!
I'm trying to implement in a game that the character walks with the mouse on the keyboard.
The system would practically emulate 8 mouse clicks depending on the combination I press the A S D and W keys on the keyboard.
As shown in the following image:

However, I can't use While (GetKeyState("D", "P")) to detect when two keys are pressed simultaneously to emulate the movement when the A and W keys are pressed together.

Does anyone have any idea how to do this?
Attachments
movmouse.jpg
(8.79 KiB) Downloaded 48 times

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

Re: Implement in a game that the character walks (GetKeyState two keys)

Post by mikeyww » 20 Apr 2024, 12:32

Welcome to this AutoHotkey forum!

WASD to MouseMove

Code: Select all

#Requires AutoHotkey v1.1.33.11
mult   := 10 ; Pixels per move
SLOW   := 0  ; Mouse speed (0-100, 0=fastest)
period := 10 ; Timer period (ms)

w::
a::
s::
d::
If (timer = period)
 Return
SetTimer Go, % timer := period
Go:
SetBatchLines -1
pressed := x := y := 0
For key, coord in {w: [0, -1], d: [1, 0], s: [0, 1], a: [-1, 0]}
 pressed |= state := GetKeyState(key, "P"), x += state * coord[1], y += state * coord[2]
If pressed
 MouseMove mult * x, mult * y, SLOW, R
Else SetTimer,, % timer := "Off"
Return
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.

Post Reply

Return to “Gaming Help (v1)”