Help adding GUI to my script. (script works, not with GUI)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jesseb
Posts: 10
Joined: 15 Oct 2013, 03:40

Help adding GUI to my script. (script works, not with GUI)

27 Oct 2013, 03:02

Okay guys, I appreciate your time to read this :D

So I got this script, works fine. It makes a hotkey (A) cycle output so that AAAA = 1234
Well basically a few people I know want to use this themselves, but all the hotkeys and such need to be changed for each person.

So I made a simple GUI to where you can simply select the keys, put in the values and click okay. After pressing okay, all the keys, and numbers are now stored in a bunch of variables, which for the most part would work fine...EXCEPT, you can't use variables as hotkeys, so I must use the hotkey command to wait for the variables to be plugged in.

So after I changed all the (A:: {code}) style hotkeys to (hotkey , %KeyVar% , Label) method, the function of the hotkeys is very broken, the cycles don't loop, or wait correctly. please help, I'm a lost noob.

I wouldn't be opposed to this script simply taking the variables and creating a new / separate script to run (plugging the vars into the write spots of the working script).
I just didn't really know how to code that up. So instead I went with the way I could picture in mind, just using the vars inside the same script, and using the hotkey command instead of the (A:: {code}) format.


Here is the working script, you can test it in notepad to see how it works. (capslock or scrollLock need to be on to test this script)

Code: Select all

VarList_1 = 1|2|3|4|5|6|7|8|9|0             ; first set of keys to be pressed (vars S1K0 - S1K9)
VarRecast_1 = 15000|10000|5000|30000|10000|15000|30000|120000|50 ;first set of recasts  (vars S1W0 - S1W9)
PauseSec_1 = 600                            ; first set cast time (var S1CT)


VarList_2 = a|b|c|d|e|f|g|h|i|j             ; second set of keys to be pressed (vars S2K0 - S2K9)
VarRecast_2 = 360000|300000|120000|120000|120000|120000|120000|30000|250  ; second set of recasts (vars S2W0 - S2W9)
PauseSec_2 = 3500                           ;second cast time (var S2CT)


Loop, 2
{
	CurrentIndex := A_Index
	Loop, parse, VarList_%CurrentIndex%, |
	{
		CurrentIndex_%CurrentIndex% := A_Index
		Maxnum_%CurrentIndex% := A_Index+1
		var%A_Index%_key_%CurrentIndex% := A_LoopField
		Loop, parse, VarRecast_%CurrentIndex%, |
		{
			if (A_Index = CurrentIndex_%CurrentIndex%)
				var%A_Index%_recast_%CurrentIndex% := A_LoopField
		}
	}
}

#IfWinActive, ahk_class Notepad


LButton::                                         ; First Set Activator (Var S1A1)
Loop
{
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		Loop, parse, VarList_1, |
		{
			num_1 = 1
			if (Start%A_Index%_1 = "")
			{
				Send , % var%A_Index%_key_1
				Start%A_Index%_1 := A_TickCount
				Sleep, %PauseSec_1%
			}
			else
			{
				Elapsed%A_Index%_1 := A_TickCount - Start%A_Index%_1
				if (Elapsed%A_Index%_1 >= Var%A_Index%_recast_1)
				{
					Send , % var%A_Index%_key_1
					Start%A_Index%_1 := A_TickCount
					Sleep, %PauseSec_1%
				}
			}
			if  (GetKeyState("LButton", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("LButton", "P") = 1)
		{
			Click down
			KeyWait, LButton
			Click up
		}
		break
	}
if  (GetKeyState("LButton", "P") = 0)
	break
}
return


RButton::                                     ; Second Set Activator (Var S2A1)
Loop
{
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		Loop, parse, VarList_2, |
		{
			num_2 = 1
			if (Start%A_Index%_2 = "")
			{
				Send , % var%A_Index%_key_2
				Start%A_Index%_2 := A_TickCount
				Sleep, %PauseSec_2%
			}
			else
			{
				Elapsed%A_Index%_2 := A_TickCount - Start%A_Index%_2
				if (Elapsed%A_Index%_2 >= Var%A_Index%_recast_2)
				{
					Send , % var%A_Index%_key_2
					Start%A_Index%_2 := A_TickCount
					Sleep, %PauseSec_2%
				}
			}
			if  (GetKeyState("RButton", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("RButton", "P") = 1)
		{
			Click down right
			KeyWait, RButton
			Click up right
		}
		break
	}
if  (GetKeyState("RButton", "P") = 0)
	break
}
return


a::                                      ;First Set Activator 2 (Var S1A2)
Loop
{
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		Loop, parse, VarList_1, |
		{
			num_1 = 1
			if (Start%A_Index%_1 = "")
			{
				Send , % var%A_Index%_key_1
				Start%A_Index%_1 := A_TickCount
				Sleep, %PauseSec_1%
			}
			else
			{
				Elapsed%A_Index%_1 := A_TickCount - Start%A_Index%_1
				if (Elapsed%A_Index%_1 >= Var%A_Index%_recast_1)
				{
					Send , % var%A_Index%_key_1
					Start%A_Index%_1 := A_TickCount
					Sleep, %PauseSec_1%
				}
			}
			if  (GetKeyState("a", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("a", "P") = 1)
		{
			send , a
		}
		break
	}
if  (GetKeyState("RButton", "P") = 0)
	break
}
return


v::                            ;Second Set Activator 2 (Var S2A2)
Loop
{
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		Loop, parse, VarList_2, |
		{
			num_2 = 1
			if (Start%A_Index%_2 = "")
			{
				Send , % var%A_Index%_key_2
				Start%A_Index%_2 := A_TickCount
				Sleep, %PauseSec_2%
			}
			else
			{
				Elapsed%A_Index%_2 := A_TickCount - Start%A_Index%_2
				if (Elapsed%A_Index%_2 >= Var%A_Index%_recast_2)
				{
					Send , % var%A_Index%_key_2
					Start%A_Index%_2 := A_TickCount
					Sleep, %PauseSec_2%
				}
			}
			if  (GetKeyState("v", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("v", "P") = 1)
		{
			Send , v
		}
		break
	}
if  (GetKeyState("v", "P") = 0)
	break
}
return


~CapsLock::
{
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		TrayTip, , HotKeys-Mouse: On, 10, 1
	}
	else if  (GetKeyState("CapsLock", "T") = 0)
	{
		TrayTip, , HotKeys-Mouse: Off, 10, 1
	}
}
return


~ScrollLock::
{
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		TrayTip, , HotKeys-Key: On, 10, 1
	}
	else if  (GetKeyState("ScrollLock", "T") = 0)
	{
		TrayTip, , HotKeys-Key: Off, 10, 1
	}
}
return


~MButton & WheelDown::
{
	SetStoreCapslockMode, off
	send , {capslock}
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		TrayTip, , HotKeys-Mouse: On, 10, 1
	}
	else if  (GetKeyState("CapsLock", "T") = 0)
	{
		TrayTip, , HotKeys-Mouse: Off, 10, 1
	}	
}
Return


~MButton & WheelUp::
{
	SetStoreCapslockMode, off
	send , {scrolllock}
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		TrayTip, , HotKeys-Key: On, 10, 1
	}
	else if  (GetKeyState("ScrollLock", "T") = 0)
	{
		TrayTip, , HotKeys-Key: Off, 10, 1
	}
}
Return

#IfWinActive ahk_class Notepad
And this is the GUI, read notes in the code above to see where the variables go.

Code: Select all

DropDownListPart1 = NONE||1|2|3|4|5|6|7|8|9|0|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
DropDownListPart2 = ``|-|=|[|]|\|,|.|/
DropDownListPart3 = Space|Tab|Enter|Escape|Backspace|Delete|Insert|Home|End|PgUp|PgDn
DropDownListPart4 = Up|Down|Left|Right|ScrollLock|CapsLock|NumLock
DropDownListPart5 = Click Left|Click Right|Click Middle|NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|NumpadDel|NumpadIns|NumpadClear
DropDownListPart6 = NumpadUp|NumpadDown|NumpadLeft|NumpadRight|NumpadHome|NumpadEnd|NumpadPgUp|NumpadPgDn
DropDownListPart7 = Numpad0|Numpad1|Numpad2|Numpad3|Numpad4|Numpad5|Numpad6|Numpad7|Numpad8|Numpad9|NumpadDot
DropDownListPart8 = F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12
DropDownListPart9 = AppsKey|LWin|RWin|Alt|Control|LControl|RControl|Shift|LShift|RShift|LAlt|RAlt|PrintScreen|CtrlBreak|Pause
DropDownListPart0 = Joy1|Joy2|Joy3|Joy4|Joy5|Joy6|Joy7|Joy8|Joy9|Joy10|Joy11|Joy12
DropDownListHalf1 = %DropDownListPart1%|%DropDownListPart0%|%DropDownListPart3%|%DropDownListPart4%|%DropDownListPart2%
DropDownListHalf2 = %DropDownListPart8%|%DropDownListPart7%|%DropDownListPart6%|%DropDownListPart9%|%DropDownListPart5%
DropDownListList = %DropDownListHalf1%|%DropDownListHalf2%
Gui,Add,DropDownList,x50 y40 w120 vS1A1 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y110 w120 vS1K1 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y130 w120 vS1K2 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y150 w120 vS1K3 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y170 w120 vS1K4 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y190 w120 vS1K5 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y210 w120 vS1K6 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y230 w120 vS1K7 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y250 w120 vS1K8 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y270 w120 vS1K9 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y290 w120 vS1K0 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y40 w120 vS2A1 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y110 w120 vS2K1 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y130 w120 vS2K2 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y150 w120 vS2K3 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y170 w120 vS2K4 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y190 w120 vS2K5 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y210 w120 vS2K6 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y230 w120 vS2K7 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y250 w120 vS2K8 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y270 w120 vS2K9 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y290 w120 vS2K0 gClick,%DropDownListList%
Gui,Add,Edit,x180 y110 w45 h21 Number vS1W1 gClick,Edit
Gui,Add,Edit,x180 y130 w45 h21 Number vS1W2 gClick,Edit
Gui,Add,Edit,x180 y150 w45 h21 Number vS1W3 gClick,Edit
Gui,Add,Edit,x180 y170 w45 h21 Number vS1W4 gClick,Edit
Gui,Add,Edit,x180 y190 w45 h21 Number vS1W5 gClick,Edit
Gui,Add,Edit,x180 y250 w45 h21 Number vS1W8 gClick,Edit
Gui,Add,Edit,x180 y270 w45 h21 Number vS1W9 gClick,Edit
Gui,Add,Edit,x180 y290 w45 h21 Number vS1W0 gClick,Edit
Gui,Add,Edit,x280 y110 w45 h21 Number vS2W1 gClick,Edit
Gui,Add,Edit,x280 y130 w45 h21 Number vS2W2 gClick,Edit
Gui,Add,Edit,x280 y150 w45 h21 Number vS2W3 gClick,Edit
Gui,Add,Edit,x280 y170 w45 h21 Number vS2W4 gClick,Edit
Gui,Add,Edit,x280 y190 w45 h21 Number vS2W5 gClick,Edit
Gui,Add,Edit,x280 y210 w45 h21 Number vS2W6 gClick,Edit
Gui,Add,Edit,x280 y230 w45 h21 Number vS2W7 gClick,Edit
Gui,Add,Edit,x280 y250 w45 h21 Number vS2W8 gClick,Edit
Gui,Add,Edit,x280 y270 w45 h21 Number vS2W9 gClick,Edit
Gui,Add,Edit,x280 y290 w45 h21 Number vS2W0 gClick,Edit
Gui,Add,Text,x80 y20 w60 h13 Center,Activator 1
Gui,Add,Text,x360 y20 w60 h13 Center,Activator 2
Gui,Add,Text,x80 y90 w60 h13 Center,Keys
Gui,Add,Text,x360 y90 w60 h13 Center,Keys
Gui,Add,Edit,x180 y210 w45 h21 Number vS1W6 gClick,Edit
Gui,Add,Edit,x180 y230 w45 h21 Number vS1W7 gClick,Edit
Gui,Add,Edit,x180 y40 w45 h21 Number vS1CT gClick,Edit
Gui,Add,Edit,x280 y40 w45 h21 Number vS2CT gClick,Edit
Gui,Add,DropDownList,x50 y60 w120 vS1A2 gClick,%DropDownListList%
Gui,Add,Text,x20 y50 w21 h13 Center,OR
Gui,Add,DropDownList,x330 y60 w120 vS2A2 gClick,%DropDownListList%
Gui,Add,Text,x460 y50 w21 h13,OR
Gui,Add,Button,x280 y330 w43 h23 gGuiClose,Submit
Gui,Add,Text,x229 y29 w50 h13,Cast Time
Gui,Add,Text,x220 y90 w65 h13,ReCast Time
Gui,Add,Button,x180 y330 w43 h23 gHelp,Help
Gui,Show,x429 y99 w500 h501 ,
Return

Click:
Gui, Submit , NoHide
Return

Help:
MsgBox, The keys you select for "Activator 1" will set off the keys beneath it, Same for "Activator 2" `nCast Time is the amount of time to wait between each keypress, This should be the amount of time it takes for you to "cast" or "perform" the action before the next press `nReCast Time is the amount of time (milliseconds) before that button is used again, for example if you want one key to go once a minute, and one to go once a second, make the first 60000 make the second 1000
Return

GuiClose:
Gui, Submit , NoHide
SetClose = 1
Gui, Cancel
Thanks a bunch for reading, and helping. If you need / want to see the script that is broken (my attempt at combining the GUI to the hotkeys) just comment, and I'll update the post. I started over from scratch (combining GUI with script) so it'll be a bit before I can post it.
just me
Posts: 9425
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Help adding GUI to my script. (script works, not with GU

27 Oct 2013, 03:54

Hi, is the number of hotkeys variable or fixed?
jesseb
Posts: 10
Joined: 15 Oct 2013, 03:40

Re: Help adding GUI to my script. (script works, not with GU

27 Oct 2013, 04:33

its fixed, at the moment anyway. Also not sure if you mean the the keys being sent, or the keys being pressed.
jesseb
Posts: 10
Joined: 15 Oct 2013, 03:40

Re: Help adding GUI to my script. SOLVED :D

27 Oct 2013, 08:07

Okay, so I changed things up, and got it to work, the GUI now calls a source.txt file, and puts the variables in the right place.

Run this script, with the source.txt file in the same directory

Code: Select all

S1C1 = 2
S1L3 = S1K1|S1K2|S1K3
S1L4 = S1K1|S1K2|S1K3|S1K4
S1L5 = S1K1|S1K2|S1K3|S1K4|S1K5
S1L6 = S1K1|S1K2|S1K3|S1K4|S1K5|S1K6
S1L7 = S1K1|S1K2|S1K3|S1K4|S1K5|S1K6|S1K7
S1L8 = S1K1|S1K2|S1K3|S1K4|S1K5|S1K6|S1K7|S1K8
S1L9 = S1K1|S1K2|S1K3|S1K4|S1K5|S1K6|S1K7|S1K8|S1K9
S1L0 = S1K1|S1K2|S1K3|S1K4|S1K5|S1K6|S1K7|S1K8|S1K9|S1K0
S2C1 = 2
S2L3 = S2K1|S2K2|S2K3
S2L4 = S2K1|S2K2|S2K3|S2K4
S2L5 = S2K1|S2K2|S2K3|S2K4|S2K5
S2L6 = S2K1|S2K2|S2K3|S2K4|S2K5|S2K6
S2L7 = S2K1|S2K2|S2K3|S2K4|S2K5|S2K6|S2K7
S2L8 = S2K1|S2K2|S2K3|S2K4|S2K5|S2K6|S2K7|S2K8
S2L9 = S2K1|S2K2|S2K3|S2K4|S2K5|S2K6|S2K7|S2K8|S2K9
S2L0 = S2K1|S2K2|S2K3|S2K4|S2K5|S2K6|S2K7|S2K8|S2K9|S2K0
FileRead, Source, source.txt
DropDownListPart1 = NONE||1|2|3|4|5|6|7|8|9|0|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
DropDownListPart2 = ``|-|=|[|]|\|,|.|/
DropDownListPart3 = Space|Tab|Enter|Escape|Backspace|Delete|Insert|Home|End|PgUp|PgDn
DropDownListPart4 = Up|Down|Left|Right|ScrollLock|CapsLock|NumLock
DropDownListPart5 = Click Left|Click Right|Click Middle|NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|NumpadDel|NumpadIns|NumpadClear
DropDownListPart6 = NumpadUp|NumpadDown|NumpadLeft|NumpadRight|NumpadHome|NumpadEnd|NumpadPgUp|NumpadPgDn
DropDownListPart7 = Numpad0|Numpad1|Numpad2|Numpad3|Numpad4|Numpad5|Numpad6|Numpad7|Numpad8|Numpad9|NumpadDot
DropDownListPart8 = F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12
DropDownListPart9 = AppsKey|LWin|RWin|Alt|Control|LControl|RControl|Shift|LShift|RShift|LAlt|RAlt|PrintScreen|CtrlBreak|Pause
DropDownListPart0 = Joy1|Joy2|Joy3|Joy4|Joy5|Joy6|Joy7|Joy8|Joy9|Joy10|Joy11|Joy12
DropDownListHalf1 = %DropDownListPart1%|%DropDownListPart0%|%DropDownListPart3%|%DropDownListPart4%|%DropDownListPart2%
DropDownListHalf2 = %DropDownListPart8%|%DropDownListPart7%|%DropDownListPart6%|%DropDownListPart9%|%DropDownListPart5%
DropDownListList = %DropDownListHalf1%|%DropDownListHalf2%
Gui,Add,DropDownList,x50 y40 w120 vS1A1 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y60 w120 vS1A2 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y110 w120 vS1K1 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y130 w120 vS1K2 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y150 w120 vS1K3 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y170 w120 vS1K4 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y190 w120 vS1K5 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y210 w120 vS1K6 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y230 w120 vS1K7 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y250 w120 vS1K8 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y270 w120 vS1K9 gClick,%DropDownListList%
Gui,Add,DropDownList,x50 y290 w120 vS1K0 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y40 w120 vS2A1 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y60 w120 vS2A2 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y110 w120 vS2K1 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y130 w120 vS2K2 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y150 w120 vS2K3 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y170 w120 vS2K4 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y190 w120 vS2K5 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y210 w120 vS2K6 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y230 w120 vS2K7 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y250 w120 vS2K8 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y270 w120 vS2K9 gClick,%DropDownListList%
Gui,Add,DropDownList,x330 y290 w120 vS2K0 gClick,%DropDownListList%
Gui,Add,Edit,x180 y110 w45 h21 Number vS1W1 gClick,Edit
Gui,Add,Edit,x180 y130 w45 h21 Number vS1W2 gClick,Edit
Gui,Add,Edit,x180 y150 w45 h21 Number vS1W3 gClick,Edit
Gui,Add,Edit,x180 y170 w45 h21 Number vS1W4 gClick,Edit
Gui,Add,Edit,x180 y190 w45 h21 Number vS1W5 gClick,Edit
Gui,Add,Edit,x180 y210 w45 h21 Number vS1W6 gClick,Edit
Gui,Add,Edit,x180 y230 w45 h21 Number vS1W7 gClick,Edit
Gui,Add,Edit,x180 y250 w45 h21 Number vS1W8 gClick,Edit
Gui,Add,Edit,x180 y270 w45 h21 Number vS1W9 gClick,Edit
Gui,Add,Edit,x180 y290 w45 h21 Number vS1W0 gClick,Edit
Gui,Add,Edit,x280 y110 w45 h21 Number vS2W1 gClick,Edit
Gui,Add,Edit,x280 y130 w45 h21 Number vS2W2 gClick,Edit
Gui,Add,Edit,x280 y150 w45 h21 Number vS2W3 gClick,Edit
Gui,Add,Edit,x280 y170 w45 h21 Number vS2W4 gClick,Edit
Gui,Add,Edit,x280 y190 w45 h21 Number vS2W5 gClick,Edit
Gui,Add,Edit,x280 y210 w45 h21 Number vS2W6 gClick,Edit
Gui,Add,Edit,x280 y230 w45 h21 Number vS2W7 gClick,Edit
Gui,Add,Edit,x280 y250 w45 h21 Number vS2W8 gClick,Edit
Gui,Add,Edit,x280 y270 w45 h21 Number vS2W9 gClick,Edit
Gui,Add,Edit,x280 y290 w45 h21 Number vS2W0 gClick,Edit
Gui,Add,Edit,x180 y40 w45 h21 Number vS1CT gClick,Edit
Gui,Add,Edit,x280 y40 w45 h21 Number vS2CT gClick,Edit
Gui,Add,Text,x80 y20 w60 h13 Center,Activator 1
Gui,Add,Text,x360 y20 w60 h13 Center,Activator 2
Gui,Add,Text,x80 y90 w60 h13 Center,Keys
Gui,Add,Text,x360 y90 w60 h13 Center,Keys
Gui,Add,Text,x20 y50 w21 h13 Center,OR
Gui,Add,Text,x460 y50 w21 h13,OR
Gui,Add,Button,x280 y355 w43 h23 gGuiClose,Submit
Gui,Add,Text,x229 y29 w50 h13,Cast Time
Gui,Add,Text,x220 y90 w65 h13,ReCast Time
Gui,Add,Button,x180 y355 w43 h23 gHelp,Help
Gui,Add,Edit,x189 y331 w123 h21 1 vMyFile gClick,File Name Here
Gui,Add,Checkbox,x20 y155 w30 h13 vS1T3 gClick,----
Gui,Add,Checkbox,x20 y175 w30 h13 vS1T4 gClick,----
Gui,Add,Checkbox,x20 y195 w30 h13 vS1T5 gClick,----
Gui,Add,Checkbox,x20 y215 w30 h13 vS1T6 gClick,----
Gui,Add,Checkbox,x20 y235 w30 h13 vS1T7 gClick,----
Gui,Add,Checkbox,x20 y255 w30 h13 vS1T8 gClick,----
Gui,Add,Checkbox,x20 y275 w30 h13 vS1T9 gClick,----
Gui,Add,Checkbox,x20 y295 w30 h13 vS1T0 gClick,----
Gui,Add,Text,x451 y156 w15 h13,----
Gui,Add,Text,x451 y176 w15 h13,----
Gui,Add,Text,x451 y196 w15 h13,----
Gui,Add,Text,x451 y216 w15 h13,----
Gui,Add,Text,x451 y236 w15 h13,----
Gui,Add,Text,x451 y256 w15 h13,----
Gui,Add,Text,x451 y276 w15 h13,----
Gui,Add,Text,x451 y296 w15 h13,----
Gui,Add,Checkbox,x465 y155 w30 h13 vS2T3 gClick,
Gui,Add,Checkbox,x465 y175 w30 h13 vS2T4 gClick,
Gui,Add,Checkbox,x465 y195 w30 h13 vS2T5 gClick,
Gui,Add,Checkbox,x465 y215 w30 h13 vS2T6 gClick,
Gui,Add,Checkbox,x465 y235 w30 h13 vS2T7 gClick,
Gui,Add,Checkbox,x465 y255 w30 h13 vS2T8 gClick,
Gui,Add,Checkbox,x465 y275 w30 h13 vS2T9 gClick,
Gui,Add,Checkbox,x465 y295 w30 h13 vS2T0 gClick,
Gui,Show,x429 y99 w500 h501 , 
Return
#NoEnv


Click:
Gui, Submit , NoHide
Return

Help:
MsgBox, The keys you select for "Activator 1" will set off the keys beneath it, Same for "Activator 2" `nCast Time is the amount of time to wait between each keypress, This should be the amount of time it takes for you to "cast" or "perform" the action before the next press `nReCast Time is the amount of time (milliseconds) before that button is used again, for example if you want one key to go once a minute, and one to go once a second, make the first 60000 make the second 1000
Return

GuiClose:
Gui, Submit , NoHide
if S1T3 = 1
	S1C1 = 3
if S1T4 = 1
	S1C1 = 4
if S1T5 = 1
	S1C1 = 5
if S1T6 = 1
	S1C1 = 6
if S1T7 = 1
	S1C1 = 7
if S1T8 = 1
	S1C1 = 8
if S1T9 = 1
	S1C1 = 9
if S1T0 = 1
	S1C1 = 10
if S1C1 = 3
	StringReplace, Source, Source, S1K1|S1K2 , %S1L3%, A
if S1C1 = 4
	StringReplace, Source, Source, S1K1|S1K2 , %S1L4%, A
if S1C1 = 5
	StringReplace, Source, Source, S1K1|S1K2 , %S1L5%, A
if S1C1 = 6
	StringReplace, Source, Source, S1K1|S1K2 , %S1L6%, A
if S1C1 = 7
	StringReplace, Source, Source, S1K1|S1K2 , %S1L7%, A
if S1C1 = 8
	StringReplace, Source, Source, S1K1|S1K2 , %S1L8%, A
if S1C1 = 9
	StringReplace, Source, Source, S1K1|S1K2 , %S1L9%, A
if S1C1 = 10
	StringReplace, Source, Source, S1K1|S1K2 , %S1L0%, A
if S2T3 = 1
	S2C1 = 3
if S2T4 = 1
	S2C1 = 4
if S2T5 = 1
	S2C1 = 5
if S2T6 = 1
	S2C1 = 6
if S2T7 = 1
	S2C1 = 7
if S2T8 = 1
	S2C1 = 8
if S2T9 = 1
	S2C1 = 9
if S2T0 = 1
	S2C1 = 10
if S2C1 = 3
	StringReplace, Source, Source, S2K1|S2K2 , %S2L3%, A
if S2C1 = 4
	StringReplace, Source, Source, S2K1|S2K2 , %S2L4%, A
if S2C1 = 5
	StringReplace, Source, Source, S2K1|S2K2 , %S2L5%, A
if S2C1 = 6
	StringReplace, Source, Source, S2K1|S2K2 , %S2L6%, A
if S2C1 = 7
	StringReplace, Source, Source, S2K1|S2K2 , %S2L7%, A
if S2C1 = 8
	StringReplace, Source, Source, S2K1|S2K2 , %S2L8%, A
if S2C1 = 9
	StringReplace, Source, Source, S2K1|S2K2 , %S2L9%, A
if S2C1 = 10
	StringReplace, Source, Source, S2K1|S2K2 , %S2L0%, A
StringReplace, Source, Source, S1A1 , %S1A1%, A
StringReplace, Source, Source, S1A2 , %S1A2%, A
StringReplace, Source, Source, S2A2 , %S2A2%, A
StringReplace, Source, Source, S1K1 , %S1K1%, A
StringReplace, Source, Source, S1K2 , %S1K2%, A
StringReplace, Source, Source, S1K3 , %S1K3%, A
StringReplace, Source, Source, S1K4 , %S1K4%, A
StringReplace, Source, Source, S1K5 , %S1K5%, A
StringReplace, Source, Source, S1K6 , %S1K6%, A
StringReplace, Source, Source, S1K7 , %S1K7%, A
StringReplace, Source, Source, S1K8 , %S1K8%, A
StringReplace, Source, Source, S1K9 , %S1K9%, A
StringReplace, Source, Source, S1K0 , %S1K0%, A
StringReplace, Source, Source, S2A1 , %S2A1%, A
StringReplace, Source, Source, S2K1 , %S2k1%, A
StringReplace, Source, Source, S2K2 , %S2k2%, A
StringReplace, Source, Source, S2K3 , %S2k3%, A
StringReplace, Source, Source, S2K4 , %S2k4%, A
StringReplace, Source, Source, S2K5 , %S2k5%, A
StringReplace, Source, Source, S2K6 , %S2k6%, A
StringReplace, Source, Source, S2K7 , %S2k7%, A
StringReplace, Source, Source, S2K8 , %S2k8%, A
StringReplace, Source, Source, S2K9 , %S2k9%, A
StringReplace, Source, Source, S2K0 , %S2k0%, A
StringReplace, Source, Source, S1W1 , %S1W1%, A
StringReplace, Source, Source, S1W2 , %S1W2%, A
StringReplace, Source, Source, S1W3 , %S1W3%, A
StringReplace, Source, Source, S1W4 , %S1W4%, A
StringReplace, Source, Source, S1W5 , %S1W5%, A
StringReplace, Source, Source, S1W6 , %S1W6%, A
StringReplace, Source, Source, S1W7 , %S1W7%, A
StringReplace, Source, Source, S1W8 , %S1W8%, A
StringReplace, Source, Source, S1W9 , %S1W9%, A
StringReplace, Source, Source, S1W0 , %S1W0%, A
StringReplace, Source, Source, S2W1 , %S2W1%, A
StringReplace, Source, Source, S2W2 , %S2W2%, A
StringReplace, Source, Source, S2W3 , %S2W3%, A
StringReplace, Source, Source, S2W4 , %S2W4%, A
StringReplace, Source, Source, S2W5 , %S2W5%, A
StringReplace, Source, Source, S2W6 , %S2W6%, A
StringReplace, Source, Source, S2W7 , %S2W7%, A
StringReplace, Source, Source, S2W8 , %S2W8%, A
StringReplace, Source, Source, S2W9 , %S2W9%, A
StringReplace, Source, Source, S2W0 , %S2W0%, A
StringReplace, Source, Source, S1CT , %S1CT%, A
StringReplace, Source, Source, S2CT , %S2CT%, A
FileAppend, %Source%, %MyFile%.ahk
Gui, Cancel
exitapp
This is the source.txt file to be stored in the same directory as the script
Emphasis, on the .TXT :p

Code: Select all

VarList_1 = S1K1|S1K2
VarRecast_1 = S1W1|S1W2|S1W3|S1W4|S1W5|S1W6|S1W7|S1W8|S1W9|S1W0
PauseSec_1 = S1CT

VarList_2 = S2K1|S2K2|S2K3|S2K4|S2K5|S2K6|S2K7|S2K8|S2K9|S2K0
VarRecast_2 = S2W1|S2W2|S2W3|S2W4|S2W5|S2W6|S2W7|S2W8|S2W9|S2W0
PauseSec_2 = S2CT



Loop, 2
{
	CurrentIndex := A_Index
	Loop, parse, VarList_%CurrentIndex%, |
	{
		CurrentIndex_%CurrentIndex% := A_Index
		Maxnum_%CurrentIndex% := A_Index+1
		var%A_Index%_key_%CurrentIndex% := A_LoopField
		Loop, parse, VarRecast_%CurrentIndex%, |
		{
			if (A_Index = CurrentIndex_%CurrentIndex%)
				var%A_Index%_recast_%CurrentIndex% := A_LoopField
		}
	}
}

#IfWinActive, ahk_class Notepad


S1A1::
Loop
{
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		Loop, parse, VarList_1, |
		{
			num_1 = 1
			if (Start%A_Index%_1 = "")
			{
				Send , % var%A_Index%_key_1
				Start%A_Index%_1 := A_TickCount
				Sleep, %PauseSec_1%
			}
			else
			{
				Elapsed%A_Index%_1 := A_TickCount - Start%A_Index%_1
				if (Elapsed%A_Index%_1 >= Var%A_Index%_recast_1)
				{
					Send , % var%A_Index%_key_1
					Start%A_Index%_1 := A_TickCount
					Sleep, %PauseSec_1%
				}
			}
			if  (GetKeyState("S1A1", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("S1A1", "P") = 1)
		{
			send , S1A1
		}
		break
	}
if  (GetKeyState("S1A1", "P") = 0)
	break
}
return


S2A1::
Loop
{
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		Loop, parse, VarList_2, |
		{
			num_2 = 1
			if (Start%A_Index%_2 = "")
			{
				Send , % var%A_Index%_key_2
				Start%A_Index%_2 := A_TickCount
				Sleep, %PauseSec_2%
			}
			else
			{
				Elapsed%A_Index%_2 := A_TickCount - Start%A_Index%_2
				if (Elapsed%A_Index%_2 >= Var%A_Index%_recast_2)
				{
					Send , % var%A_Index%_key_2
					Start%A_Index%_2 := A_TickCount
					Sleep, %PauseSec_2%
				}
			}
			if  (GetKeyState("S2A1", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("S2A1", "P") = 1)
		{
			send , S2A1
		}
		break
	}
if  (GetKeyState("S2A1", "P") = 0)
	break
}
return


S1A2::
Loop
{
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		Loop, parse, VarList_1, |
		{
			num_1 = 1
			if (Start%A_Index%_1 = "")
			{
				Send , % var%A_Index%_key_1
				Start%A_Index%_1 := A_TickCount
				Sleep, %PauseSec_1%
			}
			else
			{
				Elapsed%A_Index%_1 := A_TickCount - Start%A_Index%_1
				if (Elapsed%A_Index%_1 >= Var%A_Index%_recast_1)
				{
					Send , % var%A_Index%_key_1
					Start%A_Index%_1 := A_TickCount
					Sleep, %PauseSec_1%
				}
			}
			if  (GetKeyState("S1A2", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("S1A2", "P") = 1)
		{
			send , S1A2
		}
		break
	}
if  (GetKeyState("S1A2", "P") = 0)
	break
}
return


S2A2::
Loop
{
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		Loop, parse, VarList_2, |
		{
			num_2 = 1
			if (Start%A_Index%_2 = "")
			{
				Send , % var%A_Index%_key_2
				Start%A_Index%_2 := A_TickCount
				Sleep, %PauseSec_2%
			}
			else
			{
				Elapsed%A_Index%_2 := A_TickCount - Start%A_Index%_2
				if (Elapsed%A_Index%_2 >= Var%A_Index%_recast_2)
				{
					Send , % var%A_Index%_key_2
					Start%A_Index%_2 := A_TickCount
					Sleep, %PauseSec_2%
				}
			}
			if  (GetKeyState("S2A2", "P") = 0)
				break
		}
	}
	else
	{
		if  (GetKeyState("S2A2", "P") = 1)
		{
			Send , S2A2
		}
		break
	}
if  (GetKeyState("S2A2", "P") = 0)
	break
}
return



~CapsLock::
{
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		TrayTip, , HotKeys-Mouse: On, 10, 1
	}
	else if  (GetKeyState("CapsLock", "T") = 0)
	{
		TrayTip, , HotKeys-Mouse: Off, 10, 1
	}
}
return


~ScrollLock::
{
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		TrayTip, , HotKeys-Key: On, 10, 1
	}
	else if  (GetKeyState("ScrollLock", "T") = 0)
	{
		TrayTip, , HotKeys-Key: Off, 10, 1
	}
}
return


~MButton & WheelDown::
{
	SetStoreCapslockMode, off
	send , {capslock}
	if  (GetKeyState("CapsLock", "T") = 1)
	{
		TrayTip, , HotKeys-Mouse: On, 10, 1
	}
	else if  (GetKeyState("CapsLock", "T") = 0)
	{
		TrayTip, , HotKeys-Mouse: Off, 10, 1
	}	
}
Return


~MButton & WheelUp::
{
	SetStoreCapslockMode, off
	send , {scrolllock}
	if  (GetKeyState("ScrollLock", "T") = 1)
	{
		TrayTip, , HotKeys-Key: On, 10, 1
	}
	else if  (GetKeyState("ScrollLock", "T") = 0)
	{
		TrayTip, , HotKeys-Key: Off, 10, 1
	}
}
Return

#IfWinActive ahk_class Notepad
End result is a saved ahk file seperate from the gui that has the hotkeys.

Edit, now you can choose how many buttons to press, instead of just 10

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Mannaia666, skeerrt and 156 guests