Jump to content

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

Hopefully Gamers can use this for simple key scripts


  • Please log in to reply
No replies to this topic
  • Members
  • 234 posts
  • Last active: Dec 30 2011 11:24 PM
  • Joined: 08 Nov 2009
; SpamSpamSpam - Easy Script Creator for beginer ahk gamers. Public Domain, free to use anyway you want.

#SingleInstance force 

#NoEnv

Gosub Spam_Init

; Don't change the above unless you know what you are doing

;

; Edit the lines between the #### lines to your needs, see HELP in comments at end of file.

; ##################################################################################################################

; First Define a key list

SpamKey1={w1 F5}+{ enter}^!{w3000 click 50,150 5/200}		; various rubbish test keys, 

			,{wheelup 5/200}{mbutton down/-1}{space 10/50}	; shows how to handle long key list

			,{w100 up 5/0}{left 5/-1}{down/-1}{right 5}		; continuation lines MUST start with ,

;

; Then get ready to Make the Script; Supply a ScriptName, a HotKey, and the KeyList

; 

SpamMakeScript("AScript.ahk","!s",SpamKey1) 	; hotkey is alt-s

;

; Can either be SpamKey= then SpamMakeScript, or a bunch of SpamKeys then a bunch of SpamMakeScript

;

SpamKey2={w1000 f1}{space 5/-1}					; wait 1 sec press F1 then 5 spaces as fast as possible

SpamKey3={left 5/50}{w500 enter}{right 5/50}	; left 5 times with 50ms between, wait 1/2 sec, right 5 times

SpamKey4={space 3/-1}{w500 space 3/-1}			; press space 3 times fast as possible, wait 1/2 sec, 3 more 

;

SpamMakeScript("AScript.ahk","+F1",SpamKey2)	; if name is same this is appended to same file, hotkey Shift-F1

SpamMakeScript("AScript.ahk","#d",SpamKey3)		; Hotkey Win-d

SpamMakeScript("BScript.ahk","^space",SpamKey4) ; Hotkey Contol-space, in a different script file

SpamMakeScript("CScript.ahk","#up","{WheelUp 15/1000}") ; for short key lists enter them directly between "'s

; ##################################################################################################################

; Once you are happy, save your File to a new name, eg SpamMyStuff.ahk, then run that script to generate you Script

TrayTip, %A_ScriptName%, Complete,,1

Sleep 3000

ExitApp

;

; SpamStuff - Don't change unless you know what you are doing

;

Spam_Init:

SetBatchLines -1

SetWorkingDir %A_ScriptDir%

Spam_Version:="v 0.1a"

FormatTime Spam_DateTime

Spam_AutoExec=				

(

Created by %A_ScriptName% version %Spam_Version% on %Spam_DateTime% by %A_UserName%

#SingleInstance force

#NoEnv

SetBatchLines -1

; Put any global commands after this line



Return ; and before this line

; End of AutoExec Section

)

SetBatchLines -1

Return

SpamMakeScript(SM_ScriptName, SM_HotK, SM_KeyList) ; Scriptname - include .ahk

{

	Static SM_LastScript=""

	Global Spam_AutoExec

	If (SM_ScriptName!=SM_LastScript) {

		If (FileExist(SM_ScriptName)) {

			MsgBox,0x101,%A_ScriptName%, File '%SM_ScriptName%' exists`, OverWriter file?

			IfMsgBox Cancel

				ExitApp

			FileDelete %SM_ScriptName%

			If (ErrorLevel) {

				MsgBox,0,%A_ScriptName%, Unable to delete file '%SM_ScriptName%'!`n Exiting...

				ExitApp

				}

		}

	FileAppend `; %SM_ScriptName% %A_Tab%-%A_Space%, %SM_ScriptName%

	FileAppend %Spam_AutoExec%`n, %SM_ScriptName%

	SM_LastScript:=SM_ScriptName

	}

	FileAppend %SM_HotK%::%A_Tab%%A_Tab%%A_Tab%%A_Tab%`; Begin %SM_HotK%`n, %SM_ScriptName%

	FileAppend % Spam_Interpret(SM_KeyList) , %SM_ScriptName%

	FileAppend Return`n`; End of Hotkey %SM_HotK%`n, %SM_ScriptName%

}

	

Spam_Interpret(SI_String)

{

	SI_String:=substr(SI_String,1,-1)

	Loop, Parse,SI_String,},`,%A_Space%%A_Tab%	; get rid of whitespace, plus commas used for continuation sections	

		{

		SI_ByRefString:=A_LoopField, SI_Mouse:=SI_Key:=""

		If (SI_Wait:=Spam_ExtractAfter("w", SI_ByRefString))

			SI_Output.="Sleep " . SI_Wait . "`n"

		If (SI_WaitKey:=Spam_ExtractAfter("/", SI_ByRefString))

			If (instr(SI_ByRefString,"click") or instr(SI_ByRefString,"button") or instr(SI_ByRefString,"wheel")) {

				SI_Output.=SI_Mouse:="_Spam[MouseDelay]:=A_MouseDelay`n"	; a variable hopefully not used elsewhere

				SI_Output.="SetMouseDelay " . SI_WaitKey . "`n"

				}

			Else {

				SI_Output.=SI_Key:="_Spam[KeyDelay]:=A_KeyDelay`n"

				SI_Output.="SetKeyDelay " . SI_WaitKey . "`n"

				}

		SI_Output.="Send " . SI_ByRefString . "}`n"

		If (SI_Key)

			SI_Output.="SetKeyDelay %_Spam[KeyDelay]%`n"

		If (SI_Mouse)

			SI_Output.="SetMouseDelay %_Spam[MouseDelay]%`n"

		}

	Return, SI_Output

}

;

Spam_ExtractAfter(SE_MatchChar,ByRef SE_InStr) 

{

	SE_Pos:=RegExMatch(SE_InStr,"i)" . SE_MatchChar . "-?\d+", SE_Match)

	SE_InStr:=RegExReplace(SE_InStr, "i)" . SE_Match . "\s*","","",1,1)

	SE_Match:=SubStr(SE_Match, 2)

	Return SE_Match

}		

; ===========================================================================================

; HELP											HELP									HELP!

; ===========================================================================================

;

; SpamSpamSpam is a script to create scripts to define hotkeys

; ------------

; You need to know a couple of things about AutoHotket.

; a. Variables names 

; b. Key Definitions, and

; c. HotKey Definitions

;

; These are in the AutoHotkey Help file 'AutoHotkey.chm' in 'Program Files\AutoHotkey' (by default)

; lookup 'Variables', the 'Send/SendRaw/SendInput...' page under the 'Keyboard Control' Tab, and 'Hotkeys'

; they are also online at:

; a. http://www.autohotkey.com/docs/Variables.htm

; b. http://www.autohotkey.com/docs/commands/Send.htm#SendInput

; c. http://www.autohotkey.com/docs/Hotkeys.htm  (don't bother with the * ~ $ modifiers yet)

;

; Read that then start creating your KeyList.

; ===== Part 1 - KeyLists ===================================================================

; A KeyList is any number of {KeyDef}'s, these are assigned (=) to a variable

; eg MyKeyList={down}{F1}{enter}!{down}{space}

; As listed in the doc, ! is the Alt prefix, ^ Control, + Shift, # WindowsKey 

; eg +^{tab} is Shift-Control-Tab

; If your KeyList is long you can use a continuation section by starting the next line with a coma

; eg Long_Key_List={space}{enter}{space}{LShift Down}{space}{space}

;            		,{LShift Up}{space}{enter}{space}

;					,^{Escape}+{F1}

;

; KeyDef's can have a number to repeat the key a number of times, eg {Space 5}

;

; SpamSpamSpam has some special KeyDef's to help with timing, they are

; 1. WaitBefore, and

; 2. WaitBetween 

; WaitBefore - allows the script to sleep for a number of milliseconds before the KeyDef is pressed

; to do a WaitBefore, use 'Wnnnn' after the '{' of your KeyDef; nnnn is the Milliseconds, 1000ms = 1 Second

; eg. !{w500 Numpad5 2}   	- this says wait 500 ms (1/2 sec) press Alt-Numpad5 two times

; WaitBetween - allows the script to specify the delay between multiple key presses, you may not need WaitBetween

; to do a WaitBetween use '/nnnn' after the key repeat number, nnnn is Milliseconds

; eg {space 5/200}			- this says press space sleep for 1/5 sec press space etc. 5 times

; If you use WaitBetween with {click x,y,ClickCount} /nnnn should be the last paraameter eg {click 50,100,5/50}

; There are two special values for WaitBetween, -1 is no delay, 0 is smallest possible delay. You may not need them.

; ===== Part 2 - SpamMakeScript =================================================================

; Once you have you KeyList you need to pick a name for you script and a HotKeyDef to trigger your KeyList.

; Pick a name that reflects what the script is for, such as MyFavGameSpamKeys.ahk

; HotKeyDef must be unique and not used by you programs

; Pick a HotKeyDef to suit the actions that other normal keys are used for,

; eg Where Space is a trigger, you could use Alt-Space for auto fire mode.

; As listed in the doc, ! is the Alt prefix, ^ Control, + Shift, # WindowsKey 

; Hence '!space' is Alt-Space.

;

; We can then make out script with, SpamMakeScript("MyScriptName","MyHoyKeyDef",MyKeyDef) - not no "" for the last one

; eg SpamMakeScript("MyFacGameSpamKeys.ahk","!space",Long_Key_List);

;

; If the fileexists SpamSpamSpam will ask if you want to overwrite the file.

; When you have multiple KeyLists, you can use multiple SpamMakeScript calls with the same or different ScriptNames

; With the same ScriptName it append the KeyList script to the previous script file

; This allows you to generate a number of HotKeys in one script.

; eg Fire5={space 5/0}, JigL_Fire={left 2/100}{down down}{w100 space 2/0}{down up}

;    JigR_Fire {right 2/100}{down down}{w100 space 2/0}{down up}

;    SpamMakeScript("FireControls.ahk","!space",Fire5)				- Alt-Space

;    SpamMakeScript("FireControls.ahk","<^space",JigLeftFire)		- Left-Control-Space

;    SpamMakeScript("FireControls.ahk",">^space",JigLeftFire)		- Right-Control-Space

; All three Hotkeys are in the FireControls.ahk script

; If you have a short KeyList you canuse it directly with SpamMakeScript

; eg SpamMakeScript("MyShortCuts.ahk","+F1","!{home}")

; eg SpamMakeScript("MyShortCuts.ahk","+F2","!{Left}")

; ===== Part 3 - Using the Script ==============================================================

; Once you have edited the SpamSpamSpam.ahk file changing the bits between the ### lines,

; Save the file to a new name, eg SpamFireControl.ahk.

; The open a explorrer window to the directory where SpamSpamSpam.aahk is,

; Double Click on SpamFireControl.ahk to run it.

; A Tray tip will popup saying 'Complete'. You now should have you generated scripts.

; Refresh the Explorer window or scroll to the bottom to find the files.

; Double Click on you script, eg FireControl.ahk, and if you haven't done any typos it should load.

; Test each hotkey (but be careful if any will do something bad like ^{a}{del} which may delete all your files.

; Enjoy...