/Lib/Functions.ahk

http://7plus.googlecode.com/ · AutoHotKey · 262 lines · 243 code · 3 blank · 16 comment · 3 complexity · 91e93c11d987beb49dd00dad87040bdb MD5 · raw file

  1. /*
  2. Title: Command Functions
  3. A wrapper set of functions for commands which have an output variable.
  4. License: http://www.autohotkey.net/~Titan/license.txt
  5. */
  6. Functions() {
  7. Return, true
  8. }
  9. IfBetween(ByRef var, LowerBound, UpperBound) {
  10. If var between %LowerBound% and %UpperBound%
  11. Return, true
  12. }
  13. IfNotBetween(ByRef var, LowerBound, UpperBound) {
  14. If var not between %LowerBound% and %UpperBound%
  15. Return, true
  16. }
  17. IfIn(ByRef var, MatchList) {
  18. If var in %MatchList%
  19. Return, true
  20. }
  21. IfNotIn(ByRef var, MatchList) {
  22. If var not in %MatchList%
  23. Return, true
  24. }
  25. IfContains(ByRef var, MatchList) {
  26. If var contains %MatchList%
  27. Return, true
  28. }
  29. IfNotContains(ByRef var, MatchList) {
  30. If var not contains %MatchList%
  31. Return, true
  32. }
  33. IfIs(ByRef var, type) {
  34. If var is %type%
  35. Return, true
  36. }
  37. IfIsNot(ByRef var, type) {
  38. If var is not %type%
  39. Return, true
  40. }
  41. ControlGet(Cmd, Value = "", Control = "", WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  42. ControlGet, v, %Cmd%, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  43. Return, v
  44. }
  45. ControlGetFocus(WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  46. ControlGetFocus, v, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  47. Return, v
  48. }
  49. ControlGetText(Control = "", WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  50. ControlGetText, v, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  51. Return, v
  52. }
  53. DriveGet(Cmd, Value = "") {
  54. DriveGet, v, %Cmd%, %Value%
  55. Return, v
  56. }
  57. DriveSpaceFree(Path) {
  58. DriveSpaceFree, v, %Path%
  59. Return, v
  60. }
  61. EnvGet(EnvVarName) {
  62. EnvGet, v, %EnvVarName%
  63. Return, v
  64. }
  65. FileGetAttrib(Filename = "") {
  66. FileGetAttrib, v, %Filename%
  67. Return, v
  68. }
  69. FileGetShortcut(LinkFile, ByRef OutTarget = "", ByRef OutDir = "", ByRef OutArgs = "", ByRef OutDescription = "", ByRef OutIcon = "", ByRef OutIconNum = "", ByRef OutRunState = "") {
  70. FileGetShortcut, %LinkFile%, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState
  71. }
  72. FileGetSize(Filename = "", Units = "") {
  73. FileGetSize, v, %Filename%, %Units%
  74. Return, v
  75. }
  76. FileGetTime(Filename = "", WhichTime = "") {
  77. FileGetTime, v, %Filename%, %WhichTime%
  78. Return, v
  79. }
  80. FileGetVersion(Filename = "") {
  81. FileGetVersion, v, %Filename%
  82. Return, v
  83. }
  84. FileRead(Filename) {
  85. FileRead, v, %Filename%
  86. Return, v
  87. }
  88. FileReadLine(Filename, LineNum) {
  89. FileReadLine, v, %Filename%, %LineNum%
  90. Return, v
  91. }
  92. FileSelectFile(Options = "", RootDir = "", Prompt = "", Filter = "") {
  93. FileSelectFile, v, %Options%, %RootDir%, %Prompt%, %Filter%
  94. Return, v
  95. }
  96. FileSelectFolder(StartingFolder = "", Options = "", Prompt = "") {
  97. FileSelectFolder, v, %StartingFolder%, %Options%, %Prompt%
  98. Return, v
  99. }
  100. FormatTime(YYYYMMDDHH24MISS = "", Format = "") {
  101. FormatTime, v, %YYYYMMDDHH24MISS%, %Format%
  102. Return, v
  103. }
  104. GuiControlGet(Subcommand = "", ControlID = "", Param4 = "") {
  105. GuiControlGet, v, %Subcommand%, %ControlID%, %Param4%
  106. Return, v
  107. }
  108. ImageSearch(ByRef OutputVarX, ByRef OutputVarY, X1, Y1, X2, Y2, ImageFile) {
  109. ImageSearch, OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ImageFile%
  110. }
  111. IniRead(Filename, Section, Key, Default = "") {
  112. IniRead, v, %Filename%, %Section%, %Key%, %Default%
  113. Return, v
  114. }
  115. IniWrite(Value, Filename, Section, Key)
  116. {
  117. IniWrite, %Value%, %Filename%, %Section%, %Key%
  118. }
  119. /*
  120. Input(Options = "", EndKeys = "", MatchList = "") {
  121. Input, v, %Options%, %EndKeys%, %MatchList%
  122. Return, v
  123. }
  124. */
  125. InputBox(Title = "", Prompt = "", HIDE = "", Width = "", Height = "", X = "", Y = "", Font = "", Timeout = "", Default = "") {
  126. InputBox, v, %Title%, %Prompt%, %HIDE%, %Width%, %Height%, %X%, %Y%, , %Timeout%, %Default%
  127. Return, v
  128. }
  129. MouseGetPos(ByRef OutputVarX = "", ByRef OutputVarY = "", ByRef OutputVarWin = "", ByRef OutputVarControl = "", Mode = "") {
  130. MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, %Mode%
  131. }
  132. PixelGetColor(X, Y, RGB = "") {
  133. PixelGetColor, v, %X%, %Y%, %RGB%
  134. Return, v
  135. }
  136. PixelSearch(ByRef OutputVarX, ByRef OutputVarY, X1, Y1, X2, Y2, ColorID, Variation = "", Mode = "") {
  137. PixelSearch, OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ColorID%, %Variation%, %Mode%
  138. }
  139. Random(Min = "", Max = "") {
  140. Random, v, %Min%, %Max%
  141. Return, v
  142. }
  143. RegRead(RootKey, SubKey, ValueName = "") {
  144. RegRead, v, %RootKey%, %SubKey%, %ValueName%
  145. Return, v
  146. }
  147. RunWait(Target, WorkingDir = "", Mode = "") {
  148. RunWait, %Target%, %WorkingDir%, %Mode%, v
  149. Return v
  150. }
  151. SoundGet(ComponentType = "", ControlType = "", DeviceNumber = "") {
  152. SoundGet, v, %ComponentType%, %ControlType%, %DeviceNumber%
  153. Return, v
  154. }
  155. SoundGetWaveVolume(DeviceNumber = "") {
  156. SoundGetWaveVolume, v, %DeviceNumber%
  157. Return, v
  158. }
  159. StatusBarGetText(Part = "", WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  160. StatusBarGetText, v, %Part%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  161. Return, v
  162. }
  163. SplitPath(ByRef InputVar, ByRef OutFileName = "", ByRef OutDir = "", ByRef OutExtension = "", ByRef OutNameNoExt = "", ByRef OutDrive = "") {
  164. SplitPath, InputVar, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  165. }
  166. StringGetPos(ByRef InputVar, SearchText, Mode = "", Offset = "") {
  167. StringGetPos, v, InputVar, %SearchText%, %Mode%, %Offset%
  168. Return, v
  169. }
  170. StringLeft(ByRef InputVar, Count) {
  171. StringLeft, v, InputVar, %Count%
  172. Return, v
  173. }
  174. StringLen(ByRef InputVar) {
  175. StringLen, v, InputVar
  176. Return, v
  177. }
  178. StringLower(ByRef InputVar, T = "") {
  179. StringLower, v, InputVar, %T%
  180. Return, v
  181. }
  182. StringMid(ByRef InputVar, StartChar, Count , L = "") {
  183. StringMid, v, InputVar, %StartChar%, %Count%, %L%
  184. Return, v
  185. }
  186. StringReplace(InputVar, SearchText, ReplaceText = "", All = "") {
  187. StringReplace, v, InputVar, %SearchText%, %ReplaceText%, %All%
  188. Return, v
  189. }
  190. StringRight(ByRef InputVar, Count) {
  191. StringRight, v, InputVar, %Count%
  192. Return, v
  193. }
  194. StringTrimLeft(ByRef InputVar, Count) {
  195. StringTrimLeft, v, InputVar, %Count%
  196. Return, v
  197. }
  198. StringTrimRight(ByRef InputVar, Count) {
  199. StringTrimRight, v, InputVar, %Count%
  200. Return, v
  201. }
  202. StringUpper(ByRef InputVar, T = "") {
  203. StringUpper, v, InputVar, %T%
  204. Return, v
  205. }
  206. SysGet(Subcommand, Param3 = "") {
  207. SysGet, v, %Subcommand%, %Param3%
  208. Return, v
  209. }
  210. Transform(Cmd, Value1, Value2 = "") {
  211. Transform, v, %Cmd%, %Value1%, %Value2%
  212. Return, v
  213. }
  214. WinGet(Cmd = "", WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  215. WinGet, v, %Cmd%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  216. Return, v
  217. }
  218. WinGetActiveTitle() {
  219. WinGetActiveTitle, v
  220. Return, v
  221. }
  222. WinGetClass(WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  223. WinGetClass, v, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  224. Return, v
  225. }
  226. WinGetText(WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  227. WinGetText, v, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  228. Return, v
  229. }
  230. WinGetTitle(WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  231. WinGetTitle, v, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  232. Return, v
  233. }
  234. WinMaximize(WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  235. WinGet, style, style, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  236. if(style & 0x10000)
  237. WinMaximize, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  238. }
  239. WinMinimize(WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
  240. WinGet, style, style, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  241. outputdebug % "style " style " minimize " style & 0x20000
  242. if(style & 0x20000)
  243. WinMinimize, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
  244. }
  245. ;System modal messagebox (Options can't be considered due to msgbox parsing
  246. MsgBox2(Title, Text, Timeout="")
  247. {
  248. if(title = "")
  249. title := "7plus"
  250. Msgbox, 0x1000, %Title%, %Text%, %Timeout%
  251. }
  252. MsgBox(Text)
  253. {
  254. MsgBox, %Text%
  255. }