Sending a key press that games recognize

Ask gaming related questions (AHK v1.1 and older)
Lightcaster5
Posts: 4
Joined: 08 Jan 2019, 08:31

Sending a key press that games recognize

08 Jan 2019, 08:42

I have been have some trouble making a script that will send a key press every "x" amount of seconds. The key applies to a function that I have made, a hotkey. I have been looking at some forum posts and found the DllCall() function. Is there a list of DllCall() keys. The key I want to be pressed using this DllCall() function is "f". If there is a better way to send a keystroke to a game window, use that instead, Thanks!

What I am looking for:

Code: Select all

#SingleInstance, Force

Run := 0

Loop
{
If (Run = 1) {
\\DllCall() that presses F\\
sleep, 5000
}
}

F8::
If (Run = 1) {
Run := 0
} Else {
Run := 1
}
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Sending a key press that games recognize

09 Jan 2019, 08:08

What has DllCall got to do with sending keys?

Why not use the Send command?

Also, your code will not do anything (Apart from chewing lots of CPU doing nothing) because Run is always 0, so the Send command never gets executed

Code: Select all

#SingleInstance, Force
SetKeyDelay, 0, 50

Run := 0

Loop
{
   If (Run = 1) {
      Send f
      sleep, 5000
   }
}
Lightcaster5
Posts: 4
Joined: 08 Jan 2019, 08:31

Re: Sending a key press that games recognize

11 Jan 2019, 16:55

That worked great! I think it had to do with the SetKeyDelay part, can you explain that a little bit more to me?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Sending a key press that games recognize

12 Jan 2019, 08:02

SetKeyDelay, 0, 50 Tells AHK to insert a 50ms sleep after pressing (But before releasing) each key.
Many games need something like that, else they do not recognize the key being pressed reliably

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: LepG and 50 guests