how to use multiple digit numbers in a hotkey script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
helensmith
Posts: 58
Joined: 12 Oct 2014, 04:27

how to use multiple digit numbers in a hotkey script?

17 Feb 2015, 08:44

I want to program number keys to launch files when pressed (I have about 90 files, so I want to use hotkey numbers 1 to 90). My scrip works perfect for numbers 1-9, however for double digit numbers I am having problems. As an example if I use the hotstring for 11 (:*:11::) it will launch file 1 instead of file 11 – presumably because the hotkey for 1 is also included in the script. This problem is with all double digit numbers e.g. if I want file 23 it will launch file 2 because 2 is pressed before 3. How do I get round this problem? If I have just one script containing a single double digit number e.g. :*:11:: it will launch the file fine, however If I want to put all my numbered hotkeys in one file e.g. 1-90 things won’t work. Any ideas how to solve this problem?

Many thanks
Helen
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: how to use multiple digit numbers in a hotkey script?

17 Feb 2015, 10:24

You might require the user to enter 1 - 9 using a leading 0. That way you can just do a hotkey of 0 using #IfWinActive and then use Input to get the second key press. See "Input" in the help.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: how to use multiple digit numbers in a hotkey script?

17 Feb 2015, 11:03

You've actually got two problems, one of which you haven't noticed. When you type 11, the :*:1:: hotstring will auto-backspace. So there will never be two consecutive digits to trigger the dual digit hotstring. This can be avoided by the B0 option. But then you get to the second problem, typing 11 will trigger both the single digit hotstring as well as the dual digit hotstring, since you've explicitly disabled the requirement for an ending character. There is no built in way to use a time period as an ending character. So you'll have to check for that manually, like this:

Code: Select all

:*?:11::
SoundBeep,,800 ;Long beep
Return

:*?:12::
	SoundBeep,2000,800 ;Long beep
Return

:*?:22::
	SoundBeep,3000,800 ;Long beep
Return


:*?B0:1:: ;Single digits need to be defined below double digits and need the B0 option
	If !SingleDigit() ;Single digits need this check for another triggered hotkey/string
		Return
	SoundBeep ;Short beep
Return 

:*?B0:2:: ;Single digits need to be defined below double digits and need the B0 option
	If !SingleDigit() ;Single digits need this check for another triggered hotkey/string
		Return
	SoundBeep,2000 ;Short beep
Return 

SingleDigit(timeout=500){
	HK:=A_ThisHotkey
	Sleep,%timeout%
	If (HK!=A_ThisHotkey)
		Return False
	else{
		SendLevel 1
		SendEvent {BS}
		Return True
	}
}
It's not entirely perfect. Processing during either the time-out or soundbeep is not a 100% I noticed.
helensmith
Posts: 58
Joined: 12 Oct 2014, 04:27

Re: how to use multiple digit numbers in a hotkey script?

17 Feb 2015, 11:41

Many thanks for the suggestions. putting a zero in front of the 1-9 did work, but in the end I went with the suggestion by Nextron. I know you say it is not perfect but I havn't noticed any problems as yet.

Many thanks
Helen
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: how to use multiple digit numbers in a hotkey script?

17 Feb 2015, 12:31

Glad you have it working. :)
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
almatrah
Posts: 2
Joined: 18 Jul 2018, 08:24

Re: how to use multiple digit numbers in a hotkey script?

18 Jul 2018, 09:32

Hi Everybody

I tried this code but I'v got strange behaviour under win8.1. First I got beep (how it should be) followed by get back one level in directory tree (what is strange). Why that happens ?

I found another way to use two digit script activator over here https://autohotkey.com/board/topic/1496 ... t-numbers/ but it dosn't work for me as well :(

I will be grateful for any suggestions :)
best regards
Paul
[AHK] Version.1.1.28.00 [OS] Win8.1_64

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Joey5, JPMuir, matt101, Thorlian and 175 guests