Need help with keyhold time

Ask gaming related questions (AHK v1.1 and older)
Maqajin
Posts: 6
Joined: 30 Jan 2023, 08:01

Need help with keyhold time

Post by Maqajin » 09 Jun 2023, 14:26

Code: Select all

v::
SendInput {down down}
SendInput {d down} 
Sleep 150
SendInput {d up}
SendInput {down up}
Return
[Mod edit: [code][/code] tags added.]

Thats my script, the problem is that 150ms do not work accurately, the button delay is either less or more. Is there an option to make the script more accurate? preferably ideal, so that the delay of the buttons occurs exactly 150ms, no more, no less.

[Mod edit: Wromg subforum: Moved topic to AHK v1 help, since this is not v2 code.]

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

Re: Need help with keyhold time

Post by mikeyww » 10 Jun 2023, 07:02

Sleep cannot be completely precise. Your computer is doing dozens or hundreds of other things about the same time. The time would generally be close, within 20-30 ms. When I SetBatchLines to -1, I was typically getting 156-157 ms with this script. Read: Sleep.

Maqajin
Posts: 6
Joined: 30 Jan 2023, 08:01

Re: Need help with keyhold time

Post by Maqajin » 10 Jun 2023, 08:55

@mikeyww
Maybe there are some other more accurate and faster commands? I'm a noob at scripting, could you show me an example of how to write SetBatchLines in my script? Thanks so much

User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

Re: Need help with keyhold time

Post by V0RT3X » 10 Jun 2023, 09:19

I am curious if in your experience combining SetBatchLines that determines how fast a script can run, and SetWinDelay that determines the delay that occurs after each command, has any real world practice in the above scenario? Or am I viewing their purposes incorrectly? I realize the computer is constantly doing dozens of things at the same time constantly and how that effects Sleep times. I'm just mostly curious as to how well we are able to negate those delays. Any tips on how you measured your millisecond output? I am interested in how to test this if possible.

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

Re: Need help with keyhold time

Post by mikeyww » 10 Jun 2023, 09:27

You will have to be the judge about whether 7 ms matters. A blink of the eye requires approximately 100 ms.

Code: Select all

#Requires AutoHotkey v1.1.33

v::
Send {Down down}{d down}
start := A_TickCount
Sleep 150
end := A_TickCount
Send {d up}{Down up}
MsgBox 64, Time elapsed, % end - start " ms"
Return
image230610-1027-001_cr.png
Output
image230610-1027-001_cr.png (4.38 KiB) Viewed 420 times

User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

Re: Need help with keyhold time

Post by V0RT3X » 10 Jun 2023, 10:17

Ha... I'm thinking probably not so much. Thank you for showing me that!

Maqajin
Posts: 6
Joined: 30 Jan 2023, 08:01

Re: Need help with keyhold time

Post by Maqajin » 15 Jun 2023, 02:59

Code: Select all

#NoEnv
#Singleinstance force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
Process, Priority, , H
SetBatchLines, -1
ListLines Off
#KeyHistory 0
SendMode Input
SetTitleMatchMode 2
SetTitleMatchMode Fast
SetKeyDelay, -1, -1, -1
SetMouseDelay, -1
SetWinDelay, -1		
SetControlDelay, -1	
SetDefaultMouseSpeed, 0

v::
SendInput {Blind}{Down down}{d down}
CustomSleep(145)
SendInput {Blind}{d up}{Down up}
Return

CustomSleep(duration) {
    end := A_TickCount + duration
    while (A_TickCount < end) {
        DllCall("Sleep", "UInt", 1)
    }
}
I modified the script by finding various information on the Internet, but when I added customsleep , it seemed to me that there was an improvement in accuracy, but it is still not perfect, although it is already close, can I add or change something to bring it to perfect accuracy?


[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]

Post Reply

Return to “Gaming Help (v1)”