need to add time to a script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Manoa
Posts: 2
Joined: 09 Jun 2023, 02:16

need to add time to a script

Post by Manoa » 09 Jun 2023, 02:24

Code: Select all

#MaxHotkeysPerInterval, 20000

isWPressed = 0 ; for physical button
isQPressed = 0 ; for physical button
isXPressed = 0 ; for physical button
isNPressed = 0 ; for physical button

~SC056::
	isQPressed = 1
	if (isWPressed = 0) {
		send {NumpadLeft down}
	}
return
~SC056 Up::
	isQPressed = 0
	if (isWPressed = 0) {
		send {NumpadLeft up}
	}
return
$NumpadLeft::
	isWPressed = 1
	if (isQPressed = 0) {
		send {NumpadLeft down}
	}	
return
$NumpadLeft Up::
	isWPressed = 0
	if (isQPressed = 0) {
		send {NumpadLeft up}
	}
return

~x::
	isNPressed = 1
	if (isXPressed = 0) {
		send {NumpadRight down}
	}
return
~x Up::
	isNPressed = 0
	if (isXPressed = 0) {
		send {NumpadRight up}
	}
return
$NumpadRight::
	isXPressed = 1
	if (isNPressed = 0) {
		send {NumpadRight down}
	}	
return
$NumpadRight Up::
	isXPressed = 0
	if (isNPressed = 0) {
		send {NumpadRight up}
	}
return
this script presses a second key NumpadRight/Left triggered by 2 master keys, I would like to add to it: measure the time the master keys were in state pressed and use that information to run the opposite direction when they are unpressed

this is my attempt so far, it's not working but it should explain what I am trying to do:

Code: Select all

SC056::
	isQPressed = 1
	QPressedTime = A_TickCount
	if (isWPressed = 0) {
		send {SC056 down}{NumpadLeft down}
	}

return
SC056 Up::
	isQPressed = 0
	QLiftedTime = A_TickCount
	ATotalTime = QLiftedTime - QPressedTime
	FutureTime = A_TickCount + ATotalTime 
	if (isWPressed = 0) {
		;send {SC056 up}
		send {NumpadLeft up}
		send {NumpadRight down}
		Loop {
		If !GetKeyState("LButton", "SC056") {
		 
		}
		else break
		} Until A_TickCount - QPressedTime > ATotalTime
		;SCUnpressed = 1
		;Until A_TickCount - _starttime > FutureTime
		;sleep ATotalTime
		;if (A_TickCount  - _starttime > FutureTime) {
		;Loop {
		;} Until A_TickCount > FutureTime
		send {NumpadRight up}
		;}
		;send {NumpadClear down}
		;send {NumpadClear up}
	}
return
thank for help :)

Manoa
Posts: 2
Joined: 09 Jun 2023, 02:16

Re: need to add time to a script

Post by Manoa » 10 Jun 2023, 00:40

Code: Select all

#MaxHotkeysPerInterval, 20000

isWPressed = 0 ; for physical button
isQPressed = 0 ; for physical button
isXPressed = 0 ; for physical button
isNPressed = 0 ; for physical button
delay := 240
delayS := 100

global timing
timing := "false"
global _starttime
global QPressedTime
global QTotalTime
global QLiftedTime

global WPressedTime
global WTotalTime
global WLiftedTime

~SC056::
	isQPressed = 1
	QPressedTime := A_TickCount

	if (isWPressed = 0) {
		send {NumpadRight down}
		send {a up}
		send {d down}
	}
return
~SC056 Up::
	isQPressed = 0
	QLiftedTime := A_TickCount
	QTotalTime := QLiftedTime - QPressedTime
	if (isWPressed = 0) {

	if (QTotalTime * 5 > delay) {
		 send {NumpadRight up}
		 send {NumpadLeft up}
		 reset := 1
		 send {NumpadClear down}
		 sleep delayS
		 send {NumpadClear up}
		 QTotalTime := 0
		}
		
		if (QTotalTime * 5 < delay) {
		 send {NumpadRight up}
		 KeyIsDown := GetKeyState(NumpadLeft , Mode)
		 if (!KeyIsDown) {
		 send {NumpadLeft down}
		}
		send {d up}{a down}
		 sleep (QTotalTime * 25)
		 send {NumpadLeft up}
		 send {a up}
		}
	}
return
$NumpadLeft::
	isWPressed = 1
	if (isQPressed = 0) {
		send {NumpadLeft down}
	}	
return
$NumpadLeft Up::
	isWPressed = 0
	if (isQPressed = 0) {
		send {NumpadLeft up}
	}
return

~x::
	WPressedTime := A_TickCount
	isNPressed = 1
	if (isXPressed = 0) {
		send {NumpadLeft down}
		send {a up}
		send {d down}
	}

return
~x Up::

	isNPressed = 0
	WLiftedTime := A_TickCount
	WTotalTime := WLiftedTime - WPressedTime
	;FutureTime = A_TickCount + ATotalTime 
	if (isXPressed = 0) {

		if (WTotalTime * 5 > delay) {
		 reset := 1
		 send {NumpadClear down}
		 sleep delayS
		 send {NumpadClear up}
		 WTotalTime := 0
		}

		if (WTotalTime * 5 < delay) {
		 send {NumpadLeft up}
		 KeyIsDown := GetKeyState(NumpadRight , Mode)
		 if (!KeyIsDown) {
		 send {NumpadRight down}
		}
		 send {d up}{a down}
		 sleep (WTotalTime * 25)
		 send {NumpadRight up}
		 ;sleep delayS
		 send {a up}
		}
	}
return
$NumpadRight::
	isXPressed = 1
	if (isNPressed = 0) {
		send {NumpadRight down}
	}	
return
$NumpadRight Up::
	isXPressed = 0
	if (isNPressed = 0) {
		send {NumpadRight up}
	}
return

if (reset = 1) {
		 send {NumpadClear down}
		 sleep delayS
		 send {NumpadClear up}
		 reset := 0
		 }
ok so I made progress with the time system and it's more or less working, but now I have a new problem: when I press SC056(or x) rapidly enough (it's not 100% reproduceable) numpadRight(or Left) gets pressed and held indefinetly

Post Reply

Return to “Ask for Help (v1)”