Advertisement
Guest User

Untitled

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