Jump to content

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

Alphabet loop


  • Please log in to reply
8 replies to this topic
Xx7
  • Members
  • 674 posts
  • Last active: Mar 24 2015 10:48 PM
  • Joined: 19 Apr 2011
I would like a script with an inputbox where:

If I enter "c"... it will return "abc"
If I enter "j"... it will return "abcdefghij"
If I enter "z"... it will return "abcdefghijklmnopqrstuvwxyz"


Was trying to use something like this.
<!-- m -->http://www.autohotke... ... t=alphabet<!-- m -->

Xx7
  • Members
  • 674 posts
  • Last active: Mar 24 2015 10:48 PM
  • Joined: 19 Apr 2011
I got it working... but its probably the least efficient code possible :? . Anybody know how to shorten this or atleast not have TWO arrays in the code? :)

^7::
InputBox, SearchTerm, Alphabet, Please enter a letter, , 300, 130
if (SearchTerm <> "")
{

;########## Keys are alphabet ###############
Array1 := {a: "1",	b: "2",	c: "3",	d: "4",	e: "5",	f: "6",	g: "7",	h: "8",	i: "9",	j: "10",	k: "11",	l: "12",	m: "13",	n: "14",	o: "15",	p: "16",	q: "17",	r: "18",	s: "19",	t: "20",	u: "21",	v: "22",	y: "23",	x: "24",	y: "25",	z: "26"}

;########## Keys as numbers ###############
Array2 := {1: "a",	2: "b",	3: "c",	4: "d",	5: "e",	6: "f",	7: "g",	8: "h",	9: "i",	10: "j",	11: "k",	12: "l",	13: "m",	14: "n",	15: "o",	16: "p",	17: "q",	18: "r",	19: "s",	20: "t",	21: "u",	22: "v",	23: "y",	24: "x",	25: "y",	26: "z"}


number_pos := Array1[SearchTerm]

while, A_Index <= number_pos
{

SendInput, % Array2[A_Index]
SendInput, ){enter}
}
}
else
	Exit

return


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
:shock:

Yikes. Try this:

alphabet=abcdefghijklmnopqrstuvwxyz	; place this part in the auto-execute section of the script
Loop, parse, alphabet			;
	Hotkey, $%A_LoopField%, Letters	;
return				;


Letters:
Send %	SubStr(alphabet,1,InStr(alphabet,SubStr(A_ThisHotkey,0)))
return


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

   Hotkey, % "$" Chr(A_Index+97), Letters

return

Letters:

Send %   SubStr(alphabet,1,InStr(alphabet,SubStr(A_ThisHotkey,0)))

return


Honest Abe
  • Members
  • 310 posts
  • Last active: Jan 08 2015 08:56 PM
  • Joined: 07 Jan 2011
Using RegEx:

alphabet := "abcdefghijklmnopqrstuvwxyz"

f1::
Inputbox, _V_, Testing,,,128,128
pattern := "\w+" _V_
RegExMatch(alphabet, pattern, match)
TrayTip,, %match%
Return

From:
<!-- m -->http://l.autohotkey....Ex-QuickRef.htm<!-- m -->

\w
Matches any single "word" character, namely alphanumeric or underscore.
This is equivalent to [a-zA-Z0-9_].

+
A plus sign matches one or more of the preceding character, class, or subpattern.

Win7 (x64)
Look up commands faster by using the AutoHotkey Help File's index.
Start→AllPrograms→AutoHotkey→AutoHotkey Help File


Alpha Bravo
  • Members
  • 1687 posts
  • Last active: Nov 07 2015 03:06 PM
  • Joined: 01 Sep 2011

Or even:

Loop 26
   Hotkey, % "$" Chr(A_Index+97), Letters
return
Letters:
Send %   SubStr(alphabet,1,InStr(alphabet,SubStr(A_ThisHotkey,0)))
return

couple of things:
1- it should be Chr(A_Index+96)
2- there is no variable named 'alphabet'


Using RegEx:

alphabet := "abcdefghijklmnopqrstuvwxyz"

f1::
Inputbox, _V_, Testing,,,128,128
pattern := "\w+" _V_
RegExMatch(alphabet, pattern, match)
TrayTip,, %match%
Return

does not produce an output if input = 'a'
alphabet := "abcdefghijklmnopqrstuvwxyz"
f1::
Inputbox, _V_, Testing,,,128,128
traytip,, % RegExReplace(alphabet, "(.*" _V_ ").*", "$1")
Return


Honest Abe
  • Members
  • 310 posts
  • Last active: Jan 08 2015 08:56 PM
  • Joined: 07 Jan 2011
If an output of 'a' is desired,
you only need to replace the + with *

alphabet := "abcdefghijklmnopqrstuvwxyz"

f1::
Inputbox, _V_, Testing,,,128,128
pattern := "\w*" _V_
RegExMatch(alphabet, pattern, match)
TrayTip,, %match%
Return

*
An asterisk matches zero or more of the preceding character, class, or subpattern.

Win7 (x64)
Look up commands faster by using the AutoHotkey Help File's index.
Start→AllPrograms→AutoHotkey→AutoHotkey Help File


George88
  • Members
  • 9 posts
  • Last active: Jan 08 2016 02:46 AM
  • Joined: 13 Jul 2015
This isn't entirely on topic but I wanted to find something like this a while ago to navigate menus by using military alphabet for speech recognition with Glove Pie. it means that you don't have to remember the names of thousands of functions.

Might be handy to someone trying to do something similar.
 
The code below will list the files in a folder and attach a letter to the start. It doesn't do anything other than show you a msgbox.
 
 
var_space := "   "
 
Loop, *.*, 1 ; return only folders at this level
{
var_letter_num++
 
GOSUB letter_swag
 
File_List .= letter_item  var_space  A_LoopFileFullPath . "`n"
StringReplace, namevar, A_LoopFileFullPath,%A_Space%,_, All
  ; FileAppend,%namevar%, File_List.ah_gen
}
 
 
 
 
msgbox , % File_List
 
 
 
 
 
letter_swag:
 
if var_letter_num = 1 
{
letter_item := "a"
}
if var_letter_num = 2 
{
letter_item := "b"
}
if var_letter_num = 3 
{
letter_item := "c"
}
if var_letter_num = 4 
{
letter_item := "d"
}
if var_letter_num = 5 
{
letter_item := "e"
}
if var_letter_num = 6 
{
letter_item := "f"
}
if var_letter_num = 7 
{
letter_item := "g"
}
if var_letter_num = 8 
{
letter_item := "h"
}
if var_letter_num = 9 
{
letter_item := "i"
}
if var_letter_num = 10 
{
letter_item := "j"
}
if var_letter_num = 11 
{
letter_item := "k"
}
if var_letter_num = 12 
{
letter_item := "l"
}
if var_letter_num = 13 
{
letter_item := "m"
}
if var_letter_num = 14 
{
letter_item := "n"
}
if var_letter_num = 15 
{
letter_item := "o"
}
if var_letter_num = 16 
{
letter_item := "p"
}
if var_letter_num = 17 
{
letter_item := "q"
}
if var_letter_num = 18 
{
letter_item := "r"
}
if var_letter_num = 19 
{
letter_item := "s"
}
if var_letter_num = 20 
{
letter_item := "t"
}
if var_letter_num = 21 
{
letter_item := "u"
}
if var_letter_num = 22 
{
letter_item := "v"
}
if var_letter_num = 23 
{
letter_item := "w"
}
if var_letter_num = 24 
{
letter_item := "x"
}
if var_letter_num = 25 
{
letter_item := "y"
}
if var_letter_num = 26 
{
letter_item := "z"
}
RETURN 


YOUCEFHam
  • Members
  • 182 posts
  • Last active: Aug 16 2016 12:53 AM
  • Joined: 14 Oct 2014
Hi, You can use this very simple :

Alfa_List = abcdefghijklmnopqrstuvwxyz
InputBox, Stop_Alfa, Enter A Letter
if !ErrorLevel
{
   Sleep, 200
   Loop, Parse, Alfa_List, %Stop_Alfa%
   {
      Send_List := A_LoopField Stop_Alfa
      break
   }
   WinActivate
   Sleep, 100
   Send, %Send_List%
}