Advertisement
fludp

Untitled

Mar 4th, 2023
1,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. // by Philippe Lhoste <PhiLho(a)GMX.net> http://Phi.Lho.free.fr  
  3. // File/Project history:
  4.  1.00.000 -- Today (PL) -- Lastest version (updated regularly!).
  5.  0.01.000 -- 2013/02/12 (PL) -- Creation.
  6. */
  7. /* Copyright notice: For details, see the following file:
  8. http://Phi.Lho.free.fr/softwares/PhiLhoSoft/PhiLhoSoftLicence.txt
  9. This program is distributed under the zlib/libpng license.
  10. Copyright (c) 2013 Philippe Lhoste / PhiLhoSoft
  11. */
  12. /*
  13. Automated writer writes texts with the mouse, on a target window.
  14. Designed for BigCanvas:
  15. http://bigcanvas.frozenfractal.com/
  16. Tested with Paint, can work on all similar programs.
  17. */
  18. #SingleInstance Force
  19. #NoEnv
  20. SendMode Input
  21. StringCaseSense On
  22. SetTitleMatchMode RegEx
  23.  
  24. global fukWord := ""
  25.  
  26. ;Speed controls how fast the script runs. 1 is the fastest, 100 is the slowest. Default is 2.
  27. speed = 1
  28. ; Scale controls how big the drawing will be
  29. scale = 2
  30. ; Offsets
  31. offsetX = 0
  32. offsetY = 0
  33.  
  34. command = X
  35. prevX = 0
  36. prevY = 0
  37.  
  38. ; Better keep digits at fixed width
  39. _0 = v -16:h 8:v 16:h -8:m 4,-7:v -2:m 8,9
  40. _1 = h 8:m -4,0:v -16:l -4,4:m 12,12
  41. _2 = m 8,0:h -8:l 8,-10:v -6:h -8:v 4:m 12,12
  42. _3 = h 8:v -8:h -4:m 4,0:v -8:h -8:m 12,16
  43. _4 = m 6,0:v -16:l -6,12:h 8:m 4,4
  44. _5 = m 8,-16:h -8:v 8:h 6:l 2,2:v 4:l -2,2:h -6:m 12,0
  45. _6 =  m 8,-16:l -8,8:v 8:h 8:v -8:h -8:m 12,8
  46. _7 = l 8,-16:h -8:m 12,16
  47. _8 = h 8:v -6:l -8,-4:v -6:h 8:v 6:l -8,4:v 6:m 12,0
  48. _9 = l 8,-8:v -8:h -8:v 8:h 8:m 4,8
  49.  
  50. _a = m 0,-8:h 8:v 8:h -8:v -4:h 8:m 4,4
  51. _b = m 0,-16:v 16:h 8:v -8:h -8:m 12,8
  52. _c = v -8:h 8:m -8,8:h 8:m 4,0
  53. _d = m 8,-16:v 16:h -8:v -8:h 8:m 4,8
  54. _e = m 8,0:h -8:v -8:h 8:v 4:h -8:m 12,4
  55. _f = m 2,0:v -16:h 4:m -8,8:h 8:m 4,8
  56. _g = m 0,12:h 8:v -20:h -8:v 8:h 8:m 4,0
  57. _h = v -16:m 0,8:h 8:v 8:m 4,0
  58. _i = v -8:m 0,-2:v -2:m 4,12
  59. _j = m -4,12:h 4:v -20:m 0,-2:v -2:m 4,12
  60. _k = v -16:m 8,16:l -8,-4:l 8,-4:m 4,8
  61. _l = v -16:m 4,16
  62. _m = v -8:h 4:v 4:m 0,-4:h 4:v 8:m 4,0
  63. _n = v -8:h 8:v 8:m 4,0
  64. _o = v -8:h 8:v 8:h -8:m 12,0
  65. _p = m 0,12:v -20:h 8:v 8:h -8:m 12,0
  66. _q = m 8,12:v -20:h -8:v 8:h 8:m 4,0
  67. _r = v -8:h 8:m 4,8
  68. _s = h 8:v -4:h -8:v -4:h 8:m 4,8
  69. _t = m 2,-16:v 16:h 4:m -8,-8:h 8:m 4,8
  70. _u = m 0,-8:v 8:h 8:v -8:m 4,8
  71. _v = m 0,-8:l 4,8:l 4,-8:m 4,8
  72. _w = m 0,-8:v 8:h 4:v -4:m 0,4:h 4:v -8:m 4,8
  73. _x = l 8,-8:m -8,0:l 8,8:m 4,0
  74. _y = m 0,-8:l 4,4:m 4,-4:l -8,12:m 12,-4
  75. _z = m 0,-8:h 8:l -8,8:h 8:m 4,0
  76.  
  77. ; Need to suffix variable names with $ because AHK variable names are case-insensitive!
  78. _A$ = v -16:h 8:v 16:m -8,-8:h 8:m 4,8
  79. ;~ _B$ = v -16:h 6:l 2,2:v 4:l -2,2:h -6:m 6,0:l 2,2:v 4:l -2,2:h -6:m 12,0
  80. _B$ = v -16:h 6:v 8:h -6:m 6,0:h 2:v 8:h -8:m 12,0
  81. _C$ = m 8,0:h -8:v -16:h 8:m 4,16
  82. ;~ _D$ = v -16:h 6:l 2,2:v 12:l -2,2:h -6:m 12,0
  83. _D$ = v -16:h 4:l 4,8:v 8:h -8:m 12,0
  84. _E$ = v -16:h 8:m -8,8:h 8:m -8,8:h 8:m 4,0
  85. _F$ = v -16:h 8:m -8,8:h 8:m 4,8
  86. _G$ = m 8,-16:h -8:v 16:h 8:v -8:h -4:m 8,8
  87. _H$ = v -16:m 0,8:h 8:m 0,-8:v 16:m 4,0
  88. _I$ = h 4:m -2,0:v -16:m -2,0:h 4:m 4,16
  89. _J$ = m 0,-2:v 2:h 8:v -16:m -2,0:h 4:m 4,16
  90. _K$ = v -16:m 0,8:l 8,-8:m -8,8:l 8,8:m 4,0
  91. _L$ = m 0,-16:v 16:h 8:m 4,0
  92. _M$ = v -16:l 4,8:l 4,-8:v 16:m 4,0
  93. _N$ = v -16:l 8,16:v -16:m 4,16
  94. _O$ = v -16:h 8:v 16:h -8:m 12,0
  95. _P$ = v -16:h 8:v 8:h -8:m 12,8
  96. _Q$ = v -16:h 8:v 16:h -8:m 6,-4:l 4,8:m 2,-4
  97. _R$ = v -16:h 8:v 8:h -8:l 8,8:m 4,0
  98. _S$ = h 8:v -8:h -8:v -8:h 8:m 4,16
  99. _T$ = m 4,0:v -16:m -4,0:h 8:m 4,16
  100. _U$ = m 0,-16:v 16:h 8:v -16:m 4,16
  101. _V$ = m 0,-16:l 8,16:l 8,-16:m 4,16
  102. _W$ = m 0,-16:v 16:l 4,-8:l 4,8:v -16:m 4,16
  103. _X$ = l 8,-16:m -8,0:l 8,16:m 4,0
  104. _Y$ = m 4,0:v -8:l -4,-8:m 8,0:l -4,8:m 8,8
  105. _Z$ = m 0,-16:h 8:l -8,16:h 8:m 4,0
  106. ; Conversion of punctuation to valid identifier names. Limited to common signs only...
  107. PunctList     = ,.;: -+*/=?!()@&'"`%_
  108. PunctToLetter = cdsC_DPMSeIEoOaAqQpu
  109. ; Comma
  110. _@c = m 0,-2:v 4:m 4,-2
  111. ; Dot
  112. _@d = v -2:m 4,2
  113. ; Semi-colon
  114. _@s = m 0,-8:v 2:m 0,4:v 4:m 4,-2
  115. ; Colon
  116. _@C$ =  v -2:m 0,-4:v -2:m 4,8
  117. ; Space
  118. _@_ = m 6,0
  119. ; Dash
  120. _@D$ = m 0,-6:h 6:m 4,6
  121. ; Plus
  122. _@P$ = m 4,-2:v -8:m -4,4:h 8:m 4,6
  123. ; Multiply
  124. _@M$ = m 0,-6:h 8:m -8,4:l 8,-8:m -8,0:l 8,8:m 4,2
  125. ; Slash
  126. _@S$ = l 8,-16:m 4,16
  127. ; Equals
  128. _@e = m 0,-4:h 8:m -8,-4:h 8:m 4,8
  129. ; Question mark / Interrogation point
  130. _@I$ = m 4,0:v -2:m 0,-2:v -4:h 4:v -8:h -8:v 4:m 12,12
  131. ; Exclamation mark
  132. _@E$ = v -2:m 0,-2:v -12:m 4,16
  133. ; Commercial at (arobase)
  134. _@a = m 16,4:h -16:v -20:h 16:v 16:h -12:v -8:h 8:v 8:m 8,0
  135. ; Ampersand
  136. _@A$ = m 12,0:l -12,-12:v -4:h 8:v 4:l -8,8:v 4:h 4:l 8,-8:m 4,8
  137. ; Single Quote
  138. _@q = m 0,-14:v 4:m 4,10
  139. ; Double Quote
  140. _@Q$ = m 0,-14:v 4:m 4,-4:v 4:m 4,10
  141. ; Percent
  142. _@p = l 8,-12:m -8,0:h 2:v 2:h -2:v -2:m 8,12:h -2:v -2:h 2:v 2:m 4,0
  143. ; Underscore
  144. _@u = h 8:m 4,0
  145.  
  146. ; F1 = fast exit if things go wrong...
  147. F3:: ExitApp
  148. ; F2 = reload the script (after changes)
  149.  
  150. F2::
  151. InputBox text, Enter text to type
  152. If ErrorLevel
  153.     Return ; Cancelled
  154. fukWord = %text%
  155. Return
  156.  
  157. F1::
  158. Loop Parse, fukWord
  159. {
  160. ;~  MsgBox %A_LoopField%
  161.     ; Memorize current position, reference point for the absolute moves
  162.     MouseGetPos startX, startY
  163.     pos := InStr(PunctList, A_LoopField)
  164.     If (pos > 0)
  165.     {
  166.         subst := SubStr(PunctToLetter, pos, 1)
  167.         sign = @%subst%
  168.         If subst is upper
  169.         {
  170.             ; Uppercase symbol
  171.             sign .= "$"
  172.         }
  173. ;~          msgbox Subst: %pos% %subst% %sign%
  174.     }
  175.     Else
  176.     {
  177.         sign := A_LoopField
  178.         If sign is upper
  179.         {
  180.             ; Uppercase symbol
  181.             sign .= "$"
  182.         }
  183.     }
  184.     instrVar = _%sign%
  185.     instructions := %instrVar%
  186. ;~  msgbox %A_LoopField% | %pos% | %subst% | %instrVar% | %instructions%
  187.     Loop Parse, instructions, :
  188.     {
  189.         parseOrder(A_LoopField)
  190.     }
  191. }
  192. Return
  193.  
  194. parseOrder(order)
  195. {
  196.     Global prevX, prevY, startX, startY
  197.  
  198.     command := getCommand(order)
  199.     x := getX(order)
  200.     y := getY(order)
  201. ;~  msgbox %order% => %command% %x% %y%
  202.     If (command == "M")
  203.     {
  204.         x -= startX
  205.         y -= startY
  206.         moveTo(x, y)
  207.     }
  208.     Else If (command == "m")
  209.     {
  210.         moveTo(x, y)
  211.     }
  212.     Else If (command == "L")
  213.     {
  214.         x -= startX
  215.         y -= startY
  216.         lineTo(x, y)
  217.     }
  218.     Else If (command == "l")
  219.     {
  220.         lineTo(x, y)
  221.     }
  222.     Else If (command == "H")
  223.     {
  224.         x -= startX
  225.         lineTo(x, y)
  226.     }
  227.     Else If (command == "h")
  228.     {
  229.         lineTo(x, prevY)
  230.     }
  231.     Else If (command == "V")
  232.     {
  233.         y -= startY
  234.         lineTo(x, y)
  235.     }
  236.     Else If (command == "v")
  237.     {
  238.         lineTo(prevX, x) ; Only one parameter so the y value is in the 'x' variable
  239.     }
  240.     prevX = x
  241.     prevY = y
  242. }
  243.  
  244. getCommand(order)
  245. {
  246.     Return SubStr(order, 1, 1)
  247. }
  248. getX(order)
  249. {
  250.     Global scale, offsetX
  251.     RegExMatch(order, ". ([+-]?[\d.]+)", x)
  252.     Return x1 * scale + offsetX
  253. }
  254. getY(order)
  255. {
  256.     Global scale, offsetY
  257.     RegExMatch(order, ". [+-]?[\d.]+,([+-]?[\d.]+)", y)
  258.     Return y1 * scale + offsetY
  259. }
  260.  
  261. moveTo(x, y)
  262. {Sleep 300
  263.     ;Click down
  264.     Global speed
  265.     MouseMove x, y, speed, R
  266.     ;Click up
  267. }
  268. lineTo(x, y)
  269. {
  270.     Global speed, prevX, prevY
  271.     MouseClickDrag L, prevX, prevY, x, y, speed, R
  272. }
  273.  
  274. moveToAbs(x, y)
  275. {
  276.     Global speed
  277.     Click down
  278.     MouseMove x, y, speed
  279.     Click up
  280. }
  281. lineToAbs(x, y)
  282. {
  283.     Global speed, prevX, prevY
  284.     MouseClickDrag L, prevX, prevY, x, y, speed
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement