Sleep for current Send Action / Hold Key down until

Get help with using AutoHotkey and its commands and hotkeys
Traumverderber
Posts: 8
Joined: 25 Jan 2018, 02:38

Sleep for current Send Action / Hold Key down until

26 Jan 2018, 03:54

Hello,
I want to transform the first code, into something like the second one.
The reason for this is, because between the {Numpad9 down} and {Numpad9 up} command are several other Actions.
I appreciate your help!

Code: Select all

Send {Numpad9 down}
Sleep 375
Send {Numpad3 down}{Numpad3 up}
Sleep 375
Send {Numpad9 up}{Numpad4 down}{Numpad4 up}

Code: Select all

Send {Numpad9 down} release 750 ;hold down for 750ms then release
Sleep 375
Send {Numpad3 down}{Numpad3 up}
Sleep 375
Send {Numpad4 down}{Numpad4 up}
Instead of attaching the Send {Numpad9 up} to the last Send command, I want to do it automatically after a certain time.
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 04:24

where is your hotkey or hotstring ?

if you do send numpad9 down and not send it up it will stay down

Code: Select all

#SingleInstance, Force
#NoEnv

^a:: ;----------------------- Control + a to activate
	Send, {Numpad9, D} ;----- pressing 9 down
	Sleep, 375
	Send, {Numpad3} ;-------- while 9 is down pressing 3
	Sleep, 375
	Send, {Numpad9, U} ;----- 750ms has passed and releasing 9
	Send, {Numpad4}	;-------- pressing 4
return	
or maybe this one which will hold down numpad9 and send 3, 4 then release 9 (sleep 250 is 1/4 second)

Code: Select all

#SingleInstance, Force
#NoEnv

^a:: ;----------------------- Control + a to activate
	Send, {Numpad9, D} ;----- pressing 9 down
	Sleep, 250
	Send, {Numpad3} ;-------- while 9 is down pressing 3
	Sleep, 250
	Send, {Numpad4}	;-------- pressing 4
	Sleep, 250
	Send, {Numpad9, U} ;----- 750ms has passed and releasing 9
return	
Last edited by GreatGazoo on 26 Jan 2018, 04:43, edited 1 time in total.
Traumverderber
Posts: 8
Joined: 25 Jan 2018, 02:38

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 04:41

GreatGazoo wrote:where is your hotkey or hotstring ?

if you do send numpad9 down and not send it up it will stay down

Code: Select all

#SingleInstance, Force
#NoEnv

^a:: ;----------------------- Control + a to activate
	Send, {Numpad9, D} ;----- pressing 9 down
	Sleep, 375
	Send, {Numpad3} ;-------- while 9 is down pressing 3
	Sleep, 375
	Send, {Numpad9, U} ;----- 750ms has passed and releasing 9
	Send, {Numpad4}	;-------- pressing 4
return	

It's only a snippet of the code.
As you can see in the first code, I indeed send it up and down.
My question was to not write a line of code to send the key up again but instead automatically send it up after x amount of time.

Edit:
Your code just does exactly the same as my first one. I dont want the extra line for the Key Up
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 04:45

yeah,
you have to specify when you want it to automatically release the 9, you do that with sleep and sending 9 up, it will not do anything it is not programmed to do

sending 9 down and never sending 9 up it will stay down forever, until the program is exited


do you want 9 held down while 3 and 4 are pressed ? or no?
Traumverderber
Posts: 8
Joined: 25 Jan 2018, 02:38

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 04:48

GreatGazoo wrote:yeah,
you have to specify when you want it to automatically release the 9, you do that with sleep and sending 9 up
As I mentioned, I'm searching for a method to avoid a line with Key up.
The reason for this is because i have 300+ Timings.
The only Information I have is a start time and how long to hold the key before releasing. Meanwhile other Key presses can occure and therefore I would have to calculate all sleep times between the hold and the other keys manually.
I did that yesterday for 1 1/2 hours but also had some Errors in it and only coverd 50 keys.
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 04:50

Code: Select all

^a:: ;----------------------- Control + a to activate
	Send, {Numpad9} ;--------- pressing 9
	Sleep, 375
	Send, {Numpad3} ;--------  pressing 3
	Sleep, 375
	Send, {Numpad4} ;-------- pressing 4
return	
Traumverderber
Posts: 8
Joined: 25 Jan 2018, 02:38

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 04:52

GreatGazoo wrote:

Code: Select all

^a:: ;----------------------- Control + a to activate
	Send, {Numpad9} ;--------- pressing 9
	Sleep, 375
	Send, {Numpad3} ;--------  pressing 3
	Sleep, 375
	Send, {Numpad4} ;-------- pressing 4
return	
Please read my first post. Between num9 down and num9 up are Actions.
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 04:54

that was the second code I sent

Code: Select all

#SingleInstance, Force
#NoEnv

^a:: ;----------------------- Control + a to activate
	Send, {Numpad9, D} ;----- pressing 9 down
	Sleep, 250
	Send, {Numpad3} ;-------- while 9 is down pressing 3
	Sleep, 250
	Send, {Numpad4}	;-------- pressing 4
	Sleep, 250
	Send, {Numpad9, U} ;----- 750ms has passed and releasing 9
return	
but you said you want to send 9 down and it read your mind to when it should release 9 from being held, I cant help you with that,

you said you wanted 9 to be released after 750 milliseconds, that's what I've done, there is no other way to release a key that is being held down without a send up command, seriously I'm trying to help

any line you don't want you can add a ; at the front and it will not execute and you'll be sending 9 down the rest of your life
it's your code you do what you want, you ask for help, at least consider the answer

https://autohotkey.com/docs/commands/Se ... Down_a_Key
Traumverderber
Posts: 8
Joined: 25 Jan 2018, 02:38

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 06:01

GreatGazoo wrote:that was the second code I sent

Code: Select all

#SingleInstance, Force
#NoEnv

^a:: ;----------------------- Control + a to activate
	Send, {Numpad9, D} ;----- pressing 9 down
	Sleep, 250
	Send, {Numpad3} ;-------- while 9 is down pressing 3
	Sleep, 250
	Send, {Numpad4}	;-------- pressing 4
	Sleep, 250
	Send, {Numpad9, U} ;----- 750ms has passed and releasing 9
return	
but you said you want to send 9 down and it read your mind to when it should release 9 from being held, I cant help you with that,

you said you wanted 9 to be released after 750 milliseconds, that's what I've done, there is no other way to release a key that is being held down without a send up command, seriously I'm trying to help

any line you don't want you can add a ; at the front and it will not execute and you'll be sending 9 down the rest of your life
it's your code you do what you want, you ask for help, at least consider the answer

https://autohotkey.com/docs/commands/Se ... Down_a_Key
If you read my first post carefully it get's clear and I dont want it to read my mind lol. You basically didn't modify my code at all and just pasted it here again. But thanks for your help anyway.
I need a method that invokes a Keypress Down and automatically releases after for example 750ms. I want to avoid a sleep command after 4 lines because of calculating issues from my data.
Traumverderber
Posts: 8
Joined: 25 Jan 2018, 02:38

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 06:11

I found this post which deals with a smiliar Problem https://autohotkey.com/board/topic/467- ... -duration/.

Maybe I can work with A_TimeSinceThisHotkey?
And I could ask:
If A_TimeSinceThisHotkey = 2500, Send {Numpad 9 down}
If A_TimeSinceThisHotkey = 3250, Send {Numpad 9 up}

And extend it like this:
If A_TimeSinceThisHotkey = 2500, Send {Numpad 9 down}
If A_TimeSinceThisHotkey = 2875, Send {Numpad 4 down}{Numpad 4 up}
If A_TimeSinceThisHotkey = 3250, Send {Numpad 9 up}

Could this work?
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Re: Sleep for current Send Action / Hold Key down until

26 Jan 2018, 11:33

Traumverderber wrote:I found this post which deals with a smiliar Problem https://autohotkey.com/board/topic/467- ... -duration/.

Maybe I can work with A_TimeSinceThisHotkey?
And I could ask:
If A_TimeSinceThisHotkey = 2500, Send {Numpad 9 down}
If A_TimeSinceThisHotkey = 3250, Send {Numpad 9 up}

And extend it like this:
If A_TimeSinceThisHotkey = 2500, Send {Numpad 9 down}
If A_TimeSinceThisHotkey = 2875, Send {Numpad 4 down}{Numpad 4 up}
If A_TimeSinceThisHotkey = 3250, Send {Numpad 9 up}

Could this work?
that has a line with key up which you don't want me doing

and for numpad 4 I don't understand why you're sending down and then up when {numpad4} already does that, if you want to simulate key ressing you should use a different send mode like sendevent, sendinput


you could try this

SetKeyDelay [, Delay, PressDuration, Play]
or
A_KeyDuration

https://autohotkey.com/docs/commands/SetKeyDelay.htm

might look like this is guess, I'm not sure I never used it, might be best to use it with a Label so it can be triggered on it's own and be different from other key durations

Code: Select all

^r::
SetKeyDelay, 0, 750
     Send, {Numpad9}
     msgbox, current key duration is %A_KeyDuration%
return
not sure if we can change script settings locally like that

Return to “Ask For Help”

Who is online

Users browsing this forum: eh1286, Google [Bot], kyuuuri, Veterus and 222 guests