The script below allows you to execute macro commands with a combination of letters.
Simple macros can be encoded more quickly thanks to the simplified syntax.
(1 letter = 1 keyboard command) see letters below
It is not a macro recorder and not an AHK editor !!
Even if you can grabe a few mouse clicks, you still have to enter keyboard commands manually.
Any suggestions to improve the code are welcome.
Here is the code:
Code: Select all
; =================================================================================================================================
; Name: MACRO COMMANDER
; Description: Execute macro commands with a combination of letters
; Topic: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=61904
; Sript version: 3.0
; AHK Version: 1.1.24.03 (A32/U32/U64)
; Tested on: Win 7 (x64)
; Author: SpeedMaster
; How to play: Add a line that begin with " : " to insert a keyboard command
; Each letter represents a key command
; for example
; :U2D{F2}L4SE = Send, {Up 2}{Down}{F2}{Left 4} (Sleep, 1000) {Enter}
; 2 consecutive left clicks at the same position will be interpreted as a double-click
; ==================================================================================================================================
version:="3.0"
#SingleInstance, force
coordmode, mouse, screen
SetWorkingDir %A_ScriptDir%
help=
(
Win + F12 = Hide Show Gui
Win + F11 = Play the macro
Win + Space = insert a left click.
Win + X = insert a right click.
2 clicks at the same position = double-click
Win + W = insert current window title as comment
Win + C = insert a Wait For Color
Win + Esc = exit the script
Add a line that begin with " : " to insert a keyboard command
or " :$ " to loop for ex. (:$7ud = send up down 7 times )
(see command letters tab below)
)
Gui 1: +Resize +AlwaysOnTop
Gui 1: -dpiscale
Gui 1: font, s10
Gui 1: Add, Text,, % help
gui 1: font
Gui 1: Add, Text,, Delay between clicks in ms
Gui 1: Add, Edit, veditdelay disabled
Gui 1: Add, UpDown, vDelayTimer Range100-100000, 500
Gui 1: +Resize
Gui 1: Add, CheckBox, x+20 yp+2 hp-25 -border gtoggleLoopPlay vLoopPlay, Repeat
Gui 1: Add, Edit, x+1 yp-3 w80 +Number ved_rep Disabled c5D69BA,
Gui 1: Add, UpDown, vrepeat x34 Range1-999999, 2
Gui 1: Add, CheckBox, x+15 yp+2 hp-25 -border gnohide vNohide, Show Gui
Gui 1: Add, progress, xm y+10 w19 h19 vcapture
Gui 1: Add, text, xp-1 yp-1 wp+2 hp+2 backgroundtrans border,x
Gui 1: Add, text, x+4 yp+4, Wait For Color ( #C )
Gui 1: Add, button, x+20 yp-2 hp-25 gresetonce, Reset Run and SleepOnce
Gui 1: Add, text, x+4 yp hp vResetState 0x201, 0
Gui 1: Add, tab3, x10 section vmytab, Macro|Transcriber|Command Letters
gui 1: font, s12
Gui 1: Add, Edit, y+30 w350 h300 -ReadOnly vmyedit -Wrap HScroll WantTab hwndHandle
Gui 1: font
Gui 1: Add, Button, Default vbtplay yp-27, PLAY
Gui 1: Add, Button, x+10, CLEAR
Gui 1: Add, Button, x+25, LOAD
Gui 1: Add, Button, x+10, SAVE
gui 1:tab, Transcriber
Gui 1: Add, Edit, y+30 w350 h300 vmyedit2 -Wrap HScroll WantTab
Gui 1: Add, Button, xm+10 yp-27 gtranscribetoahk, Transcribe to AHK syntax
Gui 1: Add, Button, x+10 yp ginsertmousedelays, Insert Mouse Delays
Gui 1: Add, Button, x+10 yp gcopytoclipboard, Copy to clipboard
gui 1:tab, Command Letters
Gui 1: Add, Edit, w350 h320 ReadOnly vmyedit3 -Wrap HScroll WantTab
gosub, commandlist
guicontrol,, myedit3, % list
Gui 1: show, w400 h645, % "Macro Commander v" . version
toggle:=1, clickscount:=0
guicontrol, enable, editdelay
Gui 1: Submit, nohide
SetTimer, GetColor, 50, ON
; Hide Show Gui
#F12::
loopplay:=0
guicontrol,, loopplay, 0
GuiControl,disable,ed_rep
toggle:=!toggle
if toggle {
Gui 1: Show, w400 h645, % "Macro Commander v" . version
GuiControl, Focus, MyEdit
SendMessage, 0xB1, -2, -1,, ahk_id %Handle%
SendMessage, 0xB7,,,, ahk_id %Handle%
}
else
gui 1: hide
return
GuiSize:
If (A_EventInfo = 1) ; The window has been minimized.
Return
AutoXYWH("wh", "mytab")
AutoXYWH("wh", "myedit", "myedit2" ,"myedit3")
return
nohide:
Nohide:=!Nohide
return
; Play Macro
#F11::
gosub, buttonplay
return
; Insert Left Click
#space::
Gui 1: Submit, NoHide
MouseGetPos, xpos, ypos,
tooltip, % ++clickscount ": " xpos " " ypos
myedit .= "`n" . "mouseclick, left, " xpos " ," ypos
guicontrol,, myedit, % myedit
SendMessage, 0xB1, -2, -1,, ahk_id %Handle%
SendMessage, 0xB7,,,, ahk_id %Handle%
sleep, 300
tooltip,
return
; Insert Right Click
#x::
Gui 1: Submit, NoHide
MouseGetPos, xpos, ypos,
tooltip, % ++clickscount ": " xpos " " ypos
myedit .= "`n" . "mouseclick, right, " xpos " ," ypos
guicontrol,, myedit, % myedit
SendMessage, 0xB1, -2, -1,, ahk_id %Handle%
SendMessage, 0xB7,,,, ahk_id %Handle%
sleep, 300
tooltip,
return
; Insert Window Title as comment
#w::
Gui 1: Submit, NoHide
WinGetTitle, Title, A
myedit .="`n; " . Title
guicontrol,, myedit, % myedit
SendMessage, 0xB1, -2, -1,, ahk_id %Handle%
SendMessage, 0xB7,,,, ahk_id %Handle%
tooltip, % Title
sleep, 300
tooltip,
return
; Insert Wait for color
#c::
Gui 1: Submit, NoHide
gosub, getcolor
myedit .= "`n" . "WaitForColor, " color ", " MouseX ", " MouseY ", true"
guicontrol,, myedit, % myedit
SendMessage, 0xB1, -2, -1,, ahk_id %Handle%
SendMessage, 0xB7,,,, ahk_id %Handle%
sleep, 300
tooltip,
return
GetColor:
coordmode, pixel
MouseGetPos, MouseX, MouseY
PixelGetColor, Color, % MouseX, % MouseY, RGB
GuiControl, % "+background" SubStr(Color, 3) , capture
return
toggleLoopPlay:
if (LoopPlay:=!LoopPlay)
{
guicontrol,, loopplay, 1
GuiControl,enable,ed_rep
}
else
{
guicontrol,, loopplay, 0
GuiControl,enable0,ed_rep
}
return
Resetonce:
runonce:=sleeponce:=ActivateRunonce:=ActivateSleepOnce:=""
guicontrol,, resetstate, 0
return
ButtonPLAY:
Gui 1: Submit
clickscount:=0
GuiControlGet,ed_rep,,repeat
runmacro:
if !ed_rep
ed_rep:=1
if !LoopPlay
ed_rep:=1
Loop % ed_rep
{
loop, parse, myedit, `n
{
if regexmatch(a_loopfield, "mouseclick,.*(l|r)\D+(\d+)\D+(\d+)",match) {
MouseMove, match2, match3
tooltip, % ++clickscount
if !(pmatch2==match2) && !(pmatch3==match3)
Sleep, % DelayTimer
mouseclick, % (match1="r") ? "right" : "left"
}
pmatch2:=match2, pmatch3:=match3
if regexmatch(a_loopfield, "^msgbox,") {
msg_:=regexreplace(a_loopfield, "msgbox,( )?")
MsgBox, % msg_
msg_:=""
}
if regexmatch(a_loopfield, "^run,") {
runprog:=regexreplace(a_loopfield, "run,( )?")
run, % runprog
}
if regexmatch(a_loopfield, "^runonce,") && !runonce {
runprog:=regexreplace(a_loopfield, "runonce,( )?")
run, % runprog
ActivateRunonce:=1
runprog:=""
}
if regexmatch(a_loopfield, "^sleeponce,") && !sleeponce {
sleeponcetime:=regexreplace(a_loopfield, "sleeponce,( )?")
sleep, % (sleeponcetime) ? sleeponcetime : "1000"
ActivateSleeponce:=1
sleeponcetime:=""
}
if instr(a_loopfield, "waitforcolor") {
Color_m:=""
pcolor:=strsplit(a_loopfield, "`,")
CoordMode Pixel
tooltip, waiting for color
if regexmatch(pcolor.5, "( )+?(f|0)")
Loop
{
PixelGetColor, color_m, pcolor.3, pcolor.4, RGB
} Until (Color_m != pcolor.2)
else
Loop
{
PixelGetColor, color_m, pcolor.3, pcolor.4, RGB
} Until (Color_m = pcolor.2)
tooltip
}
if regexmatch(a_loopfield, "^:") {
match_l:=""
if regexmatch(a_loopfield, "^:\$") {
regexmatch(substr(a_loopfield, 2), "i)(^\$)(?! *)?([0-9]*\.[0-9]+|[0-9]+)",match_l)
match_l:=substr(match_l, 2)
}
loop, % (match_l) ? (match_l) : 1
{
sendstring:=0, toggleshift:=0
for k, v in strsplit(a_loopfield) {
if (ctn) {
--ctn
continue
}
if (v="""") && (ztr)
sendstring := !sendstring
if !(sendstring) {
if (v=";") {
break
}
if (v="s") {
match_s:=""
regexmatch(substr(a_loopfield, k), "i)(^s)(?! *)?([0-9]*\.[0-9]+|[0-9]+)",match_s)
if (match_s) {
match_s:=substr(match_s, 2)
tooltip, % "Sleep " match_s " sec"
sleep, % round((1000 * match_s))
}
else {
tooltip, % "Sleep 1 sec"
sleep, 1000
}
tooltip,
}
if (v="f") && !(sendkey) {
match_f:=""
regexmatch(substr(a_loopfield, k), "i)(^f)(?! *)?([0-9]+)",match_f)
if (match_f) {
match_f:=substr(match_f, 2)
SendInput, {F%match_f%}
}
else {
Send, ^f
}
}
else if (v="i") && !(sendkey) {
clip:=clipboard, num:=lnum:=tn:=nd:=t:=d:=""
RegExMatch(clip, ".*(?:\D|^)(\d+)" , tn), RegExMatch(clip, "(\d+)\D*\z" , nd), RegExMatch(tn, "(\d+)\D*\z" , num)
StringLen, lnum, num
if num is integer
++num
SetFormat, Float, 0%lnum%
num += 0.0
StringTrimRight, t, tn, %lnum%
StringTrimLeft , d, nd, %lnum%
clip:= t . num . d
(num) && clipboard:=Clip
sleep, 100
clip:=num:=lnum:=tn:=nd:=t:=d:=""
}
else if (v="{") {
sendkey:=1, match_k:=""
regexmatch(substr(a_loopfield, k), "^{.*?}",match_k)
SendInput, % match_k
}
else if (v="}") && (sendkey)
sendkey:=0
else if (v="(") {
match_command:=""
;msgbox, % substr(a_loopfield, k)
regexmatch(substr(a_loopfield, k), "(?<=\()(?:[^()]+|\([^)]+\))+(?=\))", match_command)
if (match_command) {
;msgbox, % match_command
sendraw, % match_command
ctn:=strlen(match_command)+1
match_command:=""
}
}
else if (v="u") && !(sendkey)
sk("u", "UP")
else if (v="d") && !(sendkey)
sk("d", "Down")
else if (v="l") && !(sendkey)
sk("l", "Left")
else if (v="r") && !(sendkey)
sk("r", "Right")
else if (v="e") && !(sendkey)
sk("e", "Enter")
else if (v="t") && !(sendkey)
sk("t", "Tab")
else if (v="k") && !(sendkey)
sk("k", "Appskey")
else if (v="h") && !(sendkey)
sk("h", "Home")
else if (v="n") && !(sendkey)
sk("n", "End")
else if (v="b") && !(sendkey)
sk("b", "BackSpace")
else if (v="c") && !(sendkey)
Send, ^c
else if (v="v") && !(sendkey)
Send, ^v
else if (v="x") && !(sendkey)
Send, ^x
else if (v="a") && !(sendkey)
Send, ^a
else if (v="q") && !(sendkey)
Send, !{f4}
else if (v="w") && !(sendkey)
Clipwait, 2
else if (v="z") && !(sendkey)
Clipboard:=""
else if (v="p") && !(sendkey)
clipboard = %clipboard%
else if (v="m") && !(sendkey)
msgbox,
else if (v="+") {
toggleshift:=!toggleshift
if (toggleshift)
send, {Shift down}
else
send, {Shift up}
}
else if (v="^") {
toggleControl:=!toggleControl
if (toggleControl)
send, {Ctrl down}
else
send, {Ctrl up}
}
else if (v="!") {
toggleAlt:=!toggleAlt
if (toggleAlt)
send, {Alt down}
else
send, {Alt up}
}
else if (v="#") {
toggleWin:=!toggleWin
if (toggleWin)
send, {LWin down}
else
send, {LWin up}
}
}
if (sendstring) {
if !(v="""")
tosend .= v
}
if !(sendstring) && (tosend!="") {
sendraw, % tosend
tosend:=""
}
} ; end of for loop (to parse a command line)
} ; end of if command ":"
} ; end of loop current command line (:$(n) parameter for ex. :$25 = loop this line 25 times
; Ensure that all toggle keys are released
if (toggleShift) {
send, {Shift up}
toggleShift:=0
}
if (toggleControl) {
send, {Ctrl up}
toggleControl:=0
}
if (toggleAlt) {
send, {Alt up}
toggleAlt:=0
}
if (toggleWin) {
send, {Lwin up}
toggleWin:=0
}
} ;end of parse lines loop
clickscount:=0
(ActivateRunonce) && runonce:=1
(ActivateSleepOnce) && sleeponce:=1
if (runonce=1 || sleeponce=1) {
guicontrol,, resetstate, 1
}
tooltip, % "done : " a_index "/" ed_rep
sleep, 400
tooltip,
if !loopplay
break
} ; end of repeat the macro
if nohide {
gui 1: show
toggle:=1
}
else
{
gui 1: hide
toggle:=0
}
return
guiclose:
toggle:=""
gui 1: hide
return
copytoclipboard:
gui, submit, nohide
clipboard:=myedit2
return
insertmousedelays:
gui, submit, nohide
outwithmousedelay:=""
loop, parse, text_out, "`n", "`r"
if instr(a_loopfield, "mouseclick")
outwithmousedelay .= a_loopfield "`n" "sleep, " DelayTimer "`n"
else
outwithmousedelay .= a_loopfield "`n"
guicontrol,, myedit2, % remove_delay_between_same_clicks(outwithmousedelay)
remove_delay_between_same_clicks(var) {
tesa:=strsplit(var, "`n", "`r")
tesb:=tesa.clone()
for k, v in tesa
if regexmatch(v, "^mouseclick.*",m) {
regexmatch(tesa[k+2], "^mouseclick.*",n)
if (n=m)
tesb[k+1]:="erasemmme"
}
for k, v in tesb
if instr(v, "erasemmme")
tesb.removeat(k)
return st_glue(tesb)
}
return
TranscribetoAHK:
text_out:=""
guicontrolget, text_in,,myedit
loop, parse, text_in, `n
{
if !(regexmatch(a_loopfield, "^:")) {
curtline:=a_loopfield
if instr(curtline, "waitforcolor") {
pcolor:=strsplit(curtline, "`,")
curtline :="`nCoordMode Pixel`nLoop`n{`n PixelGetColor, color, " pcolor.3 ", " pcolor.4 ", RGB`n} Until (Color = " pcolor.2 ")"
}
text_out .= "`n" . curtline
}
if regexmatch(a_loopfield, "^:") {
match_l_debug:=""
if regexmatch(a_loopfield, "^:\$") {
regexmatch(substr(a_loopfield, 2), "i)(^\$)(?! *)?([0-9]*\.[0-9]+|[0-9]+)",match_l_debug)
match_l_debug:=substr(match_l_debug, 2)
}
if (match_l_debug) {
text_out .= "`nLoop, " match_l_debug " {`n"
closeloop:=1
}
sendstringdebug:=0, toggleshiftdeb:=0
for k, v in strsplit(a_loopfield) {
if (ctn_deb) {
--ctn_deb
continue
}
if (v="""") && (ztr_deb)
sendstringdebug := !sendstringdebug
if !(sendstringdebug) {
if (v=";") {
break
}
if (v="s") {
match_s_debug:=""
regexmatch(substr(a_loopfield, k), "i)(^s)(?! *)?([0-9]*\.[0-9]+|[0-9]+)",match_s_debug)
if (match_s_debug) {
match_s_debug:=substr(match_s_debug, 2)
text_out .= "`nsleep, " round((1000 * match_s_debug))
}
else
text_out .= "`nsleep, 1000"
}
if (v="f") && !(sendkey_debug) {
match_f_debug:=""
regexmatch(substr(a_loopfield, k), "i)(^f)(?! *)?([0-9]+)",match_f_debug)
if (match_f_debug) {
match_f_debug:=substr(match_f_debug, 2)
text_out .= "`nSendInput, {F" match_f_debug "}"
}
else {
text_out .= "`nSend, ^f"
}
}
else if (v="i") {
txtapp=
(%
clip:=clipboard, num:=lnum:=tn:=nd:=t:=d:=""
RegExMatch(clip, ".*(?:\D|^)(\d+)" , tn), RegExMatch(clip, "(\d+)\D*\z" , nd), RegExMatch(tn, "(\d+)\D*\z" , num)
StringLen, lnum, num
if num is integer
++num
SetFormat, Float, 0%lnum%
num += 0.0
StringTrimRight, t, tn, %lnum%
StringTrimLeft , d, nd, %lnum%
clip:= t . num . d
(num) && clipboard:=Clip
sleep, 100
clip:=num:=lnum:=tn:=nd:=t:=d:=""
)
text_out .= "`n" txtapp
txtapp:=""
}
else if (v="{") {
sendkey_debug:=1, match_k_debug:=""
regexmatch(substr(a_loopfield, k), "^{.*?}",match_k_debug)
text_out .= "`nSendInput, " . match_k_debug
}
else if (v="}") && (sendkey_debug)
sendkey_debug:=0
else if (v="(") {
match_command_deb:=""
regexmatch(substr(a_loopfield, k), "(?<=\()(?:[^()]+|\([^)]+\))+(?=\))", match_command_deb)
if (match_command_deb) {
text_out .= "`nSendRaw, " match_command_deb
ctn_deb:=strlen(match_command_deb)+1
match_command_deb:=""
}
}
else if (v="u") && !(sendkey_debug)
sk_debug("u","Up")
else if (v="d") && !(sendkey_debug)
sk_debug("d","Down")
else if (v="l") && !(sendkey_debug)
sk_debug("l","Left")
else if (v="r") && !(sendkey_debug)
sk_debug("r","Right")
else if (v="e") && !(sendkey_debug)
sk_debug("e","Enter")
else if (v="t") && !(sendkey_debug)
sk_debug("t","Tab")
else if (v="k") && !(sendkey_debug)
sk_debug("k","Appskey")
else if (v="h") && !(sendkey_debug)
sk_debug("h","Home")
else if (v="n") && !(sendkey_debug)
sk_debug("n","End")
else if (v="b") && !(sendkey_debug)
sk_debug("b","BackSpace")
else if (v="c") && !(sendkey_debug)
text_out .= "`nSend, ^c"
else if (v="v") && !(sendkey_debug)
text_out .= "`nSend, ^v"
else if (v="x") && !(sendkey_debug)
text_out .= "`nSend, ^x"
else if (v="a") && !(sendkey_debug)
text_out .= "`nSend, ^a"
else if (v="q") && !(sendkey_debug)
text_out .= "`nSend, !{f4}"
else if (v="w") && !(sendkey_debug)
text_out .= "`nClipWait"
else if (v="z") && !(sendkey_debug)
text_out .= "`nClipboard="
else if (v="p") && !(sendkey_debug)
text_out .= "`nClipboard = %clipboard%"
else if (v="m") && !(sendkey_debug)
text_out .= "`nMsgbox,"
else if (v="+") && !(sendkey_debug) {
toggleshiftdebug:=!toggleshiftdebug
if (toggleshiftdebug)
text_out .= "`nSend, {Shift down}"
else
text_out .= "`nSend, {Shift up}"
}
else if (v="^") {
toggleControldebug:=!toggleControldebug
if (toggleControldebug)
text_out .= "`nSend, {Ctrl down}"
else
text_out .= "`nSend, {Ctrl up}"
}
else if (v="!") {
toggleAltdebug:=!toggleAltdebug
if (toggleAltdebug)
text_out .= "`nSend, {Alt down}"
else
text_out .= "`nSend, {Alt up}"
}
else if (v="#") {
toggleWindebug:=!toggleWinDebug
if (toggleWinDebug)
text_out .= "`nSend, {LWin down}"
else
text_out .= "`nSend, {LWin up}"
}
}
if (sendstringdebug) {
if !(v="""")
tosenddebug .= v
}
if !(sendstringdebug) && (tosenddebug!="") {
text_out .= "`nSendRaw, " tosenddebug
tosenddebug:=""
}
}
}
; Ensure that all toggle keys are released
if (toggleshiftdebug) {
text_out .= "`nsend, {Shift up} `; Don't forget to put a second + to release the key "
toggleshiftdebug:=0
}
if (toggleControldebug) {
text_out .= "`nsend, {Ctrl up} `; Don't forget to put a second ^ to release the key "
toggleControldebug:=0
}
if (toggleAltdebug) {
text_out .= "`nsend, {Alt up} `; Don't forget to put a second ! to release the key "
toggleAltdebug:=0
}
if (toggleWindebug) {
text_out .= "`nsend, {Lwin up} `; Don't forget to put a second # to release the key "
toggleWindebug:=0
}
(closeloop) && text_out .= "`n}`n"
closeloop:=""
}
text_out:=removeemptylines(text_out)
guicontrol,, myedit2, % text_out
return
;--------------------------------------------------------------------------------------------------------
sk(key,KeyName) {
global
match_num:=""
regexmatch(substr(a_loopfield, k), "i)(^" key ")(?! *)?([0-9]+)",match_num)
if (match_num) {
match_num:=substr(match_num, 2)
SendInput, {%KeyName% %match_num%}
}
else {
SendInput, {%KeyName%}
}
}
sk_debug(key,KeyName) {
global
match_num_deb:=""
regexmatch(substr(a_loopfield, k), "i)(^" key ")(?! *)?([0-9]+)",match_num_deb)
if (match_num_deb) {
match_num_deb:=substr(match_num_deb, 2)
text_out .= "`nSendInput, {" KeyName " " match_num_deb "}"
}
else {
text_out .= "`nSendInput, {" KeyName "}"
}
}
;---------------------------------------------------------------------------------------------------------
ButtonCLEAR:
clickscount:=0
myedit:=""
guicontrol,, myedit, % ""
return
ButtonLOAD:
Gui +OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, Open File, Text Documents (*.txt)
if SelectedFileName = ; No file selected.
return
Gosub FileRead
return
FileRead: ; Caller has set the variable SelectedFileName for us.
FileRead, MyEdit, %SelectedFileName% ; Read the file's contents into the variable.
if ErrorLevel
{
MsgBox Could not open "%SelectedFileName%".
return
}
GuiControl,, MyEdit, %MyEdit% ; Put the text into the control.
return
ButtonSAVE:
Gui +OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, S16, %A_WorkingDir% , Save File, Text Documents (*.txt)
if SelectedFileName = ; No file selected.
return
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return
SaveCurrentFile: ; Caller has ensured that CurrentFileName is not blank.
IfExist %CurrentFileName%
{
FileDelete %CurrentFileName%
if ErrorLevel
{
MsgBox The attempt to overwrite "%CurrentFileName%" failed.
return
}
}
GuiControlGet, myedit ; Retrieve the contents of the Edit control.
if ! instr(currentfilename, ".",,2)
FileAppend, %myedit%, %CurrentFileName%.txt ; Save the contents to the file.
else
FileAppend, %myedit%, %CurrentFileName% ; Save the contents to the file.
return
commandlist:
list=
(
Add a line that begin with " : " to insert a command in the Macro
Each letter represents a key command.
The standard AHK notation for keys is also supported.
for ex. :{PgDn} u2 {Enter} = SendInput, {PgDn}{Up 2}{Enter}
$ (at the beginning of a command) = loop current command line `n for ex. :$12 = loop 12 times :$5 = loop 5 times etc...
U D L R = {Up} {Down} {Left} {Right}
S = Sleep, 1000
Sn = Sleep, n seconds (n=number or floating number)
S3.2 = Sleep, 3200 S4 = Sleep, 4000 etc...
Bn = {BackSpace} (n = number of times the key is pressed)
for ex. B3 = SendInput, {Backspace 3) ; n is also compatible with commands E D H N T U D L R
E = {Enter}
H = {Home}
N = {End}
T = {Tab}
K = {Appskey}
A = ^a ; select all
X = ^x ; cut
C = ^c ; copy
V = ^v ; paste
F = ^f ; find
Q = {Alt}{F4} ; Close
W = ClipWait
I = Increment the last number found in clipboard
for ex. "dir05\file001.txt" to "dir05\file002.txt"
Z = Clipbaord clear
P = Plain text (convert clipboard to plain text)
M = Msgbox,
F1 to F24 = {F1} - {F24} ; function keys
() = place text between parenteses to sendraw text
for example
:(Hello) + H + = Send, Hello {Shift Down}{Home}{Shift Up}
+ = {Shift Down/Up} Toogle shift key
Don't forget to put a second + to release the key !!!
for example
:+ N + = Send, {Shift Down}{End}{Shift up}
:++ = Send, {Shift Down}{Shift up} (normal shift event)
^ = {Ctrl Down/Up} Toogle Ctrl key
Don't forget to put a second ^ to release the key !!!
for example
:^ "o" ^ = Send, {Ctrl Down} o {Ctrl up}
! = {Alt Down/Up} Toogle Alt key
Don't forget to put a second ! to release the key !!!
for example
:! "fs" ! = Send, {Alt Down} fs {Alt up}
# = {Win Down/Up} Toogle Win key
Don't forget to put a second # to release the key !!!
for example to open explorer
: # "e" # = Send, {Win Down} e {Win up}
other supported commands:
Run, ; to run a program
RunOnce, ; to run a program only once
SleepOnce, (millisec) ; to sleep only once (value in milliseconds)
WaitForColor, color, posx, posy, true/false ; wait for a pixel color to become visible or invisible (false)
MouseClick, left/right, posx , posy
MsgBox, text ; display simple message box (options not supported)
)
return
removeemptylines(var){
loop, parse, var, `n, `r
if !(a_loopfield=="") {
out .= a_loopfield "`n"
}
return out:=substr(out, 1, -1)
}
st_glue(array, delim="`n")
{
for k,v in array
new.=v delim
return trim(new, delim)
}
getcontrol(crtname, what)
{
guicontrolget, out, Pos, %crtname%
if (what="x")
return % outx
if (what="y")
return % outy
if (what="w")
return % outW
if (what="h")
return % outH
if (what="yh")
return % outy + outH
if (what="xw")
return % outx + outW
}
~#esc::
send, {shift up}
tooltip,
exitapp
return
; =================================================================================
; Function: AutoXYWH
; Move and resize control automatically when GUI resizes.
; Parameters:
; DimSize - Can be one or more of x/y/w/h optional followed by a fraction
; add a '*' to DimSize to 'MoveDraw' the controls rather then just 'Move', this is recommended for Groupboxes
; cList - variadic list of ControlIDs
; ControlID can be a control HWND, associated variable name, ClassNN or displayed text.
; The later (displayed text) is possible but not recommend since not very reliable
; Examples:
; AutoXYWH("xy", "Btn1", "Btn2")
; AutoXYWH("w0.5 h 0.75", hEdit, "displayed text", "vLabel", "Button1")
; AutoXYWH("*w0.5 h 0.75", hGroupbox1, "GrbChoices")
; ---------------------------------------------------------------------------------
; Version: 2015-5-29 / Added 'reset' option (by tmplinshi)
; 2014-7-03 / toralf
; 2014-1-2 / tmplinshi
; requires AHK version : 1.1.13.01+
; =================================================================================
AutoXYWH(DimSize, cList*){ ; http://ahkscript.org/boards/viewtopic.php?t=1079
static cInfo := {}
If (DimSize = "reset")
Return cInfo := {}
For i, ctrl in cList {
ctrlID := A_Gui ":" ctrl
If ( cInfo[ctrlID].x = "" ){
GuiControlGet, i, %A_Gui%:Pos, %ctrl%
MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move"
fx := fy := fw := fh := 0
For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]")))
If !RegExMatch(DimSize, "i)" dim "\s*\K[\d.-]+", f%dim%)
f%dim% := 1
cInfo[ctrlID] := { x:ix, fx:fx, y:iy, fy:fy, w:iw, fw:fw, h:ih, fh:fh, gw:A_GuiWidth, gh:A_GuiHeight, a:a , m:MMD}
}Else If ( cInfo[ctrlID].a.1) {
dgx := dgw := A_GuiWidth - cInfo[ctrlID].gw , dgy := dgh := A_GuiHeight - cInfo[ctrlID].gh
For i, dim in cInfo[ctrlID]["a"]
Options .= dim (dg%dim% * cInfo[ctrlID]["f" dim] + cInfo[ctrlID][dim]) A_Space
GuiControl, % A_Gui ":" cInfo[ctrlID].m , % ctrl, % Options
} } }
Win + F12 = Hide Show Gui
Win + F11 = Play the macro
Win + Space = insert a left click.
Win + x = insert a right click.
Win + C = insert " wait for color "
Win + W = insert current window title as comment
Win + Esc = exit the script
Other supported commands:
Run, = to run a program
RunOnce, = to run a program only once
SleepOnce, (millisec) = to sleep only once (value in milliseconds)
WaitForColor, color, posx, posy, true/false = wait for a pixel color to become visible or invisible (false)
MouseClick, left/right, posx , posy = simple mouseclick (others options not supported)
MsgBox, text = simple message box (others options not supported)
Letters Dictionary:
Add a line that begin with " : " to insert a command in the Macro
or " :$ " to loop for ex. (:$7ud = send {up}{down} 7 times )
Each letter represents a key command.
Standard AHK notation for keys is also supported.
for ex. :{PgDn} u2 {Enter} = SendInput, {PgDn}{Up 2}{Enter}
S = Sleep, 1000
Sn = Where n represents number of seconds to sleep (floating number are supported)
for example S3.2 = Sleep, 3200 S4 = Sleep, 4000 etc...
B = {BackSpace}
Bn = n represents the number of times the key is pressed
for example B3 = SendInput, {Backspace 3) (also compatible with commands E D H N T U D L R)
U D L R = {Up} {Down} {Left} {Right}
E = {Enter}
H = {Home}
N = {End}
T = {Tab}
K = {Appskey}
A = ^a ; select all
X = ^x ; cut
C = ^c ; copy
V = ^v ; paste
F = ^f ; find
Q = !{F4} ; Close/Quit
W = ClipWait
I = Increment the last number found in clipboard (for ex. "dir05\file001.txt" to "dir05\file002.txt")
Z = Clipboard clear
P = Plain text (convert clipboard to plain text)
M = Msgbox,
F1 to F24 = {F1} - {F24} ; function keys
$n (dollar sign at the beginning of a command) = loop current command line (:$12 = loop 12 times etc...)
() = Place text between parentesis to send a text (sendraw)
toggle keys commands (first will be interpreted as down and second as up)
+ = {Shift Down/Up} Toogle shift key
^ = {Ctrl Down/Up} Toogle Ctrl key
! = {Alt Down/Up} Toogle Alt key
# = {Win Down/Up} Toogle Win key
examples:
:! (fs) ! f2= Send, {Alt Down} fs {Alt up}{F2}
:U2 R3 LS E = Send, {Up 2}{Right 3}{Left}{Sleep, 1000}{Enter}
:S2.5 (Hello World) = {sleep, 2500} Sendraw, Hello World
: ACNEV = Send, ^a ^c {End}{Enter} ^v
Practical examples:
duplicate the current line in a text editor
Code: Select all
:h +n+ c s0.2 n e v
Code: Select all
:#(r)# s0.5 (charmap)
Code: Select all
run, notepad
:s("hello world")
Code: Select all
:aciv
Code: Select all
runonce, notepad
sleeponce, 1000
:$4(hello)t
:$2(world)t