PageRenderTime 33ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/camerb-OCR-function/thirdParty/mg.ahk

https://github.com/camerb/AHKs
AutoHotKey | 159 lines | 101 code | 8 blank | 50 comment | 25 complexity | 0a5f015534ce2c9fb20610d4f9646597 MD5 | raw file
  1. /*==Description=========================================================================
  2. MOUSE GESTURES module
  3. Author: Learning one (Boris Mudrinic)
  4. Contact: boris-mudrinic@net.hr
  5. AHK forum: http://www.autohotkey.com/forum/topic56472.html
  6. License:
  7. Mouse gestures module is free for non-commercial, personal use.
  8. You are not allowed to use it commercialy or have any profit from it in general, without my written permission.
  9. I'm not responsible for any damages arising from the use of Mouse gestures module. You are not allowed to remove
  10. comments from this file.
  11. In majotiry of cases, mentioning my name and contact will probably be all what I'll demand for giving you permission
  12. to use this module commercialy. First ask and than act!
  13. Documentation.
  14. Mouse gestures are specific mouse movements which can be recognized by this module.
  15. Gestures recognition system recognizes 4 basic mouse movements; up, down, right, left.
  16. Abbreviations for those movements are U (up), D (down) , R (right), and L (left).
  17. Minimal mouse movement distance which this module recognizes as movement is 9 pixels.
  18. To recognize mouse gesture, you have to call MG_Recognize() function. You can:
  19. 1) store performed gesture in variable. Example: Gesture := MG_Recognize()
  20. 2) or execute existing MG_ function. Syntaxs: "MG_" means mouse gesture. "U" means up, "D" down, "R" right, "L" left.
  21. So, for example, if function MG_R() exists in your script, it will be executed when you perform "drag right gesture"
  22. MG_RU() will be executed when you perform "drag right up gesture", MG_UDU() - "drag up down up gesture", etc.
  23. MG_Recognize(MGHotkey="", ToolTip=0, MaxMoves=3, ExecuteMGFunction=1, SendIfNoDrag=1)
  24. All parameters are optional.
  25. - MGHotkey mouse gesture hotkey. Can be: 1) any mouse button that can be pressed down and 2) any keyboard key
  26. except alt, control, shift (modifiers).
  27. - ToolTip 1 means show gesture in tooltip while performing it, 0 means don't show it.
  28. - MaxMoves maximum number of moves (directions) in one gesture. If you perform more moves than specified,
  29. gesture will be canceled. In that case, MG_Recognize() will not execute existing MG_<gesture>
  30. function and will return blank value.
  31. - ExecuteMGFunction 1 means execute existing MG_<gesture> function. 0 means don't execute it.
  32. - SendIfNoDrag 1 means send MGHotkey click (press) if drag was under 9 pixels. 0 Means don't send it.
  33. MG_Recognize() return values:
  34. - blank if gesture is canceled
  35. - 0 if you dragged MGHotkey for less than 9 pixels
  36. - <performed gesture> for example; R, D, LD, LUL, URL, etc.
  37. If SendIfNoDrag = 1 (default), normal MGHotkey's click function is preserved; just click and don't drag and module will
  38. send normal click. There are no built-in actions on gestures. It's up to you to write your commands that fit your needs.
  39. You can find more informations about this type of mouse gestures in Radial menu help file. You will find Radial menu here:
  40. http://www.autohotkey.com/forum/viewtopic.php?p=308352#308352
  41. */
  42. ;===Functions===========================================================================
  43. MG_GetMove(Angle)
  44. {
  45. Loop, 4
  46. {
  47. if (Angle <= 90*A_Index-45)
  48. {
  49. Sector := A_Index
  50. Break
  51. }
  52. Else if (A_Index = 4)
  53. Sector = 1
  54. }
  55. if Sector = 1
  56. Return "U"
  57. else if Sector = 2
  58. Return "R"
  59. else if Sector = 3
  60. Return "D"
  61. else if Sector = 4
  62. Return "L"
  63. }
  64. MG_GetAngle(StartX, StartY, EndX, EndY)
  65. {
  66. x := EndX-StartX, y := EndY-StartY
  67. if x = 0
  68. {
  69. if y > 0
  70. return 180
  71. Else if y < 0
  72. return 360
  73. Else
  74. return
  75. }
  76. deg := ATan(y/x)*57.295779513
  77. if x > 0
  78. return deg + 90
  79. Else
  80. return deg + 270
  81. }
  82. MG_GetRadius(StartX, StartY, EndX, EndY)
  83. {
  84. a := Abs(endX-startX), b := Abs(endY-startY), Radius := Sqrt(a*a+b*b)
  85. Return Radius
  86. }
  87. MG_Recognize(MGHotkey="", ToolTip=0, MaxMoves=3, ExecuteMGFunction=1, SendIfNoDrag=1)
  88. {
  89. CoordMode, mouse, Screen
  90. MouseGetPos, mx1, my1
  91. if MGHotkey =
  92. MGHotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W)")
  93. Loop
  94. {
  95. if !(GetKeyState(MGHotkey, "p"))
  96. {
  97. if Gesture =
  98. {
  99. if ToolTip = 1
  100. ToolTip
  101. if SendIfNoDrag = 1
  102. {
  103. Suspend, on
  104. SendInput, {%MGHotkey%}
  105. Suspend, off
  106. }
  107. Return 0
  108. }
  109. if ToolTip = 1
  110. ToolTip
  111. if (IsFunc("MG_" Gesture) <> 0 and ExecuteMGFunction = 1)
  112. MG_%Gesture%()
  113. Return Gesture
  114. }
  115. Sleep, 20
  116. MouseGetPos, EndX, EndY
  117. Radius := MG_GetRadius(mx1, my1, EndX, EndY)
  118. if (Radius < 9)
  119. Continue
  120. Angle := MG_GetAngle(mx1, my1, EndX, EndY)
  121. MouseGetPos, mx1, my1
  122. CurMove := MG_GetMove(Angle)
  123. if !(CurMove = LastMove)
  124. {
  125. Gesture .= CurMove
  126. LastMove := CurMove
  127. {
  128. if (StrLen(Gesture) > MaxMoves)
  129. {
  130. if ToolTip = 1
  131. ToolTip
  132. Progress, m2 b fs10 zh0 w80 WMn700, Gesture canceled
  133. Sleep, 200
  134. KeyWait, %MGHotkey%
  135. Progress, off
  136. Return
  137. }
  138. }
  139. }
  140. if ToolTip = 1
  141. ToolTip, %Gesture%
  142. }
  143. }