New AutoHotkey Script Template

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: New AutoHotkey Script Template

Re: New AutoHotkey Script Template

by DaveT1 » 04 Jan 2022, 13:17

Thanks for this thread. Borrowing from you and others, this is what I'm currently using as a script header:

Code: Select all

{ ; Script Information ==================================================================
;
; Name:        Add#IncludeCode.ahk
; AHK Version: AutoHotkey_2.0-beta.3
; OS Version:  Microsoft Windows 10 Pro
; Author:      MyForumName (AUTOHOTKEY forums)
; Topic:			https://www.autohotkey.com/boards/viewtopic.php?f=81&t=97798
;
; Description:
;		- Item one of the description.
;		- Another item of the description.
;		- Further description point.
;
; Revision History: 
; (+) NEW, (*) CHANGED, (!) FIXED
; vX(new or changed functionality / maybe not backwards compatible).Y(minor revisons).
; ---------------------------------------------------------------------------------------
; v1.0 02-Jan-22	+ Initial release.
;
;\Script Information ===================================================================
}
Note that I include braces around this so this 'header' can be collapsed in case it gets too visually distracting.

Re: New AutoHotkey Script Template

by TheDewd » 28 Mar 2017, 13:09

Once again, another revision of the New AutoHotkey Script template that I'm currently using:

Code: Select all

; Script Information ===========================================================
; Name:        New AutoHotkey Script
; Description: New Script Description
; AHK Version: AHK 1.1.25.01 (Unicode 32-bit)
; OS Version:  Windows 2000+
; Language:    English (United States)
; Author:      FirstName LastName <email@address.xyz>
; Filename:    New AutoHotkey Script.ahk
; ==============================================================================

; Revision History =============================================================
; Revision 1 (YYYY-MM-DD)
; * Initial release
; ==============================================================================

; Auto-Execute =================================================================
#SingleInstance, Force ; Allow only one running instance of script
#Persistent ; Keep the script permanently running until terminated
#NoEnv ; Avoid checking empty variables for environment variables
#Warn ; Enable warnings to assist with detecting common errors
;#NoTrayIcon ; Disable the tray icon of the script
SetWorkingDir, % A_ScriptDir ; Set the working directory of the script
SetBatchLines, -1 ; The speed at which the lines of the script are executed
SendMode, Input ; The method for sending keystrokes and mouse clicks
;DetectHiddenWindows, On ; The visibility of hidden windows by the script
;SetWinDelay, -1 ; The delay to occur after modifying a window
;SetControlDelay, -1 ; The delay to occur after modifying a control
OnExit("OnUnload") ; Run a subroutine or function when exiting the script

return ; End automatic execution
; ==============================================================================

; Labels =======================================================================
GuiEscape:
GuiClose:
ExitSub:
    ExitApp ; Terminate the script unconditionally
return
; ==============================================================================

; Functions ====================================================================
OnLoad() {
    Global ; Assume-global mode
    Static Init := OnLoad() ; Call function

    Menu, Tray, Tip, New AutoHotkey Script
}

OnUnload(ExitReason, ExitCode) {
    Global ; Assume-global mode
}

GuiCreate() {
    Global ; Assume-global mode
    Static Init := GuiCreate() ; Call function

    Gui, +LastFound -Resize +HwndGuiHwnd
    Gui, Margin, 10, 10
    Gui, Add, Text, w400 h200, Sample Text
    ;Gui, Add, Tab3, vTab, Tab1|Tab2|Tab3|Tab4
    ;Gui, Tab ; Future controls are excluded from any tab control
    ;Gui, Add, Button, w75 h23 vButton1, Button1
    Gui, Show, AutoSize, Example
}

GuiSize(GuiHwnd, EventInfo, Width, Height) {
    IfEqual, ErrorLevel, 1, return ; Window minimized
}

MenuHandler(ItemName, ItemPos, MenuName) {
    MsgBox, 0x40, MenuHandler, % "Item Name: " ItemName "`n"
    . "Item Position: " ItemPos "`n"
    . "Menu Name: " MenuName
}
; ==============================================================================

Re: New AutoHotkey Script Template

by Xeo786 » 14 Jun 2016, 04:29

I am not a coder I just learned AHK my self and when I get stuck I had huge help from #ahkscript IRc and this forum I am very thank full for that :) before ahk I only knows excel and little bid macros. I have never made any tamplet file yet but yes I wana share What was my first ahk script ... I wrote my first ahk within excel and have made a macro that save as excel file into scriptmaker.ahk ... yess my first AHK code is written in excel.

1) Excel macro that save as xlsx into ahk and run that

Code: Select all

Sub ScriptMaker()
'
' ScriptMaker Macro
'
' Keyboard Shortcut: Ctrl+j
'
    Range("B2").Select
    ActiveWorkbook.Save
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="C:\Users\user\Documents\AhkScript.ahk", _
        FileFormat:=xlTextPrinter, CreateBackup:=False
    Application.DisplayAlerts = True
    ActiveWindow.Close savechanges:=True
    Shell ("C:\Program Files\AutoHotkey\AutoHotkey.exe C:\Users\user\Documents\AhkScript.ahk")
End Sub
2) my first ahk code written in scriptmaker.xlsx file I have upgraded it time to time :) so it is doing so many things. https://drive.google.com/open?id=0BzJv4 ... TQ4NS1tMlE

3) a short code that update links of / within scriptmaker.xlsx

Code: Select all

^F1::
FileDelete, D:\My Documents\SSHEDLE\*.xlsx
FileCopy, Z:\network\*.xlsx, D:\My Documents\SSHEDLE\*.*
SourcePath := "D:\My Documents\SSHEDLE\"
Loop, %SourcePath%\*.*
{
StringLeft, NewFileName, A_LoopFileName, 34
FileMove, %SourcePath%\%A_LoopFileName%, %SourcePath%\%NewFileName%.xlsx
}
msgbox, Recent schedule loaded , Scriptmaker alert
return

^F2::
XlApp := ComObjActive("Excel.Application")
G15 := XlApp.Worksheets("GAP USA COMMERCIAL").Range("G15").value

E2 = =VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,12,FALSE)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("E2").value := E2

G1 = =VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,10,FALSE)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G1").value := G1

G4 = =VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,8,FALSE)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G4").value := G4

G5 = =VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,2,FALSE)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G5").value := G5

G7 = =LEFT(SUBSTITUTE(VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,3,FALSE),"-",""),7)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G7").value := G7

G8 = =LEFT(VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,4,FALSE),6)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G8").value := G8

G9 = =VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,5,FALSE)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G9").value := G9

G10 = =VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,9,FALSE)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G10").value := G10

G13 = =VLOOKUP($B$2,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:O,7,FALSE)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G13").value := G13

G20 = =INDEX('D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!C:C,MATCH(G23,'D:\My Documents\SSHEDLE\%G15%SHIPMENT ADVICE'!E:E,0),1)
XlApp.Worksheets("GAP USA COMMERCIAL").Range("G20").value := G20

XlApp := ""
return
My first thought to do a task written in scriptmaker.xlsx and you need to see that excel file and you would find interesting. :HeHe:

and I wana know how you guys use ahk and do your tasks as I have seen tamplet.ahk and have no idea how to get used to code like you guys.

Re: New AutoHotkey Script Template

by victorel » 13 Jun 2016, 20:33

I actually had a small trouble with:

Code: Select all

SendMode, Input ; Recommended for new scripts due to its superior speed and reliability
my small piece of code

Code: Select all

;--------case conversion------------------

^u:: 
    save:=clipboard
    send, ^c
    ;sleep, 1000
    StringUpper, clipboard, clipboard
    ;sleep, 1000
    send, ^v
    clipboard:=save
return
^+u:: 
    save:=clipboard
    send, ^c
    ;sleep, 1000
    stringlower, clipboard, clipboard
    ;sleep, 1000
    send, ^v
    clipboard:=save
return
;-----------------------------------------
only worked in notepad.exe with that "sendmode input" and not in wordpad.exe, webmail and others; after dis-activating that mode, it worked fine everywhere.
Replacing "^c" with "{ctrl down}c{ctrl up}", or putting sleep in place, did not help.

Why?

Re: New AutoHotkey Script Template

by HinkerLoden » 09 Apr 2016, 11:02

Not thought that something like that stands in the OFFTOPIC :shock:

:SCRATCHINGBALLS: ( ! tHATS OFFTOPIC ! ) :mrgreen:

Nevermind. I am in progress to create 3 different Templates .

1.) General - Save Settings - description to some settings - Beginner Friendly.
2.) Performance - Speed Settings - possible unstable but fast setting and more AHK specific Commands are listed and explained
3.) Gui Variant - Save SEttings but some Gui Elements are integreated - This is more a Root-DataSheet for the Upcoming Tutorials i want to write.

First additional. OS and Versionsinfo. Not thought it is so important.

Code: Select all

;************************************************
; AHK _ SCRIPT STRUCTURE TEMPLATE v1.0
; by HinkerLoden
; 25/03/2016 
; OS  			--> 	Win 10 / etc. 
;AHK Version	-->		1.1.23.05 
;************************************************

;************************************************
;Script Global Settings
;************************************************

#NoEnv						; Clear All Systemvariables 
#Persistent 				;Keeps a script permanently running until ExitApp execute

#SingleInstance force		;The word FORCE skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.

;************************************************
;Performance PARAMETERS - if you need speed 
;************************************************
;SetBatchLines, -1   		
;Process, Priority, , L  ;A  - Max Speed
;************************************************
; Input PARAMETERS
;************************************************
SendMode Input					;Default = Event , Play - for Speed -> Set Keydelay to -1 & Setmousedely to -1 
;----
SetKeyDelay, 10, 10   			; for speed -1, -1, 
SetMouseDelay, 25				;0 recommend   /  -1 for max speed 
SetDefaultMouseSpeed, 0			;0-100 
;************************************************
;History Protocols 
;Switch setting for more Speed 
;************************************************
#KeyHistory 1					;  0 - No Keyhistory 
ListLines  On  					; Off  - for more speed 
;************************************************
;Window detection
;************************************************
SetTitleMatchMode, 2
SetTitleMatchMode Fast			;slow detect hidden windows

SetWinDelay, 200  				;0 - for more speed 
;DetectHiddenWindows, On		; | Off   
;i double the standard settings to be on the save side 
;#######################				#######################
; Script Parameter
;#######################				#######################

SetWorkingDir %A_ScriptDir%  	;Ensures a consistent starting directory.

;#Include %A_ScriptDir%\YourLibrarys2integrate.ahk

CoordMode, Pixel, Screen		;relative/Window - active Window
CoordMode, Mouse, Screen

;WinMinimizeAll					;Optional

;#######################				#######################
; Try to avoid pure numbers inside the code - adress all Vars here
;=============================================================
; 						Variable Section
;=============================================================
;#######################				#######################
;global / static
;EnvUpdate ; --> Notifies the OS and all running applications that environment variable(s) have changed. 
;#######################				#######################

;===============================  TimerVars
Variable_01	=	
Variable_02	=	
Variable_03	=	
Variable_04	=	
Variable_05	=	
Variable_06	=	
Variable_07	=	
Variable_08	=	
Variable_09	=	
Variable_10	=	
;#######################				#######################
;=============================================================
; 						CODE 
;=============================================================
;#######################				#######################

 
 
;=============================================================
; 						GUI 
;=============================================================
;=============================================================

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

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






;=============================================================
; 						gLabel 
;=============================================================
;ButtonX
;=============================================================
;EditX
;=============================================================
;
;=============================================================


;=============================================================
; 						TIMER 
;=============================================================
;TimerX
;=============================================================
return

; Timer2
;=============================================================
Timer2:
 
return
 
;=============================================================
; 						HOTKEYS 
;=============================================================




; Hotkey1
;=============================================================






; Hotkey2
;=============================================================




; Exit 
;=============================================================
Exit:
^!x::  ; Hotkey ALT+x.
GuiEscape:
GuiClose:
 ExitApp


 
;#######################				#######################
;=============================================================
; 						FUNCTIONS 
;=============================================================
;#######################				#######################

Code: Select all


;************************************************
; AHK _ SCRIPT PERFORMANCE TEMPLATE v1.0
; by HinkerLoden
; 25/03/2016 
; OS  			--> 	Win 10 / etc. 
;AHK Version	-->		1.1.23.05 
;************************************************

;************************************************
;Script Global Settings
;************************************************

#NoEnv						; Clear All Systemvariables 
#Persistent 				;Keeps a script permanently running until ExitApp execute

#SingleInstance force		;The word FORCE skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.

;************************************************
;Performance PARAMETERS
;************************************************
SetBatchLines, -1				; look up long descriptions
Process, Priority, , A  		;H  - Max Speed but maybe unstable
;************************************************
; Input PARAMETERS
;************************************************
SendMode Input					;Default = Event , Play - for Speed -> Set Keydelay to -1 & Setmousedely to -1 
SetKeyDelay, -1, -1, Play		; for speed -1, -1, 

SetMouseDelay, -1				;0 recommend   /  -1 for max speed 
SetDefaultMouseSpeed, 0			;0-100 
;************************************************
;History Protocols
;************************************************
#KeyHistory 0					;  0 - No Keyhistory 
ListLines Off					; Off  - for more speed 
;************************************************
;Window detection
;************************************************
SetTitleMatchMode 2
SetTitleMatchMode Fast

SetWinDelay, 0 
SetControlDelay, 0	 

;#######################				#######################
; Script Parameter
;#######################				#######################

CoordMode, Pixel, Screen
CoordMode, Mouse, Screen

;#######################				#######################
; Prepare Start 
;#######################				#######################

WinMinimizeAll



;************************************************
;PERFORMANCE PARAMETERS DESCRIPTION
;************************************************
/*
;************************************************
;Performance PARAMETERS
;************************************************

SetBatchLines, -1

;default = 10ms
   
;SetBatchLines is set to 10 ms (the default), a task that uses 20 ms of CPU time will run for ~10 ms, sleep to allow other processes to run, and then run for the final 10 ms. If SetBatchLines is set to 2 ms, a task that uses 20 ms of CPU will sleep ~10 times before completing.
 
My advice... Leave SetBatchLines at the default of 10 ms. 10 ms is a good default. Most scripts run fine with this setting. If needed, increase SetBatchLines to a higher value (20ms, 50ms, -1, etc.) if one or more of your tasks needs more priority.

As Lower the Value as Slower the Script runs !!!
SetBatchLines, 20ms
SetBatchLines, LineCount



Process, Priority, , A  

;L (or Low)
;B (or BelowNormal), N (or Normal), A (or AboveNormal), H (or High), R (or Realtime). 
;Note: Any process not designed to run at Realtime priority might reduce system stability if set to that level.

Process, Priority, , L ;if unstable, comment or remove this line

;************************************************
; Input PARAMETERS
;************************************************

SendMode Input

;Keysettings		***********************

SetKeyDelay, -1, -1  ;  Delay, PressDuration
; default = 10
;Sets the delay that will occur after each keystroke sent by Send and ControlSend. -1 
;Use -1 for no delay at all and 0 for the smallest possible delay 


;Mousesettings		***********************
 
SetMouseDelay, -1 
;Sets the delay that will occur after each mouse movement or click.
;default = 10 - Sets the delay that will occur after each mouse movement or click.
 
SetDefaultMouseSpeed, 0
;default = 2 , Min = 0 , Max = 100

;Hotkeysettings		***********************
#MaxHotkeysPerInterval 99000000	:default = 70  	- prevent creating endless loops

#HotkeyInterval 99000000		;default = 2000 - Hoy much hotkeys can activate per ms

#MaxThreads 255					;default 10 	- How many Hotkeys + Timers .. can run simultanously 

#MaxThreadsBuffer On			;default Off - This is the default behavior. A hotkey press will be ignored whenever that hotkey is already running its maximum number of threads (usually 1, but this can be changed with #MaxThreadsPerHotkey).
 


;************************************************
;History Protocols
;************************************************
#KeyHistory 0					;disable KeyHistory log

ListLines,  Off					
;ListLines Off/On can be used to selectively omit some lines from the history, which can help prevent the history from filling up too quickly (such as in a loop with many fast iterations). ListLines Off may also improve performance by a few percent.
 

;************************************************
;Window detection
;************************************************

 
SetTitleMatchMode fast
;Fast: This is the default behavior. Performance may be substantially better than Slow, but certain WinText elements for some types of windows may not be "seen" by the various window commands.
;The built-in variables A_TitleMatchMode and A_TitleMatchModeSpeed contain the current settings.
 
SetWinDelay, 0 ;default = 100,  no delay = -1 	
;Sets the delay that will occur after each windowing command, such as WinActivate.


SetControlDelay, 0	 ; default = 20     , fastest = -1 
;Sets the delay that will occur after each control-modifying command.


SendMode Input	
; Recommended for new scripts due to its superior speed and reliability.
;Input: Switches to the SendInput method for Send, SendRaw, Click, and MouseMove/Click/Drag. Known limitations:Windows Explorer ignores SendInput's simulation of certain navigational hotkeys such as Alt+LeftArrow. To work around this, use either SendEvent !{Left} or SendInput {Backspace}. 

;************************************************
;Other 
;************************************************

#MaxMem 4095					;default 64MB - Max 4095	 set the Memory use for each Variable 


*/
 

Code: Select all


;************************************************
; AHK _ SCRIPT STRUCTURE TEMPLATE v1.0
; by HinkerLoden
; 09/04/2016 
; OS  			--> 	Win 10 / etc. 
;AHK Version	-->		1.1.23.05 
;************************************************

;************************************************
;Script Global Settings
;************************************************

#NoEnv						; Clear All Systemvariables 
#Persistent 				;Keeps a script permanently running until ExitApp execute

#SingleInstance force		;The word FORCE skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.

;************************************************
;Performance PARAMETERS - if you need speed 
;************************************************
;SetBatchLines, -1   		
;Process, Priority, , L  ;A  - Max Speed
;************************************************
; Input PARAMETERS
;************************************************
SendMode Input	;Default = Event , Play - for Speed -> Set Keydelay to -1 & Setmousedely to -1 
;----
SetKeyDelay, 10, 10   			; for speed -1, -1, 
SetMouseDelay, 25				;0 recommend   /  -1 for max speed 
SetDefaultMouseSpeed, 0			;0-100 
;************************************************
;History Protocols 
;Switch setting for more Speed 
;************************************************
#KeyHistory 1					;  0 - No Keyhistory 
ListLines  On  					; Off  - for more speed 
;************************************************
;Window detection
;************************************************
SetTitleMatchMode, 2
SetTitleMatchMode Fast			;slow detect hidden windows

SetWinDelay, 200  				;0 - for more speed   

DetectHiddenWindows, On			; | Off 

;i double the standard settings to be on the save side 
;#######################				#######################
; Script Parameter
;#######################				#######################

SetWorkingDir %A_ScriptDir%  	;Ensures a consistent starting directory.

;#Include %A_ScriptDir%\YourLibrarys2integrate.ahk

CoordMode, Pixel, Screen		;relative/Window - active Window
CoordMode, Mouse, Screen

;WinMinimizeAll     ;optional 


;#######################				#######################
; Try to avoid pure numbers inside the code - adress all Vars here
;=============================================================
; 						Variable Section
;=============================================================
;#######################				#######################
;global / static
;EnvUpdate ; --> Notifies the OS and all running applications that environment variable(s) have changed. 
;#######################				#######################

;===============================  TimerVars
CycleTimer1=500
CycleTimer2=500

Timer1Status=0
Timer2Status=0



;#######################				#######################
;=============================================================
; 						CODE 
;=============================================================
;#######################				#######################

 
 
;=============================================================
; 						GUI 
;=============================================================

;#######################				#######################
; GUI Template
;=============================================================

Gui, Tutorial: New , -ToolWindow +AlwaysOnTop, test
gui, font, s14, Verdana
Gui Add, Text, vText x40 y24 w350 h40 +0x200, Text
Gui Add, Edit, vEdit gEdit x40 y72 w350 h40, Edit
;----------
Gui Add, Button, vButton1 gButton1 x40 y152 w132 h44,  Button1
Gui Add, Button, vButton2 gButton2 x272 y152 w132 h44, Button2

;----------
Gui Add, Button, gExit x72 y272 w352 h76 cRed , -- E X I T --

Gui Show, w480 h380, Window
Return

/*	Used Vars 
Text =
Edit =
Button1 =
Button2 =
*/

;=============================================================
; 						gLabel 
;=============================================================
; Button1 - Start-Stop-Timer
;=============================================================
Button1:



If Timer1Status=1
	{
	SetTimer, Timer1, Off
	Timer1Status=0
	}
SetTimer, Timer1, %CycleTimer1%
Timer1Status=1
Return




; Button2 - Start-Stop-Timer
;=============================================================
Button2:


If Timer2Status=1
	{
	SetTimer, Timer2, Off
	Timer2Status=0
	}
SetTimer, Timer2, %CycleTimer2%
Timer2Status=1
Return

; gEdit
;=============================================================
Edit:


return
;=============================================================
; 						TIMER 
;=============================================================

; Timer1
;=============================================================
Timer1:


Return


return

; Timer2
;=============================================================
Timer2:
 
return
 
;=============================================================
; 						HOTKEYS 
;=============================================================




; Hotkey1
;=============================================================






; Hotkey2
;=============================================================




; Exit 
;=============================================================
Exit:
^!x::  ; Hotkey ALT+x.
GuiEscape:
GuiClose:
 ExitApp


 
;#######################				#######################
;=============================================================
; 						FUNCTIONS 
;=============================================================
;#######################				#######################

Re: New AutoHotkey Script Template

by joedf » 20 Mar 2016, 11:23

You have a good point there...
Related: https://github.com/Shambles-Dev/AutoHotkey-Defaults

Re: New AutoHotkey Script Template

by Masonjar13 » 20 Mar 2016, 04:22

I couldn't stand having all that stuff on a new script. :? I need a blank canvas to start working.

Code: Select all

#singleInstance force
#persistent
#include <Lib_1>

Lib_1 takes care of my defaults.

Code: Select all

#noEnv
settings:=a_programFiles "\Masonjar13"
if(!fileExist(settings))
    fileCreateDir,% settings
sini:=settings "\settings.ini"
coordMode,pixel,screen
coordMode,mouse,screen
sendMode input

Re: New AutoHotkey Script Template

by lexikos » 14 Mar 2016, 20:02

@TheDewd: Even if you don't have the plugin, stock Notepad++ 6.9 prompts to elevate if needed:
---------------------------
Save failed
---------------------------
The file cannot be saved and it may be protected.
Do you want to launch Notepad++ in Administrator mode?
---------------------------
Yes No
---------------------------
I suppose with the plugin, Notepad++ would not remain running as admin after the file is saved.

Re: New AutoHotkey Script Template

by TheDewd » 14 Mar 2016, 09:18

Notepad++ has a useful plugin that I often use:
Save as admin

This plugin allows you to save any file as administrator.
Just press "Save" in Notepad++ and if you are not allowed to change this file as user, Notepad++ will save it as administrator.
Windows XP, Windows 7 and Windows Vista are supported.
Author: Khnykin Evgeniy

Re: New AutoHotkey Script Template

by lexikos » 13 Mar 2016, 21:29

derz00 wrote::P Does Microsoft like that? :D :lol: Really what are they afraid of, not letting you have ownership? :roll:
Microsoft has nothing to do with it, except for following sensible security policies (in this case). If you are not an administrator, you are not permitted to write files in system folders or Program Files. The AutoHotkey installer created the file just fine - because it had administrative privileges. You just need to run your text editor as admin to edit it (or you can create the file elsewhere and drag-drop; Explorer will ask you to confirm).

Re: New AutoHotkey Script Template

by joedf » 13 Mar 2016, 13:34

Hhaha yeah ;)
No problem

Re: New AutoHotkey Script Template

by derz00 » 12 Mar 2016, 10:44

joedf wrote:Search Google for the Take Ownership script. :)
:P Does Microsoft like that? :D :lol: Really what are they afraid of, not letting you have ownership? :roll:
Worked great for me though, thanks.

Re: New AutoHotkey Script Template

by joedf » 12 Mar 2016, 01:38

Search Google for the Take Ownership script. :)

Re: New AutoHotkey Script Template

by derz00 » 11 Mar 2016, 17:28

Can someone tell poor ignorant me how to edit shellnew/template.ahk? I suppose I'm just missing some simple concept, but I can't do anything to anything in that folder except read...

Re: New AutoHotkey Script Template

by TheDewd » 11 Mar 2016, 15:07

I have made another revision to my Template.ahk file... I think it's an improvement.

Code: Select all

; Script Information ===========================================================
; Name .........: New AutoHotkey Script
; Description ..: New Script Description
; AHK Version ..: 1.1.23.01 (Unicode 32-bit) - January 24, 2016
; OS Version ...: Windows 2000+
; Language .....: English - United States (en-US)
; Author .......: FirstName LastName <email@address.xyz>
; Filename .....: New AutoHotkey Script.ahk
; ==============================================================================

; Revision History =============================================================
; Revision 2 (YYYY-MM-DD)
; * Change description
; * Change description
; ------------------------------------------------------------------------------
; Revision 1 (YYYY-MM-DD)
; * Initial release
; ==============================================================================

; Auto-Execute =================================================================
#SingleInstance, Force ; Allow only one running instance of script
#Persistent ; Keep the script permanently running until terminated
#NoEnv ; Avoid checking empty variables for environment variables
#Warn ; Enable warnings to assist with detecting common errors
;#NoTrayIcon ; Disable the tray icon of the script
SendMode, Input ; The method for sending keystrokes and mouse clicks
SetWorkingDir, %A_ScriptDir% ; Set the working directory of the script
;SetBatchLines, -1 ; The speed at which the lines of the script are executed
;SetWinDelay, -1 ; The delay to occur after modifying a window
;SetControlDelay, -1 ; The delay to occur after modifying a control
OnExit("OnUnload") ; Run a subroutine or function when exiting the script

return ; End automatic execution
; ==============================================================================

; Labels =======================================================================
MenuHandler:
    MsgBox,, MenuHandler, % "Menu Item: " A_ThisMenuItem "`nMenu Name: " A_ThisMenu
return

ControlHandler:
    If (A_GuiControl = "Button1") {
        MsgBox, % "You clicked the button!"
    }
return

GuiEscape:
GuiClose:
ExitSub:
    ExitApp ; Terminate the script unconditionally
return
; ==============================================================================

; Functions ====================================================================
OnLoad() { ; Execute before the Auto-Execute section of the script
    Global ; Assume-global mode
    Static Init := OnLoad() ; Call function

    ; Global Variables ---------------------------------------------------------
    ApplicationName := "New AutoHotkey Script"
    ApplicationVersion := "0.1"
    ResourceTemp := A_Temp . "\" . ApplicationName . "\"

    FileCreateDir, % ResourceTemp ; Create a directory for temporary files

    ;DllCall("Gdi32.dll\AddFontResourceEx", "Str", "filename.ttf", "UInt", 0x10, "UInt", 0)
}

OnUnload(ExitReason, ExitCode) { ; Execute when exiting the script
    Global ; Assume-global mode

    ;DllCall("Gdi32.dll\RemoveFontResourceEx", "Str", "filename.ttf", "UInt", 0x10, "UInt", 0)

    FileRemoveDir, % ResourceTemp, 1 ; Remove the directory for temporary files
}

WM_CTLCOLORBTN(wParam, lParam, Msg, Hwnd) {
    ; Set button border color to match the GUI color
    Global ; Assume-global mode
    Static Init := OnMessage(0x0135, "WM_CTLCOLORBTN") ; Call function
    Local B := SubStr(GuiColor, 5, 2) ; Blue
    Local G := SubStr(GuiColor, 3, 2) ; Green
    Local R := SubStr(GuiColor, 1, 2) ; Red
    return DllCall("Gdi32.dll\CreateSolidBrush", "UInt", "0x" . B . G . R, "UPtr")
}

GuiCreate() { ; Main GUI window
    Global ; Assume-global mode
    Static Init := GuiCreate() ; Call function

    ; Global Variables ---------------------------------------------------------
    GuiWidth := 600 ; Default width of the GUI window
    GuiHeight := 400 ; Default height of the GUI window

    ; Tray Options -------------------------------------------------------------
    Menu, Tray, Icon, Shell32.dll, 3
    Menu, Tray, Tip, % ApplicationName
    Menu, Tray, NoStandard ; Remove all standard menu items from the tray menu
    Menu, Tray, Add, Exit, ExitSub

    ; Graphical User Interface -------------------------------------------------
    Gui, +LastFound -Resize +HWNDhGui1
    Gui, Color, % (GuiColor := "000000")
    Gui, Margin, % (GuiMarginX := 10), % (GuiMarginY := 10)

    Gui, Add, Tab2, % " x" 0 " y" 0 " w" 0 " h" 0 " vTabControl", % "Tab1|Tab2"

    Gui, Tab ; Future controls are excluded from any tab control
    Gui, Add, Button, % " x" 10 " y" 10 " w" 80 " h" 26 " vButton1 gControlHandler", % "Button1"

    ;Gui, Tab, 1 ; Future controls are owned by the indicated tab
    ;Gui, Tab, 2 ; Future controls are owned by the indicated tab

    Gui, Show, % " w" GuiWidth " h" GuiHeight, % (GuiTitle := ApplicationName)
}

GuiSize(GuiHwnd, EventInfo, Width, Height) {
    ;TrayTip,, % "GuiHwnd: " GuiHwnd "`nEventInfo: " EventInfo "`nWidth: " Width "`nHeight: " Height
}
; ==============================================================================

Re: New AutoHotkey Script Template

by tidbit » 19 Jan 2016, 11:18

my link is my repo, while it was a WIP. the official version removed it: https://autohotkey.com/docs/Tutorial.htm
(also note: the official version has sections like 1.1 1.2 1.3... but mine has 1.a 1.b 1.c... if you click 1.1, it still has "a. Downloading and installing AutoHotkey" :D)

Re: New AutoHotkey Script Template

by TheDewd » 19 Jan 2016, 10:56

tidbit wrote:I used it on my original version of the tutorial as an easter-egg (hover over a header) but it was removed :(
I still see it... I don't think it has been removed... Or did you mean that your tutorial is no longer being used?
OwlHeader.png
OwlHeader.png (7.3 KiB) Viewed 21143 times

Re: New AutoHotkey Script Template

by tidbit » 19 Jan 2016, 10:46

quite the nice owl. I have one aswell (yours is more realistic, though):

Code: Select all

,___, 
[O.o] 
/)__) 
―"――"―
I used it on my original version of the tutorial as an easter-egg (hover over a header) but it was removed :(
https://acorns.github.io/AHK_Tutorial/

Re: New AutoHotkey Script Template

by vasili111 » 19 Jan 2016, 03:01

Nice thread.
1. I am always putting in the top TODO list when script is not complete. It always helps to quickly realise what to do next if there was some pause in script development.
2. After always goes Special notes which describe some special notes that I should remember when working with this script.
All this helps me to quickly continue script development and if it have some special cases to always remember them.
Like:

Code: Select all

; TODO:
; 1. ------------------
; 2. ------------------
; 3. ------------------
; 4. ------------------


; Special notes:
; 1. ------------------
; 2. ------------------
; 3. ------------------
; 4. ------------------

Re: New AutoHotkey Script Template

by joedf » 18 Jan 2016, 02:39

Haha! Yes!!! :D

Top