My little testscript for functions
Code:
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <myemail@nowhere.com>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;
;_FileAppend()
;_MsgBox()
;_FileCopy()
;_loop()
;_variables()
;_funcs()
;_gui()
;_FileSelectFile()
;_FileSetGetAttrib()
;_FileGetSetTime()
;_SetFormat()
;_FileCreateDir()
;_FormatTime()
;_DriveSpaceFree()
;_RegReadWrite()
;_FileCreateShortcut()
;_Strings()
_WindowFunctions()
exitapp
_WindowFunctions()
{
}
_Strings()
{
szText = This is a very stupid text
StringGetPos, OutputVar, szText, very
MsgBox, Position of very = %OutputVar%
res:= InStr(szText, stup)
MsgBox, Instr:= %res%
StringLeft, OutputVar, szText, 7
MsgBox, StringLeft OutputVar szText 7=%OutputVar%
StringLen, OutputVar, szText
MsgBox, StringLen:=%OutputVar%
StringLower, OutputVar, szText , T
StringLower, OutputVar1, szText
StringUpper, OutputVar2, szText , T
StringUpper, OutputVar3, szText
MsgBox, StringLower:%OutputVar% - %OutputVar1% StringUpper: %OutputVar2% - %OutputVar3%
StringMid, OutputVar, szText, 9, 7
MsgBox, StringMid:=%OutputVar%
StringReplace, OutputVar, szText, stupid , genius
MsgBox, StringReplace: %OutputVar%
StringRight, OutputVar, szText, 11
MsgBox, StringRight: %OutputVar%
TestString = This is a test.
Colors = red,green,blue
StringSplit, ColorArray, Colors, `,
Loop, %ColorArray0%
{
this_color := ColorArray%a_index%
MsgBox, Color number %a_index% is %this_color%.
}
StringTrimLeft, OutputVar, szText, 5
StringTrimRight, OutputVar1, szText, 5
MsgBox, StringTrimLeftRight: %OutputVar% - %OutputVar1%
}
_FileCreateShortcut()
{
FileCreateShortcut, \temp\ahk2008.exe, \windows\desktop\ahk.lnk
}
_RegReadWrite()
{
RegRead, OutputVar, HKCU, ControlPanel\Backlight, BatteryTimeout
MsgBox, %OutputVar%
RegWrite, REG_SZ, HKCU, Software\AutohotkeyCE, Demovalue, ValueText
RegRead, OutputVar, HKCU, Software\AutohotkeyCE, Demovalue
MsgBox, %OutputVar%
}
_DriveSpaceFree()
{
DriveSpaceFree, OutputVar, \
MsgBox, %OutputVar% free
}
_FormatTime()
{
FormatTime, TimeString
MsgBox The current time and date (time first) is %TimeString%.
FormatTime, TimeString, R
MsgBox The current time and date (date first) is %TimeString%.
FormatTime, TimeString,, Time
MsgBox The current time is %TimeString%.
FormatTime, TimeString, T12, Time
MsgBox The current 24-hour time is %TimeString%.
FormatTime, TimeString,, LongDate
MsgBox The current date (long format) is %TimeString%.
FormatTime, TimeString, 20050423220133, dddd MMMM d, yyyy hh:mm:ss tt
MsgBox The specified date and time, when formatted, is %TimeString%.
FormatTime, TimeString, 200504, 'Month Name': MMMM`n'Day Name': dddd
MsgBox %TimeString%
FormatTime, YearWeek, 20050101, YWeek
MsgBox January 1st of 2005 is in the following ISO year and week number: %YearWeek%
}
_FileCreateDir()
{
FileCreateDir, \temp\a
FileCreateDir, \temp\b
FileCreateDir, \temp\c
MsgBox, Folders are there
FileRemoveDir, \temp\a
FileRemoveDir, \temp\b
FileRemoveDir, \temp\c
}
_SetFormat()
{
VariableContainingAnInteger = 54
SetFormat, integer, hex
VariableContainingAnInteger += 0
SetFormat, integer, d
MsgBox, %VariableContainingAnInteger%
Var = 11.333333
SetFormat, float, 6.2
Var -= 1 ; Sets Var to be 10.33 with one leading space because the total width is 6.
MsgBox, %Var%
SetFormat, float, 0.2
Var += 1 ; Sets Var to be 11.33 with no leading spaces.
MsgBox, %Var%
SetFormat, float, 06.0
Var += 0 ; Sets Var to be 000011
MsgBox, %Var%
SetFormat, integer, hex
Var += 0 ; Sets Var to be 0xb
SetFormat, integer, d
MsgBox, %Var%
}
_FileGetSetTime()
{
FileGetTime, OutputVarM, \temp\AutoHotkey.ahk
FileGetTime, OutputVarC, \temp\AutoHotkey.ahk
FileGetTime, OutputVarA, \temp\AutoHotkey.ahk
FileSetTime, 2007122109244523, \temp\AutoHotkey.ahk, M
FileSetTime, 2007122109244523, \temp\AutoHotkey.ahk, C
FileSetTime, 2007122109244523, \temp\AutoHotkey.ahk, A
FileGetTime, OutputVarNM, \temp\AutoHotkey.ahk
FileGetTime, OutputVarNC, \temp\AutoHotkey.ahk
FileGetTime, OutputVarNA, \temp\AutoHotkey.ahk
MsgBox, %OutputVarM% - %OutputVarC% - %OutputVarA% - %OutputVarNM% - %OutputVarNC% - %OutputVarNA%
}
_FileSetGetAttrib()
{
FileGetAttrib, OutputVarbefore, \temp\AutoHotkey.ahk
FileSetAttrib, +RASH, \temp\AutoHotkey.ahk
FileGetAttrib, OutputVarAfter, \temp\AutoHotkey.ahk
MsgBox, %OutputVarbefore% - %OutputVarAfter%
}
_FileSelectFile()
{
FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt; *.doc)
if SelectedFile =
MsgBox, The user didn't select anything.
else
MsgBox, The user selected the following:`n%SelectedFile%
}
_gui()
{
gui, add, edit, w600 ; Add a fairly wide edit control at the top of the window.
gui, add, text, section, First Name: ; Save this control's position and start a new section.
gui, add, text,, Last Name:
gui, add, edit, ys ; Start a new column within this section.
gui, add, edit
gui, show, , AHKGuiTitel
/* IfWinExist, AHKGuiTitel
MsgBox, AHKGuiTitel existiert
else
MsgBox, AHKGuiTitel existiert nicht
loop, 3
{
ControlFocus, Edit1, AHKGuiTitel
Sleep, 500
ControlFocus, Edit2, AHKGuiTitel
Sleep, 500
}
*/
ControlFocus, Edit1, AHKGuiTitel
ControlSetText, Edit1, Das ist der neue Text, AHKGuiTitel
Sleep, 4000
ControlSend, Edit2, KeysToSend, AHKGuiTitel
MsgBox, fertig
}
_funcs()
{
v1 := abs(-23)
v2 := FileExist("\temp\autohotkey.ahk")
v3 := FileExist("\temp\autohotkey.xxx")
v4 := InStr("abcdefghijk", "fg")
MsgBox, abs:=%v1% - Exist:%v2% - existx:%v3% - instr:%v4%
v1 := SubStr("WholelonglongString", 2, 3)
v2 := StrLen("longlongstring")
v3 := asc("A")
V4 := chr(65)
MsgBox, substr:=%v1% - strlen:%v2% - asc:=%v3% - chr:=%v4%
v1:= exp(4)
v2:= Ceil(4.5)
v3:= floor(4.5)
v4:= log(4)
MsgBox, exp:=%v1% - ceil:%v2% - floor:=%v3% - log:=%v4%
v1:= ln(4)
v2:= mod(10,3)
v3:= round(4.5)
v4:= sqrt(4)
v5:= sin(34)
MsgBox, ln:=%v1% - mod:%v2% - round:=%v3% - sqrt:=%v4% - sin:=%v5%
}
_variables()
{
outVar := GetVarVal("a_ahkPath") . " " . GetVarVal("a_ahkversion")
MsgBox, %outVar%
outVar := GetVarVal("a_workingdir") . " " . GetVarVal("a_scriptdir")
MsgBox, %outVar%
outVar := GetVarVal("a_scriptname") . " " . GetVarVal("a_scriptfullpath")
MsgBox, %outVar%
outVar := GetVarVal("a_linenumber") . " " . GetVarVal("a_linefile")
MsgBox, %outVar%
outVar := GetVarVal("a_thisfunc") . " " . GetVarVal("a_thislabel")
MsgBox, %outVar%
outVar := GetVarVal("a_ahkversion") . " " . GetVarVal("a_ahkpath")
MsgBox, %outVar%
outVar := GetVarVal("a_YYYY") . " " . GetVarVal("A_MM") . " " . GetVarVal("A_DD") . " " . GetVarVal("a_MMMM")
MsgBox, %outVar%
outVar := GetVarVal("a_MMM") . " " . GetVarVal("a_DDDD") . " " . GetVarVal("a_DDD") . " " . GetVarVal("a_Wday")
MsgBox, %outVar%
outVar := GetVarVal("a_yday") . " " . GetVarVal("a_yweek")
MsgBox, %outVar%
outVar := GetVarVal("a_hour") . " " . GetVarVal("a_min")
MsgBox, %outVar%
outVar := GetVarVal("a_sec") . " " . GetVarVal("a_msec")
MsgBox, %outVar%
outVar := GetVarVal("a_now") . " " . GetVarVal("a_nowutc")
MsgBox, %outVar%
outVar := GetVarVal("a_tickcount") . " " . GetVarVal("A_IsSuspended")
MsgBox, %outVar%
outVar := GetVarVal("A_BatchLines") . " " . GetVarVal("A_TitleMatchMode")
MsgBox, %outVar%
outVar := GetVarVal("A_TitleMatchModeSpeed") . " " . GetVarVal("A_DetectHiddenWindows")
MsgBox, %outVar%
outVar := GetVarVal("A_DetectHiddenText") . " " . GetVarVal("A_AutoTrim")
MsgBox, %outVar%
outVar := GetVarVal("A_StringCaseSense") . " " . GetVarVal("A_FormatInteger")
MsgBox, %outVar%
outVar := GetVarVal("A_FormatFloat") . " " . GetVarVal("A_KeyDelay")
MsgBox, %outVar%
outVar := GetVarVal("A_WinDelay") . " " . GetVarVal("A_ControlDelay")
MsgBox, %outVar%
outVar := GetVarVal("A_MouseDelay") . " " . GetVarVal("A_DefaultMouseSpeed")
MsgBox, %outVar%
outVar := GetVarVal("A_Temp") . " " . GetVarVal("A_OSType")
MsgBox, %outVar%
outVar := GetVarVal("A_OSVersion") . " " . GetVarVal("A_Language")
MsgBox, %outVar%
outVar := GetVarVal("A_ComputerName") . " " . GetVarVal("A_WinDir")
MsgBox, %outVar%
outVar := GetVarVal("A_UserName")
MsgBox, %outVar%
outVar := GetVarVal("A_TimeIdle") . " " . GetVarVal("A_TimeIdlePhysical")
MsgBox, %outVar%
outVar := GetVarVal("A_ProgramFiles") . " " . GetVarVal("A_Desktop")
MsgBox, %outVar%
outVar := GetVarVal("A_StartMenu") . " " . GetVarVal("A_Programs")
MsgBox, %outVar%
outVar := GetVarVal("A_Startup") . " " . GetVarVal("A_MyDocuments")
MsgBox, %outVar%
outVar := GetVarVal("A_ScreenWidth") . " " . GetVarVal("A_ScreenHeight")
MsgBox, %outVar%
}
GetVarVal(VarName)
{
Val1 := %VarName%
szRC = %VarName%:=%Val1% -
return szRC
}
_loop()
{
a:=5
loop, 30
{
a := a + a_index
}
MsgBox, a:= %a%
}
_FileCopy()
{
FileCopy, \temp\FileAppend.txt, \temp\FileCopytest.txt, 1
}
_MsgBox()
{
MsgBox, 4,, Would you like to continue? (press Yes or No)
IfMsgBox Yes
MsgBox You pressed Yes.
else
MsgBox You pressed No.
}
_FileAppend()
{
FileAppend, LangerLangerText!§$`%&/()=?*öäüÖÄÜß?, \temp\fileappend.txt
}