Advertisement
Guest User

Ahk for buggy mouse

a guest
Apr 6th, 2015
3,363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.30 KB | None | 0 0
  1. /*
  2. ** Buggy-Mouse.ahk - Fix a buggy mouse. Stop it from double-clicking when you try to single-click.
  3. **
  4. ** NOTE: Please use this URL when linking to Buggy Mouse: r.secsrv.net/AutoHotkey/Scripts/Buggy-Mouse
  5. **
  6. ** Updated: Thu, Nov 1, 2012 --- 11/1/12, 10:19:19am EDT
  7. ** Location: r.secsrv.net/AutoHotkey/Scripts/Buggy-Mouse
  8. **
  9. ** Keywords: mouse double clicks when I click once
  10. ** Keywords: mouse double clicks when I single click
  11. ** Keywords: mouse double clicks on its own
  12. ** Keywords: mouse double clicks with one click
  13. ** Keywords: mouse double clicks on single click
  14. ** Keywords: mouse double clicks on one click
  15. ** Keywords: mouse double-clicking when you single-click
  16. ** Keywords: set mouse minimum double click speed
  17. ** Keywords: debounce mouse
  18. **
  19. ** Author: JSLover - r.secsrv.net/JSLover - r.secsrv.net/JSLoverAHK
  20. **
  21. ** NOTE: Please use AutoHotkey 1.1+ (AutoHotkey_L) for this script!
  22. ** AutoHotkey.com
  23. ** L.AutoHotkey.net
  24. **
  25. ** NOTE: Compiled version available here: r.secsrv.net/AutoHotkey/Scripts/Buggy-Mouse.exe
  26. **
  27. */
  28. #SingleInstance force
  29. OnExit, OnExit
  30.  
  31. ;// **************************** Settings ****************************
  32.  
  33. ;// Minimum double-click time. Any lower & it will be blocked (as being inhumanly fast).
  34. DoubleClickMin_ms:=90
  35.  
  36. ;// *** DISABLED *** ;// Minimum click after mouse-up time. Any lower & it will be blocked (as being inhumanly fast).
  37. ;// *** DISABLED *** ClickAfterMouseUpMin_ms:=100
  38.  
  39. ;// **************************** /Settings ****************************
  40.  
  41. ;// **************************** Advanded Settings ****************************
  42.  
  43. ;// Enable logging if you need to report a bug.
  44. ;// Default (Disabled): Log=0
  45. Log=0
  46.  
  47. ;// Enable debugging if you want to see blocked/allowed clicks.
  48. ;// Default (Disabled): Debug=0
  49. Debug=0
  50.  
  51. ;// Enable this if you only want to see blocked clicks (when debugging is enabled).
  52. ;// Default (Enabled): Debug_OnlyBlocked=1
  53. ;// Note: Requires Debug (above) to be enabled (or no debugging will happen at all)
  54. Debug_OnlyBlocked=1
  55.  
  56. ;// **************************** /Advanded Settings ****************************
  57.  
  58. Gosub, OnStartup
  59.  
  60. ;// *** Build Tray Menu ***
  61.  
  62. Text_ClicksBlocked=Clicks Blocked
  63. Text_Debug=Debug
  64. Text_Debug_OnlyBlocked=Debug (only blocked)
  65.  
  66. Menu, Tray, Add, %Text_ClicksBlocked%, BuggyMouse_MenuSelect_ClicksBlocked
  67. Text_ClicksBlocked_MenuCurrent:=Text_ClicksBlocked
  68. Menu, Tray, Default, %Text_ClicksBlocked%
  69. Menu, Tray, Add, %Text_Debug%, BuggyMouse_MenuSelect_Debug
  70. Menu, Tray, Add, %Text_Debug_OnlyBlocked%, BuggyMouse_MenuSelect_Debug_OnlyBlocked
  71. Menu, Tray, Disable, %Text_Debug_OnlyBlocked%
  72.  
  73. Menu, Tray, MainWindow
  74. Menu, Tray, NoStandard
  75. Menu, Tray, Add
  76. Menu, Tray, Standard
  77.  
  78. ;// *** /Build Tray Menu ***
  79.  
  80. ;// BuggyMouse_Debug:=1
  81. ;// BuggyMouse_Debug_OnlyBlocked:=1
  82. if (Debug) {
  83. Gosub, BuggyMouse_MenuSelect_Debug
  84. }
  85.  
  86. if (Debug_OnlyBlocked) {
  87. Gosub, BuggyMouse_MenuSelect_Debug_OnlyBlocked
  88. }
  89. return
  90.  
  91. OnStartup:
  92. logdir=%A_ScriptDir%
  93. logfilename=%A_ScriptName%.log
  94. logfile=%logdir%\%logfilename%
  95.  
  96. time:=time()
  97. logmsg=
  98. (LTrim
  99. %A_ScriptName% Started`t`t%time%
  100. ` Status`t`tUpDn`t Key`t`t`tReason`t`t`t`tWindow`n
  101. )
  102. log(logmsg)
  103. return
  104.  
  105. OnExit:
  106. time:=time()
  107. logmsg=
  108. (LTrim
  109. %A_ScriptName% Exited`t`t%time%`n`n
  110. )
  111. log(logmsg)
  112. ExitApp
  113.  
  114. *LButton::
  115. *MButton::
  116. *RButton::
  117.  
  118. A_ThisHotkey_VarSafe:=Hotkey_MakeVarSafe(A_ThisHotkey, "*")
  119. A_ThisHotkey_NoModifiers:=Hotkey_RemoveModifiers(A_ThisHotkey)
  120. ;// A_ThisHotkey_Modifiers:=Hotkey_GetModifiers(A_ThisHotkey)
  121. A_ThisHotkey_KeyName:=Hotkey_GetKeyName(A_ThisHotkey)
  122.  
  123. log_key:="Down`t" A_ThisHotkey "`t"
  124. Critical
  125. di++
  126.  
  127. TimeSinceLastMouseDown:=A_TickCount-LastMouseDown_ts
  128.  
  129. ;// TimeSinceLastMouseUp:=A_TickCount-LastMouseUp_ts
  130.  
  131. DoubleClickTooFast:=TimeSinceLastMouseDown<=DoubleClickMin_ms
  132.  
  133. ;// *** DISABLED *** ClickAfterMouseUpTooSoon:=(ClickAfterMouseUpMin_ms!="" && TimeSinceLastMouseUp<=ClickAfterMouseUpMin_ms)
  134. ;// if ((A_ThisHotkey==LastMouseDown && DoubleClickTooFast) || ClickAfterMouseUpTooSoon) {
  135. if (A_ThisHotkey==LastMouseDown && (DoubleClickTooFast || ClickAfterMouseUpTooSoon)) {
  136. ;// if (A_TimeSincePriorHotkey<=DoubleClickMin_ms) {
  137. reason:=DoubleClickTooFast ? "DoubleClickTooFast" "(" TimeSinceLastMouseDown ")" "(" DoubleClickMin_ms ")"
  138. : ClickAfterMouseUpTooSoon ? "ClickAfterMouseUpTooSoon" "(" TimeSinceLastMouseUp ")" "(" ClickAfterMouseUpMin_ms ")"
  139. : "Unknown"
  140. msg=`nblocked (%reason%)
  141. blockeddown:=1
  142. BlockedCount_Down++
  143. BlockedCount_%A_ThisHotkey_VarSafe%++
  144. Gosub, BuggyMouse_UpdateStatus_ClicksBlocked
  145.  
  146. log_action:="BLOCKED`t"
  147. } else {
  148. reason:=""
  149. Send, {Blind}{%A_ThisHotkey_KeyName% DownTemp}
  150. msg=`nSent, {Blind}{%A_ThisHotkey_KeyName% DownTemp}`n`n
  151. (LTrim C
  152. if (%A_ThisHotkey%==%LastMouseDown% && (%DoubleClickTooFast% || %ClickAfterMouseUpTooSoon%))
  153. )
  154.  
  155. log_action:="`tallowed"
  156. }
  157. BuggyMouse_DebugMsg_down=%di%: %A_ThisHotkey%(%TimeSinceLastMouseDown%)%LastMouseDown%%msg%
  158. msg=
  159. Gosub, BuggyMouse_Debug
  160. LastMouseDown:=A_ThisHotkey
  161. LastMouseDown_ts:=A_TickCount
  162.  
  163. wininfo:=WinGetInfo("a")
  164. log(log_action "`t`t" log_key "`t`t" reason "`t`t`t`t`t" wininfo "`n")
  165. return
  166.  
  167. *LButton up::
  168. *MButton up::
  169. *RButton up::
  170.  
  171. A_ThisHotkey_VarSafe:=Hotkey_MakeVarSafe(A_ThisHotkey, "*")
  172. A_ThisHotkey_NoModifiers:=Hotkey_RemoveModifiers(A_ThisHotkey)
  173. ;// A_ThisHotkey_Modifiers:=Hotkey_GetModifiers(A_ThisHotkey)
  174. A_ThisHotkey_KeyName:=Hotkey_GetKeyName(A_ThisHotkey)
  175.  
  176. log_key:=" Up `t" A_ThisHotkey
  177. Critical
  178. ui++
  179. TimeSinceLastMouseUp:=A_TickCount-LastMouseUp_ts
  180. ;// if (A_ThisHotkey=A_PriorHotkey && A_TimeSincePriorHotkey<=DoubleClickMin_ms) {
  181. ;// if (A_ThisHotkey=LastMouseUp && A_TimeSincePriorHotkey<=DoubleClickMin_ms) {
  182. if (blockeddown) {
  183. msg=`nblocked
  184. blockedup:=1
  185. BlockedCount_Up++
  186. BlockedCount_%A_ThisHotkey_VarSafe%++
  187. Gosub, BuggyMouse_UpdateStatus_ClicksBlocked
  188.  
  189. log_action:="BLOCKED`t"
  190. } else {
  191. Send, {Blind}{%A_ThisHotkey_KeyName% up}
  192. msg=`nSent, {Blind}{%A_ThisHotkey_KeyName% up}
  193. log_action:="`tallowed"
  194. }
  195. ;// if (BuggyMouse_Debug) {
  196. BuggyMouse_DebugMsg_up=%ui%: %A_ThisHotkey%(%TimeSinceLastMouseUp%)%LastMouseUp%%msg%
  197. msg=
  198. Gosub, BuggyMouse_Debug
  199. ;// }
  200. blockeddown=
  201. blockedup=
  202. LastMouseUp:=A_ThisHotkey
  203. LastMouseUp_ts:=A_TickCount
  204.  
  205. wininfo:=WinGetInfo("a")
  206. log(log_action "`t`t" log_key "`t`t" reason "`t`t`t`t`t" wininfo "`n")
  207. return
  208.  
  209. BuggyMouse_Debug_ShowLastMsg:
  210. ;// BuggyMouse_Debug_ShowLastMsg=1
  211. BuggyMouse_Debug:
  212. CoordMode, Tooltip
  213. if (A_ThisLabel="BuggyMouse_Debug_ShowLastMsg"
  214. || (BuggyMouse_Debug && (!BuggyMouse_Debug_OnlyBlocked
  215. || (BuggyMouse_Debug_OnlyBlocked && (blockeddown||blockedup))))) {
  216. Tooltip, %BuggyMouse_DebugMsg_down%`n`n%BuggyMouse_DebugMsg_up%, 819, 619
  217. } else {
  218. Tooltip
  219. }
  220. return
  221.  
  222. BuggyMouse_UpdateStatus_ClicksBlocked:
  223. BlockedCount_Total:=BlockedCount_Down+BlockedCount_Up
  224. Text_ClicksBlocked_MenuNew=%Text_ClicksBlocked%: %BlockedCount_Total%
  225. Menu, Tray, Rename, %Text_ClicksBlocked_MenuCurrent%, %Text_ClicksBlocked_MenuNew%
  226. Text_ClicksBlocked_MenuCurrent:=Text_ClicksBlocked_MenuNew
  227. Menu, Tray, Tip, %Text_ClicksBlocked_MenuCurrent% - %A_ScriptName%
  228. return
  229.  
  230. BuggyMouse_MenuSelect_ClicksBlocked:
  231. msgbox, 64, ,
  232. (LTrim C
  233. %Text_ClicksBlocked_MenuCurrent%
  234.  
  235. Down(%BlockedCount_Down%)
  236. Up(%BlockedCount_Up%)
  237.  
  238. LButton(%BlockedCount_LButton%)
  239. MButton(%BlockedCount_MButton%)
  240. RButton(%BlockedCount_RButton%)
  241.  
  242. LButton up(%BlockedCount_LButton_up%)
  243. MButton up(%BlockedCount_MButton_up%)
  244. RButton up(%BlockedCount_RButton_up%)
  245. )
  246. return
  247.  
  248. BuggyMouse_MenuSelect_Debug:
  249. BuggyMouse_Debug:=!BuggyMouse_Debug
  250. Menu, Tray, ToggleCheck, %Text_Debug%
  251. Menu, Tray, ToggleEnable, %Text_Debug_OnlyBlocked%
  252. Tooltip
  253. return
  254.  
  255. BuggyMouse_MenuSelect_Debug_OnlyBlocked:
  256. BuggyMouse_Debug_OnlyBlocked:=!BuggyMouse_Debug_OnlyBlocked
  257. Menu, Tray, ToggleCheck, %Text_Debug_OnlyBlocked%
  258. Tooltip
  259. return
  260.  
  261. Hotkey_MakeVarSafe(p_hotkey, p_ignorechars="") {
  262. replace:=p_hotkey
  263.  
  264. StringReplace, replace, replace, $, % !InStr(p_ignorechars, "$") ? "KH_":""
  265. StringReplace, replace, replace, ~, % !InStr(p_ignorechars, "~") ? "PT_":""
  266. StringReplace, replace, replace, *, % !InStr(p_ignorechars, "*") ? "WC_":""
  267.  
  268. StringReplace, replace, replace, <^>!, AltGr_
  269. StringReplace, replace, replace, <, L, a
  270. StringReplace, replace, replace, >, R, a
  271. StringReplace, replace, replace, &, and
  272.  
  273. StringReplace, replace, replace, ^, Ctrl_, a
  274. StringReplace, replace, replace, +, Shift_, a
  275. StringReplace, replace, replace, #, Win_, a
  276. StringReplace, replace, replace, !, Alt_, a
  277.  
  278. replace:=RegExReplace(replace, "i)[^a-z0-9_]", "_")
  279.  
  280. p_hotkey:=replace
  281.  
  282. return p_hotkey
  283. }
  284.  
  285. Hotkey_GetModifiers(p_hotkey) {
  286. return RegExReplace(p_hotkey, "i)[\w\s]+$")
  287. }
  288.  
  289. Hotkey_RemoveModifiers(p_hotkey) {
  290. return RegExReplace(p_hotkey, "i)^[^a-z0-9_]+")
  291. }
  292.  
  293. Hotkey_GetKeyName(p_hotkey) {
  294.  
  295. p_hotkey:=Hotkey_RemoveModifiers(p_hotkey)
  296.  
  297. ;// Get string before 1st space...(removes "up" or "down" from name of key)
  298. Loop, Parse, p_hotkey, " "
  299. {
  300. p_hotkey:=A_LoopField
  301. break
  302. }
  303.  
  304. return p_hotkey
  305. }
  306.  
  307. log(p_msg, p_file="") {
  308. Global Log, logfile
  309. if (!Log) {
  310. return
  311. }
  312. if (p_file="") {
  313. p_file:=logfile
  314. }
  315. FileAppend, %p_msg%, %p_file%
  316. }
  317.  
  318. time() {
  319. FormatTime, time, L1033, ddd, MMM d, yyyy --- M/d/yy h:mm:sstt
  320. return time
  321. }
  322.  
  323. WinGetInfo(p_win, ByRef r_win_title="", ByRef r_win_class="") {
  324. WinGetTitle, win_title, %p_win%
  325. WinGetClass, win_class, %p_win%
  326.  
  327. r_win_title:=(win_title ? win_title:"<no-title-info>")
  328. r_win_class:=(win_class ? win_class:"<no-class-info>")
  329.  
  330. ;// wininfo:=(win_title ? win_title:"<no-title-info>") " - " (win_class ? win_class:"<no-class-info>")
  331. wininfo:=(win_class ? win_class:"<no-class-info>") ": " (win_title ? win_title:"<no-title-info>")
  332. return wininfo
  333. }
  334.  
  335. ;// #ScrollLock::log("*** PROBLEM ***`n")
  336. ^+#!F8::Gosub, BuggyMouse_Debug_ShowLastMsg
  337. ^+#!F9::Suspend
  338. ^+#!F12::ExitApp
  339.  
  340. /* ;// **************************** Changelog / Version History ****************************
  341. **
  342. ** Created: Fri, Apr 11, 2008 --- 4/11/08, 11:19:19am
  343. ** Modified: Sat, Apr 12, 2008 --- 4/12/08, 5:38:19am
  344. ** Modified: Sun, Jul 10, 2011 --- 7/10/11, 3:19:19am EDT
  345. ** * Added blocking of "mouse down too soon after last mouse up"
  346. ** Modified: Wed, Jul 20, 2011 --- 7/20/11, 1:19:19pm EDT
  347. ** Modified: Thu, Aug 25, 2011 --- 8/25/11, 1:19:19am EDT
  348. ** * Temporarily disabled "mouse down too soon after last mouse up" blocking, until I get it working.
  349. ** Modified: Thu, Aug 25, 2011 --- 8/25/11, 2:38:19am EDT
  350. ** * Updated Keywords for search engines
  351. ** Modified: Sat, Aug 27, 2011 --- 8/27/11, 7:19:19am EDT
  352. ** * Added Logging
  353. ** Modified: Sat, Aug 27, 2011 --- 8/27/11, 2:38:19pm EDT
  354. ** * Added Window Info to log
  355. ** Modified: Sun, May 13, 2012 --- 5/13/12, 7:19:19pm EDT
  356. ** * Added support for blocking mouse clicks while holding down keyboard keys
  357. ** Modified: Mon, May 14, 2012 --- 5/14/12, 10:19:19am EDT
  358. ** * Updated Hotkey_MakeVarSafe()
  359. ** Modified: Tue, May 15, 2012 --- 5/15/12, 7:19:19am EDT
  360. ** * Hotkey_MakeVarSafe(): Fixed error msg/incompatibility with AutoHotkey < 1.1
  361. ** Modified: Thu, Nov 1, 2012 --- 11/1/12, 10:19:19am EDT
  362. ** * Made Debugging default to Off
  363. ** * Added "Debug" & "Debug_OnlyBlocked" to Settings section, for easier toggling of the default state
  364. **
  365. */ ;// **************************** /Changelog / Version History ****************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement