Interrupt the sleep if any key is pressed Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Gonzalo94
Posts: 40
Joined: 17 Jul 2017, 12:56

Interrupt the sleep if any key is pressed

01 Nov 2018, 20:01

Hi friends!! want some help in this idea. I have a code with a sleep of 2000 that works perfects, but sometimes i want to end the code if i press other key.
Thanks if anyone can help me!!
theres the code
I appreciate the help guys :) thanks if anyone of the community can say me something

Code: Select all

f9::
Send {F5}{F10}{ScrollLock}
SetMouseDelay, -1
CoordMode, Mouse, Window
BlockInput, MouseMove
MouseMove, 625,  446, 1
KeyWait, LButton, D, t0.700
MouseMove, 490,  277, 0
BlockInput, MouseMoveOFF
Send {F12}{End}
DllCall("Sleep","UInt",7)
Send {F7}
DllCall("Sleep","UInt",2000)
Send {F1}
return
Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Interrupt the sleep if any key is pressed  Topic is solved

02 Nov 2018, 04:02

Hallo,
this ends the Sleep and the Hotkey-Thread if you press another Hotkey.

Code: Select all

f9::
Send {F5}{F10}{ScrollLock}
SetMouseDelay, -1
CoordMode, Mouse, Window
BlockInput, MouseMove
MouseMove, 625, 446, 1
KeyWait, LButton, D, t0.700
MouseMove, 490, 277, 0
BlockInput, MouseMoveOFF
Send {F12}{End}
DllCall("Sleep","UInt",7)
Send {F7}
Sleep(2000)
Send {F1}
return

Sleep(Time)
{ ;like "Sleep, Time", but terminates the thread when another hotkey is pressed
    End:= A_TickCount + Time - 10
	Hotkey := A_ThisHotkey
    While, S:= End-A_TickCount > 0
        IF (A_ThisHotkey = Hotkey)
            Sleep,S>100?100:S
        Else Exit
}
Gonzalo94
Posts: 40
Joined: 17 Jul 2017, 12:56

Re: Interrupt the sleep if any key is pressed

02 Nov 2018, 11:19

Rohwedder wrote:
02 Nov 2018, 04:02
Hallo,
this ends the Sleep and the Hotkey-Thread if you press another Hotkey.

Code: Select all

f9::
Send {F5}{F10}{ScrollLock}
SetMouseDelay, -1
CoordMode, Mouse, Window
BlockInput, MouseMove
MouseMove, 625, 446, 1
KeyWait, LButton, D, t0.700
MouseMove, 490, 277, 0
BlockInput, MouseMoveOFF
Send {F12}{End}
DllCall("Sleep","UInt",7)
Send {F7}
Sleep(2000)
Send {F1}
return

Sleep(Time)
{ ;like "Sleep, Time", but terminates the thread when another hotkey is pressed
    End:= A_TickCount + Time - 10
	Hotkey := A_ThisHotkey
    While, S:= End-A_TickCount > 0
        IF (A_ThisHotkey = Hotkey)
            Sleep,S>100?100:S
        Else Exit
}
THANKS U VERY MUCH!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 70 guests