Advertisement
tduva

AutoHotkey Counter Script

Jul 28th, 2015
3,230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Simple AHK script to change a number in a textfile to count stuff.
  4.  
  5. You need to have AutoHotey installed: ahkscript.org
  6.  
  7. - Edit this script accordingly:
  8.   - Change the hotkeys to increase/decrease the number
  9.   - Just remove the second hotkey if you don't need one to decrease
  10.     the number (comment out or remove the whole section)
  11.   - Change the file name/path if necessary
  12.   - You can have some text added behind the number if you want
  13. - Run the script with AutoHotkey and use the hotkey, it should create
  14.   the file, which you can then add in your streaming program as source
  15.   for a text layer
  16. */
  17.  
  18. ; The file to read from/write the number to
  19. filepath := "test.txt"
  20.  
  21. ; Add some text behind the number
  22. appendText := ""
  23.  
  24. /*
  25. Add window name if it should be restricted
  26. (http://ahkscript.org/docs/commands/_IfWinActive.htm)
  27. */
  28. #IfWinActive
  29.  
  30. /*
  31. This are the actual hotkeys
  32. (how to define: http://ahkscript.org/docs/Hotkeys.htm)
  33. */
  34. ; Hotkey to increase number
  35. !q::
  36.     ChangeNumber(1)
  37. Return
  38.  
  39. ; Hotkey to decrease number
  40. !w::
  41.     ChangeNumber(-1)
  42. Return
  43.  
  44. #IfWinActive
  45.  
  46.  
  47. ; Function to change the number in the file
  48. ChangeNumber(Add)
  49. {
  50.     global filepath
  51.     global appendText
  52.     file := FileOpen(filepath, "rw", "UTF-8")
  53.     Num := RegExReplace(file.Read(), "[^0-9]*")
  54.     if (StrLen(Num) = 0) {
  55.         Num := 0
  56.     }
  57.     Num := Num + Add
  58.     if (Num < 0) {
  59.         Num := 0
  60.     }
  61.     Output := Num . appendText
  62.     ;MsgBox, Writing: %Output%
  63.     file.Length := 0
  64.     file.Seek(0, 0)
  65.     file.Write(Output)
  66.     file.Close()
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement