Set Key State Up without triggering native function Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Set Key State Up without triggering native function

16 Dec 2019, 15:05

Hello -

How can I set the key state to "up" without effecting the native function?

The code below displays the current time in a tooltip when you hold the back button on the mouse for more than 500 milliseconds.

The Problem: When you release the button, the native "Back" function will proceed.
The Question: How can I set the key state to "up" without effecting the native function?

Code: Select all

#SingleInstance Force
SetBatchLines -1

~XButton1::
	If (A_PriorHotkey "XButton1" AND A_TimeSincePriorHotkey < 500)
	{
	GoTo, SubTime
	}


SubTime:
;~XButton1:: ; ~ allows native function as I need the back button to work.
Loop
	{
	CurentTime := SubStr(A_Now,-4)
	Tooltip, %CurentTime% ; Display the curent date & time in tooltip.
	GetKeyState, state, XButton1, P ; Check to see if XButton1 is depressed.
	sleep 250 ; sleep for one quarter second.
If State = U ; If XButton1 is up (not depressed).
	{{
	Tooltip, ; Turns Tooltip off.
	break ; Break the loop.
	}}
	}
	return
	
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Set Key State Up without triggering native function

16 Dec 2019, 16:08

Your description doesn't correspond to the code, which itself has a misty syntax.
Double press triggers ToolTip:

Code: Select all

~XButton1::
	If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 500)
	{
	GoTo, SubTime
	}
Return
Holding for half a second triggers ToolTip:

Code: Select all

~XButton1::
	KeyWait, XButton1, T.5
    if ErrorLevel
	{
	GoTo, SubTime
	}
Return
Better Time display:

Code: Select all

CurentTime := SubStr(A_Now,-5, 2) ":" SubStr(A_Now,-3, 2) ":" SubStr(A_Now,-1)
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Set Key State Up without triggering native function

16 Dec 2019, 16:32

That is progress, I modified the code using your suggestion. @rommmcek
The problem When I release the Back mouse button, the web page will navigate "back".
Question How can I release the mouse button without a web page navigating "back"?

Updated code below....

Code: Select all

#SingleInstance Force
SetBatchLines -1

~XButton1::
	KeyWait, XButton1, T.5
	;send, {XButton1}
    if ErrorLevel
	{
	GoTo, SubTime
	}
Return

;If (A_PriorHotkey <> "XButton1" and A_TimeSincePriorHotkey < 2000)	
SubTime:	
Loop
	{{
	CurentTime := SubStr(A_Now,-5, 2) ":" SubStr(A_Now,-3, 2) ":" SubStr(A_Now,-1)
	Tooltip, %CurentTime% ; Display the curent date & time in tooltip.
	GetKeyState, state, XButton1, P ; Check to see if XButton1 is depressed.
	sleep 250 ; sleep for one quarter second.
	If State = U ; If XButton1 is up (not depressed).
	{{{
	Tooltip, ; Turns Tooltip off.
	break ; Break the loop.
	}}}
	}}
	return
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Set Key State Up without triggering native function  Topic is solved

16 Dec 2019, 16:34

I followed your initial code. Try this:

Code: Select all

XButton1::
	KeyWait, XButton1, T.5
    if ErrorLevel
	{
	GoTo, SubTime
	} else Send, {XButton1}
Return
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Set Key State Up without triggering native function

16 Dec 2019, 16:48

Thank you @rommmcek :bravo:
You did an amazing job! Thanks so much for sharing your knowledge. I truly appericate it.

Completed code below....

Code: Select all

#SingleInstance Force
SetBatchLines -1

XButton1::
	KeyWait, XButton1, T.5
    if ErrorLevel
	{
	GoTo, SubTime
	} Else Send, {XButton1} 
Return
	
SubTime:	
Loop
	{{
	CurentTime := SubStr(A_Now,-5, 2) ":" SubStr(A_Now,-3, 2) ":" SubStr(A_Now,-1)
	Tooltip, %CurentTime% ; Display the curent date & time in tooltip.
	GetKeyState, state, XButton1, P ; Check to see if XButton1 is depressed.
	sleep 250 ; sleep for one quarter second.
	If State = U ; If XButton1 is up (not depressed).
	{{{
	Tooltip, ; Turns Tooltip off.
	break ; Break the loop.
	}}}
	}}
	return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: tabr3 and 187 guests