SetKeyDelay in Menu?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

SetKeyDelay in Menu?

01 Jun 2016, 12:32

I just finished converting an extensive non AHK macro script (contains 4 sub menus, 2 subsub menus and over 70 macros) into an AHK menu script that is now working flawlessly

I know that I can insert a SetKeyDelay line before a SEND line so that the keystroke output can be slowed down.

What I wonder is if I can execute something within this script that toggles the setkeydelay so that it will remain in effect for subsequent menu uses until it is toggled back.

fwiw, I am running into websites that restrict the rate that characters are typed into form fields so that pasting and macros cannot be used to fill in web form fields.

The two apparent options would be something to toggle the key delay globally until it is turned off OR have a menu selection that would toggle the delay on but the menu would stay in place for a subsequent macro selection.

Thanks in advance for any wisdom to meet this need.

Beverly Howard
User avatar
waetherman
Posts: 112
Joined: 05 Feb 2016, 17:00

Re: SetKeyDelay in Menu?

01 Jun 2016, 13:25

Do you mean something like this?

Code: Select all

flag := true

#q::
	if ( flag ) {
		SetKeyDelay, 0, 0
	} else {
		SetKeyDelay, 100, 100
	}	
	Send 0123456789
	return

#Space::
	flag := !flag
	if ( flag ) {
		Tooltip, Fast typing
	} else {
		Tooltip, Slow typing
	}
	Sleep, 2000
	Tooltip
	return
Hope this helps,
Marek Smoliński
Image
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: SetKeyDelay in Menu?

01 Jun 2016, 14:49

>> Do you mean something like this? <<

Exactly. But bear with me as I am a rank beginner with ahk and don't really understand the process flow.

Your example makes sense and works. However, In this menu script I have over 70 send routines, so, my question is if there is a way to SetKeyDelay before a selection is made or do I have to add the command above every SEND command line?

Also, your example makes the toggle depending on the hotkey used to trigger the script. Is that the best way to do it rather than adding a menu selection to toggle the state?

Thanks again, and thanks in advance,
Beverly Howard
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: SetKeyDelay in Menu?

01 Jun 2016, 14:59

This help file info seems to relate to my need;

>> The built-in variable A_KeyDelay contains the current setting of Delay for Send/SendEvent mode. [v1.1.23+]: A_KeyDuration contains the setting for PressDuration, while A_KeyDelayPlay and A_KeyDurationPlay contain the settings for SendPlay <<

Can "built-in variable" values be changed within a script or are they for reference only?

Beverly Howard
User avatar
waetherman
Posts: 112
Joined: 05 Feb 2016, 17:00

Re: SetKeyDelay in Menu?

02 Jun 2016, 03:09

SetKeyDelay
Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).
I couldn't find how to change the default outside of the auto-execute section. I guess it can't be done. Some hacky method could accomplish that, for example saving desired state (like the desired key delay and maybe something else) into a file, restarting the script and loading the state from the file. It's probably easier and better to just auto replace every "::\n" with "::\nSetKeyDelay, %keyDelay%, %pressDuration%\n".
Image
User avatar
waetherman
Posts: 112
Joined: 05 Feb 2016, 17:00

Re: SetKeyDelay in Menu?

02 Jun 2016, 03:24

Code: Select all

;======= above goes autoexecute part of your script
flag = %1% ;first parameter
paramNum = %0%
if ( !flag ) {
	if ( paramNum ) { ;at least one parameter was passed, so the flag was just switched
		Tooltip, Fast typing
	}
	SetKeyDelay, 0, 0
} else {
	Tooltip, Slow typing
	SetKeyDelay, 200, 200
}
Sleep, 2000
Tooltip
 
#Space::
	flag := !flag
	Run "%A_AhkPath%" /r "%A_ScriptFullPath%" %flag%
	return

;=============== below go your hotkeys
#q::
	Send 0123456789
	return
You asked about hotkeys vs Menu - I noticed you like the menu, I don't use it at all, but I guess it depends on one's preference.

Take care,
Marek Smolinski
Image
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: SetKeyDelay in Menu?

02 Jun 2016, 10:42

>> You asked about hotkeys vs Menu - I noticed you like the menu, I don't use it at all, but I guess it depends on one's preference. <<

When you pass a certain number of keyboard macros that you use every day, then many others that you use several times a week, hotkeys become hard to manage as well as hard to remember whereas in a menu they are fast and the hotkeys are visible when learning new entries.

In another thread here I mentioned that during my ahk learning process that there was no documentation about creating hotkeys _within_ ahk menus... i.e. underlining letters in menu selections so that they execute with a single keypress. So, the most used macros need two keypresses, the menu trigger and the menu item trigger. Less used macros put in submenus take one more keypress per submenu item... fast, very fast.

The good news, is that when I tried the same syntax for the ahk menu labels, it works! ...just put an asterisk "&" in front of the label letter anywhere in the label you want to use as a trigger... i.e. "Rebe&ka" to trigger "Rebeka" As long as that labeled letter is a unique within any one menu, it will trigger the label by simply pressing that key.

There is also a new factor at play... windows based tablets when used without hardware keyboards. The windows tablet osk has neither an <alt> nor <win> key, so, there are almost no available <ctrl> keys for ahk use.

I just purchased a lenovo Miix700 as a replacement for my 2006 fujitsu laptop and quickly found that win10 and especially it's tablet mode finally defeated the menu based macro program I have been using for a decade, so, it was time to pull out ahk and start stirring up the grey cells by learning a new language... it's been a fun and productive few days, ...but, my brain hurts ;-)

Thanks for the response. Your posts have given me some additional ideas to test. I will experiment and report my findings.

Beverly Howard
User avatar
waetherman
Posts: 112
Joined: 05 Feb 2016, 17:00

Re: SetKeyDelay in Menu?

02 Jun 2016, 12:08

bevhoward wrote:The good news, is that when I tried the same syntax for the ahk menu labels, it works! ...just put an asterisk "&" in front of the label letter anywhere in the label you want to use as a trigger... i.e. "Rebe&ka" to trigger "Rebeka" As long as that labeled letter is a unique within any one menu, it will trigger the label by simply pressing that key.
I think it's Windows' implementation. I remember this ampersand functionality from my experience in Borland Delphi almost 20 years ago.
Also, the menu functionality can be easily reproduced by hotkeys by just putting hotkeys on all keys (not just rarely used combinations), but enabling them only after first hotkey or only when e.g. scroll lock is ON.

Marek Smolinski
Image
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: SetKeyDelay in Menu?

02 Jun 2016, 12:15

>> putting hotkeys on all keys (not just rarely used combinations), but enabling them only after first hotkey or only when e.g. scroll lock is ON. <<

Great info! Will definitely use that ...however, for other needs and especially for use in windows tablet mode. Another issue with me is age (73) and the creeping inability to remember what key is for what ;-)

I will be back later for the "enabling" syntax.

Thanks again,
Beverly Howard
User avatar
waetherman
Posts: 112
Joined: 05 Feb 2016, 17:00

Re: SetKeyDelay in Menu?

02 Jun 2016, 14:58

You could also for example create a searchable interface. For example pressing a Windows key could popup a field to search for a command. Because pressing Windows key alone is done only to access Windows Menu, it wouldn't interfere, and could detect a mouse click and hide itself in such case. But if a user would type instead, then something similar to autocomplete suggestions would appear. It's some hassle to do, but how cool would it be!

Marek Smolinski
Image
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: SetKeyDelay in Menu?

02 Jun 2016, 16:55

>> how cool would it be <<

That's what drives many of us ;-)

Beverly Howard

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 347 guests