Re: New AutoHotkey Script Template
Posted: 13 Mar 2016, 13:34
Hhaha yeah
No problem
No problem
Let's help each other out
https://www.autohotkey.com/boards/
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).derz00 wrote: Does Microsoft like that? Really what are they afraid of, not letting you have ownership?
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
I suppose with the plugin, Notepad++ would not remain running as admin after the file is saved.---------------------------
Save failed
---------------------------
The file cannot be saved and it may be protected.
Do you want to launch Notepad++ in Administrator mode?
---------------------------
Yes No
---------------------------
Code: Select all
#singleInstance force
#persistent
#include <Lib_1>
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
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
;=============================================================
;####################### #######################
Code: Select all
SendMode, Input ; Recommended for new scripts due to its superior speed and reliability
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
;-----------------------------------------
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
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
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
}
; ==============================================================================
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 ===================================================================
}