Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Send, {Sleep 100} or Send, {100ms}


  • Please log in to reply
50 replies to this topic
jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
It seems like I quite often send a series of keys that would be one line, except I need to add short pauses for timing. I think it would be nice to have the following option:
Send, {Home}{Tab 3}%username%{Sleep 100}{Tab}%password%{Sleep 100}{Enter}

; would be the same as:

Send, {Home}{Tab 3}%username%
Sleep, 100
Send, {Tab}%password%
Sleep, 100
Send, {Enter}


Also, (and perhaps this should be another thread) I think it would be nice to be able to send a series of keys multiple times, like this:
Send, {Down,Space 2}

; would be the same as:

Loop, 2
   Send, {Down}{Space}


jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
SetKeyDelay should solve the first one.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

SetKeyDelay should solve the first one.

I had taken this into consideration, but usually I want the script to operate as fast as possible (I typically use SendInput). I had also realized that I could just send words via clipboard and ^v, but I still think Send, {Sleep} would be a nice functionality when you need a slight pause between sending certain keys.

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
The second one would probably be better as a user defined function since, while not explicitly catering to gamers, would appear to implicitly cater to them. And when you think about it the function itself would inevitably become a little wieldy when you consider that in most cases such repeats will also call for delays to be repeated. For example(untested):

!j::SendRepeat("{DOWN}{SPACE}",2)

SendRepeat(keys,no,slp=0,del=0,dur=0) {

  SetKeyDelay, % del, % dur

  Loop % no {
    Send % keys
    Sleep % slp
  }

}

And then once you've called that function in the script, do you have to reset SetKeyDelay to the default settings(or previous settings)? Just one thing after another that makes a more complex problem for a kind of niche usage.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
I would love this too, especially because Send, {Sleep} does not do anything for me :) :arrow: Sleep, {Sleep}

But it looks like it is not going to happen since you can do:
SendInput % "{1}" Sleep(100) "{2}"
Return
Sleep(t){
	Sleep % t
}


engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
does that sleep at the right time? I don't think there is logic that you can count on for the order of execution on an expression like that. Interesting solution if it works.

temp01
  • Members
  • 120 posts
  • Last active: May 18 2013 08:27 PM
  • Joined: 09 Jul 2009
SendMode, Input



Send(500, "abc", "def", "ghi")

Send(100, "{Home}{Tab 3}", "{Tab}", "{Enter}")



Send(delay, p0, p1="!",p2="!",p3="!",p4="!",p5="!",p6="!",p7="!",p8="!",p9="!",p10="!",p11="!",p12="!"){

	Send, %p0%

	Loop, 12 {

		If p%A_Index%=!

			Break

		Sleep, delay

		Send, % p%A_Index%

	}

}


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

does that sleep at the right time? I don't think there is logic that you can count on for the order of execution on an expression like that. Interesting solution if it works.


No it does not, I forgot already about it :(

Thank you temp01, but I think this would suite little more, not sure why I have not build it earlier :)
Send("a{500}b{450}c{400}d{350}e{300}f{250}g{200}h{150}i{100}j{50}k{10}{1}")

Send(keys,SendMode="Input"){
	Loop,Parse,Keys,{
	{
		If RegExMatch(A_LoopField,"^\d\d+\}"){
			Sleep % RegExReplace(A_LoopField,"^\d\d+\K}.*")
			If !(keys:=SubStr(A_LoopField,InStr(A_LoopField,"}")+1))
				Continue
		} else keys:= "{" . A_LoopField
		If (SendMode="Play")
			SendPlay % keys
		else if (SendMode="Raw")
			SendRaw % keys
		else if (SendMode="Event")
			SendEvent % keys
		else if (SendMode="Input")
			SendPlay % keys
		else if (SendMode="")
			Send % keys
	}
}


  • Guests
  • Last active:
  • Joined: --
My Send() function, currently only mentioned here...(in reply to someone else's function)...
Re: SendInputSlow() - Delay Function...is parses the Send line & replaces any {Sleep X} with a real Sleep...

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Bump.
AutoHotkey_H already has the feature, I would like to see it implemented in AutoHotkey_L? Anyone else?

I use the feature all the time and it saves a lot of code :D

The only "didadvantage" is that we cant use {0} - {9} but this is really chickenfeed for the benefit ;)
Sleep abc{100}def ;Sends abc, sleeps for 100 ms and sends def
The only required change is in keyboard_mouse.cpp:
void SendKeys(LPTSTR aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetWindow)
;...
	            // Alt to still be down after the command is over, even though F is modified
					// by Alt.
					SendKey(vk, sc, mods_for_next_key, persistent_modifiers_for_this_SendKeys
						, repeat_count, event_type, key_as_modifiersLR, aTargetWindow);
				}
				[color=red]else if (isdigit((UCHAR)*aKeys) && key_name_length > 1)
				{
					SLEEP_WITHOUT_INTERRUPTION((int)ATOI(aKeys));
				}[/color]
				else if (key_name_length == 1) // No vk/sc means a char of length one is sent via special method.
				{
					// v1.0.40: SendKeySpecial sends only keybd_event keystrokes, not ControlSend style
					// keystrokes.
;...


nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Seems pretty simple with variadic funcs...
Send("abcdef", 200, "ghijk", 100, "{Tab}")

Send(p*){
   Loop % p.MaxIndex()
      If (A_Index & 1)
         Send % p[A_Index]
      else
         Sleep p[A_Index]
}
But yes it would be useful built-in.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
HotKeyIt: That does not work for SendInput. SendInput puts all key events into an array, then passes the array to the SendInput() API. Sleeping when {1000} is parsed causes a delay before the first key is sent, no matter where {1000} is encountered.

Another issue is readability: if you have something like Send {65}, why should one expect it to sleep? Interpreting it as a keycode would be much more logical. We could use {Sleep N}, but then it only saves typing "Send " after each sleep.

The only "didadvantage" is that we cant use {0} - {9}

Wrong. key_name_length > 1 takes care of that. However, it will misinterpret {0 down} or similar, which is unacceptable.

but this is really chickenfeed for the benefit

I disagree. Backward-compatibility is more important than any trivial time-saving features.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

HotKeyIt: That does not work for SendInput. SendInput puts all key events into an array, then passes the array to the SendInput() API. Sleeping when {1000} is parsed causes a delay before the first key is sent, no matter where {1000} is encountered.

Strangely it works for SendInput and SendEvent but not for SendPlay :?

Another issue is readability: if you have something like Send {65}, why should one expect it to sleep? Interpreting it as a keycode would be much more logical. We could use {Sleep N}, but then it only saves typing "Send " after each sleep.

Good point, have not thought about that. Btw. Sleep is a key :!: {Sleep 10} = Send {Sleep} key 10 times.

The only "didadvantage" is that we cant use {0} - {9}

Wrong. key_name_length > 1 takes care of that. However, it will misinterpret {0 down} or similar, which is unacceptable.

I meant that we cannot sleep for less than 10 sec.

but this is really chickenfeed for the benefit

I disagree. Backward-compatibility is more important than any trivial time-saving features.

What do you mean, currently {10} does nothing, how can it break a script?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Strangely it works for SendInput and SendEvent but not for SendPlay :?

SendPlay works similarly to SendInput, but key delays can also be put into the array. For SendPlay, you should do that instead of sleeping immediately. See DoKeyDelay.

Again, it does not work for SendInput. If it appeared to work for you, SendInput probably fell back to SendEvent mode due to the presence of a second hook.

Send {Sleep} key 10 times.

I knew Sleep was a key, but had forgotten about the repetition syntax.

I meant that we cannot sleep for less than 10 sec.

Sleep has a granularity of 10 or 15.6 milliseconds anyway.

What do you mean, currently {10} does nothing, how can it break a script?

You have broken {0 down}, {0 up}, {0 5} and similar.

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004

I disagree. Backward-compatibility is more important than any trivial time-saving features.

...I'm never gonna understand this. We should treat "Backward-compatibility" as God, just cuz that's the way it was written 100 years ago? Should we revert to AutoHotkey 1.0?...you never know what AutoHotkey 1.0 scripts are out there, that don't work anymore!...gotta support them!

We should not 100% support "Backward-compatibility" & sacrifice progress/a better language/coding experience. "Backward-compatibility" just means "old scripts don't need updated". You've broken some of my scripts...& what did I do?...update them! "Backward-compatibility" is not all it's cracked up to be...especially if it hinders progress.

Sleep is a key :!: {Sleep 10} = Send {Sleep} key 10 times.

...I think the convenience of "Sleeping inside a Send" is more important than "sending the Sleep key 1000 times".

The syntax could be one of...
[*:1kn6lclm]{Sleep 10} = no comma = Sleep this many ms (providing no way to send the Sleep key multiple times)
[*:1kn6lclm]{Sleep, 10} = with comma = Sleep this many ms, without comma = send the Sleep key this many times
[*:1kn6lclm]{Sleep, 10ms} = with "ms" suffix = Sleep this many ms, without "ms" suffix = send the Sleep key this many times (with or without comma)...then also...[*:1kn6lclm]{SleepKey 10} = with any of the above, make "SleepKey" be the new syntax for "send the Sleep key this many times"
[*:1kn6lclm]{Sleep} = with any of the above, without a number, it means press the Sleep key (once)...my Send() function, that I wrote 100 years ago, supports some of this...it supports this syntax...

send=a1{Sleep, 319}b2{Sleep, 319}c3{Sleep, 819}d{Raw}4{Sleep, 1119}e5
Send(send)
...it works with any send mode (SendInput, SendPlay, etc)...& I believe it also supports {Sleep} (without a number) to mean "press the Sleep key".

Why can't AutoHotkey, internally, do like my function?...oh yes, I forgot, we need to support "old scripts" that might need :roll: to press the Sleep key 1000 times. Gotcha!

I've pretty much given up on getting ANYTHING into AutoHotkey...everything is denied based on "Backward-compatibility"...or it's "unnecessary"...or some other reason not to do it. Don't get me wrong, I don't mean that everything should be accepted, it's just that nothing ever is.

I've just decided to write my own functions to "workaround" the limitations of the language (unfortunately this don't help others {unless they search & find my functions}). So, if I ever hit something I can't workaround in AutoHotkey, then, perhaps, maybe, (not likely), I'll try to compile my own version of AutoHotkey, like I want it.

PS...did everyone miss my (valid) Bug Report? SetTimer+Common Dialog+WinWait = 100% CPU usage
Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?