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
  • Guests
  • Last active:
  • Joined: --
The suggested functionality looks convenient but Sleep is not a key but a command. It's not consistent in terms of design to have the ability to send another command while the Send command only deals with keystrokes. If it is allowed, something like Send {MsgBox Hello} should be also possible in a sense but it doesn't look right.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
JSLover, when I mentioned backward-compatibility, I was talking about breaking {0} - {9}, which it turns out weren't actually broken, and {0 down} and similar, which were broken without good reason. Furthermore, my meaning was that this feature saves a trivial amount of time, and isn't worth breaking compatibility for. Am I to understand you think that backward-compatibility is completely worthless?

Btw, I had already suggested {Sleep N} as an alternative, for a different reason.

It's not consistent in terms of design to have the ability to send another command while the Send command only deals with keystrokes.

Thank you. I also had that thought but couldn't find the right words to express it.

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

The suggested functionality looks convenient but Sleep is not a key but a command. It's not consistent in terms of design to have the ability to send another command while the Send command only deals with keystrokes. If it is allowed, something like Send {MsgBox Hello} should be also possible in a sense but it doesn't look right.

The point of my original request was never to send a command, or to even use Sleep - per se. The point was to specify a delay - similar to SetKeyDelay, but not for every key. Also, the syntax was only a suggestion. It could be something like:
Send, {delay 10}
; or 
Send, {10ms}
Really, the suggestion was simply to make sending a string of keys even more user friendly - similar to how:
Send, {tab 3}
... is shorthand for:
Send, {tab}{tab}{tab}


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

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.

No, this one is caught by
if (space_pos)  // undo the temporary termination
					*space_pos = old_char;
				*end_pos = '}';  // undo the temporary termination
				if (repeat_count < 1)
					goto brace_case_end; // Gets rid of one level of indentation. Well worth it.

[color=red]				if (vk || sc)[/color]
				{
					if (key_as_modifiersLR = KeyToModifiersLR(vk, sc)) // Assign
					{
						if (!aTargetWindow)
						{

Thanks for the hint with DoKeyDelay, I have now implemented following, it seems to work fine in any sendmode and with another hook and without ;)
// 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)
				{
					if (sSendMode != SM_EVENT)
						PutKeybdEventIntoArray(0, 0, 0, 0,ATOI(aKeys));
					else
						SLEEP_WITHOUT_INTERRUPTION(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.
Support delay for Sendmode Input
void SendEventArray(int &aFinalKeyDelay, modLR_type aModsDuringSend)
;...
		// Caller has ensured that sMySendInput isn't NULL.
		[color=red]// Following is done to support Sleep in Send e.g. Send, abc{100}def
		unsigned int aLastEventCount = 0;
		for (unsigned int i = 0;i < sEventCount;i++)
		{
			// wVK and wScan are 0 and dwExtraInfo holds time to sleep
			if (sEventSI[i].ki.wVk == 0 && sEventSI[i].ki.wScan == 0)
			{
				sMySendInput(i - aLastEventCount, &sEventSI[aLastEventCount], sizeof(INPUT)); // Must call dynamically-resolved version for Win95/NT compatibility.
				SLEEP_WITHOUT_INTERRUPTION((int)sEventSI[i].ki.dwExtraInfo);
				aLastEventCount = i + 1; // + 1 to skip current item
			}
		}
		// Process unprocessed Events
		if (aLastEventCount == 0)[/color]
			sMySendInput(sEventCount, sEventSI, sizeof(INPUT)); // Must call dynamically-resolved version for Win95/NT compatibility.
		[color=red]else
			sMySendInput(aLastEventCount, &sEventSI[aLastEventCount], sizeof(INPUT));[/color]
		// The return value is ignored because it never seems to be anything other than sEventCount, even if
;...
I have pushed the changes to AutoHotkey_H if you like to test.

I still vote to have e.g. {100} for sleep since it is not used and gives the shortest syntax + does not break compatibility with older scripts :!:

  • Guests
  • Last active:
  • Joined: --

[code=auto:0]Send, {delay 10}
; or
Send, {10ms}[/code

That looks better; however, I would say they are not a key.

I still vote to have e.g. {100} for sleep since it is not used and gives the shortest syntax + does not break compatibility with older scripts

{100} doesn't look right than {delay 10}. You may be forgetting the point of view from non-programmers. Let's think about it this way; there are kids trying to learn alphabets and they are reading a list of alphabets. If you include numbers in the list, the kids would get confused and make them slow down from learning. Including exeptions in the first place prevents learners from getting the whole picture.

Similarly, {100} is an exception for the Send command. It may be convenient and easy to understand for those who already know what the command does. However, those who don't know it, it would be hard to figure what it means. Consistency in design is very important. If you make an exception, it should be clearly indicated to say it is not same as others.

So {Delay 100} is slightly better than {100} but I would say even {Delay 100} is not enough because the users won't know at first glance whether Delay is a key or an exception. The users would think there is a key named 10ms from {10ms} also. So I think it's better to leave users to write an own custom function for this functionality unless there is better syntax for it.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
@Guest - I still haven't found the {tab 3} key. The point is delay functionality with shorthand syntax. Perhaps none of the suggested syntax is sufficient, but the functionality would be nice.

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

No, this one is caught by ...

In that case, I retract my arguments about compatibility, but the questions of readability, consistency and worth remain.

Perhaps none of the suggested syntax is sufficient, but the functionality would be nice.

If you exclude syntax changes, what's left? Send and Sleep already provide the required functionality.

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

No, this one is caught by ...

In that case, I retract my arguments about compatibility, but the questions of readability, consistency and worth remain.

Perhaps none of the suggested syntax is sufficient, but the functionality would be nice.

If you exclude syntax changes, what's left? Send and Sleep already provide the required functionality.

In my view it is definitely worth implementing.
As jethrow said this is same as {Tab 3}, here most users find this functionality first on forum, not in help, and they also have no Idea what it means in first place.

With regards to readability this looks better in my view:
Loop 100
   Send a{100}b{50}{Tab 3}{50}{Enter}{1000}!{F4}
than that:
Loop 100 {
   Send a
   Sleep 100
   Send b
   Sleep 50
   Send {Tab 3}
   Sleep 50
   Send {Enter}
   Sleep 1000
   Send !{F4}
}

In general I would not use something like {Sleep 100} or {Delay 100} since this does not save much space, code will look ugly I think. I could agree with {100ms} but still prefer {100}.

  • Guests
  • Last active:
  • Joined: --

I could agree with {100ms} but still prefer {100}.

It is because you already knew what it does. I suggest you think about those who need to learn it. The shortest does not always mean it is clear and easy to understand.

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

With regards to readability this looks better in my view:

When I mentioned readability I wasn't talking about aesthetics, but actually imparting the right meaning on the reader.

  • Guests
  • Last active:
  • Joined: --

In my view it is definitely worth implementing. ... With regards to readability this looks better in my view

I don't agree I'm afraid. The long version is far easier to understand and read. Not worth adding in my view.

MacroMan!
  • Members
  • 604 posts
  • Last active: Mar 20 2012 11:40 AM
  • Joined: 28 Aug 2009

I don't agree I'm afraid. The long version is far easier to understand and read. Not worth adding in my view.


These arguments aside, are there not lots of things in any programming language that aren't obvious to a newbie?

Take the Ternary Operator. It's used in scripts all the time because it's a shorthand way of doing if/else. There are lots of other examples which could be given.

The short, I really don't see the big deal with adding this in, as long as it doesn't compromise backward compatibility.

David
What ever happened, happened.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
One thing:
This:
Send a{100}b
is dangerously close to
Send {a 100}b
and in fact I made that exact mistake while reading HotKeyIt's code

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

With regards to readability this looks better in my view:

When I mentioned readability I wasn't talking about aesthetics, but actually imparting the right meaning on the reader.

I see, sorry for misinterpretation. In that case {100ms} would a better solution than {100}.

Are there any other suggestion for syntax or have you got a favorite?

As I understand we have users that do not need this feature but they do care about the syntax and other who want the feature and do not care about the syntax. So what's next?

In my view it is definitely worth implementing. ... With regards to readability this looks better in my view

I don't agree I'm afraid. The long version is far easier to understand and read. Not worth adding in my view.

I have got scripts that would be 2 pages long if there was not that feature, now they are just half a page and I can overview all code which makes it much easier to develop and debug.

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006

{100ms} would a better solution than {100}.

I agree.

I have got scripts that would be 2 pages long if there was not that feature,

May we see an example? It might help to demonstrate the need for this feature.