Stopping Unintentional Left Clicks

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Stopping Unintentional Left Clicks

28 Sep 2020, 19:39

Basically, my single left click mouse presses are getting confused for left click and hold because I have a fine motor skill Impairment. I only want the left click and hold to trigger if I hold down the left-click for 200 ms.

The issue I am having is described in the video clip where I captured the behavior on my computer. That's me talking in the audio. The audio is quiet but it's there.

(I originally posted it in the AutoHotkey IRC web client.)
https://www.dropbox.com/s/fghi82ue5h73dw5/autohotkey%20IRC%20question.mp4?dl=0

A kindly moderator donated some of their time to writing a script we thought would work but we just can't get it quite there, so the moderator directed me here, to you guys.

I appreciate any help.
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Stopping Unintentional Left Clicks

28 Sep 2020, 19:45

A broken jumping off point for anyone interested:

Code: Select all

setTitleMatchMode, 2
; #installKeybdHook
threshhold:=1000
isHeld:=0

setKeyDelay, 50, 50
setMouseDelay, 50

$lbutton::
	start:=A_TickCount
	isHeld:=0
	while (getKeyState("lbutton", "P"))
	{
		mouseClick, left
		sleep, 50
		if (A_TickCount-start>threshhold)
			isHeld:=1
		if (isHeld=1)
		{
			mouseClick, left
			ToolTip, % "a" A_TickCount-start, 100, 500, 2
		}
	}
	end:=A_TickCount
	if (end-start<threshhold)
	{
		; mouseClick, left
		ToolTip % "z" isHeld end-start, 150, 500
	}
		
return
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Stopping Unintentional Left Clicks

28 Sep 2020, 22:20

Code: Select all

Start:
Hotkey, LButton, Go
Return

Go:
SetTimer, Wait, -200
Hotkey, LButton, Nothing
Return

Nothing:
Return

Wait:
SetTimer, Type, 1
KeyWait, LButton
SetTimer, Type, Off
Gosub, Start
Return

Type:
Click
Return

F4::ExitApp
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: Stopping Unintentional Left Clicks

28 Sep 2020, 23:08

It works great except that occasionally some of my legitimmate clicks are ignored. I imagine I have to shrink the 200 ms?

Thank you so much.

I just noticed that with the script on I can no longer highlight text. Weird.
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Stopping Unintentional Left Clicks

29 Sep 2020, 05:20

This version is better. Remember: this will ignore clicks unless you hold the key for 200 ms. That is apparently what you needed. It's possible to modify the script so that, say, a short click is processed, and then everything else is ignored until 200 ms have passed.

Code: Select all

Start:
Hotkey, LButton, Go
Return

Go:
Hotkey, LButton, Nothing
SetTimer, Wait, -200
Return

Nothing:
Return

Wait:
While GetKeyState("LButton", "P")
 Click
Gosub, Start
Return

F4::ExitApp
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Stopping Unintentional Left Clicks

29 Sep 2020, 06:50

This script allows short initial clicks to be seen. Drag does not work because the script is generating clicks while the button is held.

Code: Select all

/* Stop trigger finger ============================================================================================
This script acts on the left button. It clicks only for short and long presses, but not presses of medium duration.
@mikeyww on 29 September 2020
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81565
===================================================================================================================
*/
; Press durations ---------------------------------------
short := 10, medium := 200 ; Change short to zero to eliminate Phase 1
; Phase 1: go = -1 : Short
; Phase 2: go =  0 : Medium
; Phase 3: go =  1 : Long (short+medium)
; -------------------------------------------------------

LButton::
go := -1
If short
 SetTimer, Phase, % -1 * short
Else Gosub, Phase
While GetKeyState("LButton", "P")
 If go ; Phase is short or long
  Click
Return

Phase: ; Advance to the next phase
go := go ? -0.5 * go - 0.5 : 1 ; Advance to the next phase
If !go
 SetTimer, Phase, % -1 * medium
Return

F4::ExitApp
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Stopping Unintentional Left Clicks

29 Sep 2020, 09:40

A shorter alternative here.

Code: Select all

LButton::
Click
KeyWait, LButton, T0.2
If ErrorLevel ; Button remains pressed after the wait
 While GetKeyState("LButton", "P")
  Click
Return
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Stopping Unintentional Left Clicks

29 Sep 2020, 10:36

SmithyZoomZoom wrote:
28 Sep 2020, 23:08
I just noticed that with the script on I can no longer highlight text. Weird.
this is the "its hard to keep the mouse acting as normal" issue I mentioned.
it's hard to override the behavior to do your own things, but if those conditions are not met, pretend like we never did anything.
since we replace the original behavior, we need to code the original back in if we want it. But thats a lot more than just a 'click' command, as mice have click, doubleclick, clickdrag. Since we are using AHK, these are no longer physical hardware events from the mouse itself, but simulated via ahk. So some programs might not accept them.

not saying it's impossible, there might be (probably are) ways around it. But sometimes a simple task is a lot harder than it sounds :D or you gotta get creative and avoid using a hotkey, like above.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Stopping Unintentional Left Clicks

29 Sep 2020, 16:04

I agree! Drag (e.g., highlight) seems tricky; I have not tried to do anything with it.
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: Stopping Unintentional Left Clicks

29 Sep 2020, 18:31

I agree! I see what you mean now. I feel a little guilty knowing it's more than I anticipated.

Just to simplify the thing, would it be possible to have a toggle hot key that I could assign to one of my extra mouse buttons, with a persistent tooltip labeled "Tiptoe Mode" for when the 200 ms limit is active and, "Charge Mode" for when the script is disabled, meaning my character is free to blunder full-speed ahead?

That might be a little easier than having the program interpret good clicks from bad clicks – would that be fair to say?

Oh, I noticed for whatever reason, when I was playing with the script last night, that pressing and holding the mouse button makes the character zoom across the screen uncontrollably fast: faster than in the game normally. If there's not a way to slow that down, it would be fine by me if the rapid movement were disabled in Tiptoe Mode.

(This script is mainly for precision moments, so I don't launch myself into another lava pit, again.)

The very last thing I'll mention, I would do it myself because I have the command bookmarked but I'm nervous to mess up your script. Here is the window spy information for the game:
https://www.dropbox.com/s/pzhizqkrqo0tuj5/20200929_161315.png?dl=0

Could you please make the toggle script only active, when the game is running?
(Only if you have time, of course.)
Thank you, thank you, thank you. I'm going to go try the latest versions of the script!
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Stopping Unintentional Left Clicks

29 Sep 2020, 21:25

Code: Select all

/* Stop trigger finger ============================================================================================
This script acts on the left button. It clicks only for short and long presses, but not presses of medium duration.
@mikeyww on 29 September 2020
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81565
Version 02
===================================================================================================================
*/
#IfWinActive Rogue ahk_class UnityWndClass
XButton1::charge := mode(!charge) ; Press the fourth mouse button to toggle the hotkey; change as needed
#IfWinActive

F4::
SoundBeep, 500, 30
ExitApp

LB:
Click
KeyWait, LButton, T0.2
If ErrorLevel ; Button remains pressed after the wait
 While GetKeyState("LButton", "P") {
  Sleep, 10 ; Adjust the slowdown as needed
  Click
 }
Return

mode(charge) {
 Static gw := 88, gh := 25, gx := A_ScreenWidth - gw - 25, gy := A_ScreenHeight - gh - 8
 Static winTitle := "Rogue ahk_class UnityWndClass"
 Gui, Destroy
 Gui, New, +AlwaysOnTop -Caption +ToolWindow Border
 Gui, Color, % charge ? "E6FFE6" : "FFDB00"
 Gui, Font, s9, Arial
 Gui, Add, Text,, % (charge ? "Charge" : " Tiptoe") " Mode  "
 Gui, Show, x%gx% y%gy% w%gw% h%gh%
 SoundBeep, charge ? 1500 : 1000, 25
 Hotkey, IfWinActive, %winTitle%
 Hotkey, LButton, LB, % charge ? "On" : "Off"
 Hotkey, IfWinActive
 WinActivate, %winTitle%
 Return charge
}
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: Stopping Unintentional Left Clicks

01 Oct 2020, 13:52

It's beautiful! And you even made the font on the tooltip fancy! Thank you so much. Question: Tiptoe Mode is still registering single clicks as double-click. That means I have to fiddle with the LButton, T0.2 section? To make the 0.2 a higher value? In tiptoe mode, I would be okay if double-clicking had to be disabled altogether. As in charge mode if the character is running too fast, that just means I have to increase the value of the sleep number you noted in your script, right?

Thanks again for your unbelievably gracious help.
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Stopping Unintentional Left Clicks

01 Oct 2020, 14:58

I realized that I was using the opposite definitions of Charge and Tiptoe. Update is below.

Code: Select all

/* Stop trigger finger ============================================================================================
This script acts on the left button. It clicks only for short and long presses, but not presses of medium duration.
@mikeyww on 01 October 2020
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81565
Version 03
===================================================================================================================
*/
#IfWinActive Rogue ahk_class UnityWndClass
XButton1::tiptoe := mode(!tiptoe) ; Press the fourth mouse button to toggle the hotkey; change as needed
#IfWinActive

F4::
SoundBeep, 500, 30
ExitApp

Tiptoe:
Click
KeyWait, LButton, T0.2
If ErrorLevel ; Button remains pressed after the wait
 While GetKeyState("LButton", "P") {
  Sleep, 10 ; Increase the sleep if tiptoe is too fast
  Click
 }
Return

mode(tiptoe) {
 Static gw := 88, gh := 25, gx := A_ScreenWidth - gw - 25, gy := A_ScreenHeight - gh - 8
 Static winTitle := "Rogue ahk_class UnityWndClass"
 Gui, Destroy
 Gui, New, +AlwaysOnTop -Caption +ToolWindow Border
 Gui, Color, % tiptoe ? "FFDB00" : "E6FFE6"
 Gui, Font, s9, Arial
 Gui, Add, Text,, % (tiptoe ? "Tiptoe" : " Charge") " Mode  "
 Gui, Show, x%gx% y%gy% w%gw% h%gh%
 SoundBeep, tiptoe ? 1000 : 1500, 25
 Hotkey, IfWinActive, %winTitle%
 Hotkey, LButton, Tiptoe, % tiptoe ? "On" : "Off"
 Hotkey, IfWinActive
 WinActivate, %winTitle%
 Return tiptoe
}
As you noted initially, the subroutine is disabled in Charge Mode, so whatever is happening in Charge Mode is happening "outside" the script, I think.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, jaka1, metallizer, Rohwedder and 326 guests