Press a button if another has been pressed x time Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Du001
Posts: 3
Joined: 27 Feb 2017, 10:57

Press a button if another has been pressed x time

27 Feb 2017, 11:22

Yesterday the middle button of my mouse was damaged, so I decided to create a script in which if I press for x time the "back" button (Xbutton1) the central button (MButton) gets activated. This is the code I have, the problem is that both keys are activated after holding down the "back" button. I only want the Mbutton gets activated.

Code: Select all

Loop {
if (GetKeyState("XButton1"))
{
while getkeystate("XButton1")
{
count++
sleep 50
}
if count>5
	Send, {MButton}
count=0
}
}
return
Can you guys help me?

I'm new to this. :P
bigdeal
Posts: 66
Joined: 13 Feb 2017, 06:31

Re: Press a button if another has been pressed x time

27 Feb 2017, 13:42

hmm your the second one posting this question lemme send you to this thread (it's very good)
https://autohotkey.com/board/topic/6457 ... re-thread/
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Press a button if another has been pressed x time

27 Feb 2017, 13:50

Code: Select all

delay := 200 ;200ms
return

xbutton1::
start := a_tickcount + delay
while (GetKeyState("xbutton1","P")) {
	if (a_tickcount > start) {
		Send, {MButton}
		break
	}
}
return
Hopefully that helps you with your mouse problem =P
Du001
Posts: 3
Joined: 27 Feb 2017, 10:57

Re: Press a button if another has been pressed x time

27 Feb 2017, 14:18

Thanks for answering Spawnova, but I need to keep the functionality of the Xbutton1 if it doesn't reach pressed the desired time. Sorry, I Didn't explained that.
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Press a button if another has been pressed x time  Topic is solved

27 Feb 2017, 14:53

Ah I see, just need to edit the script a little..

Code: Select all

delay := 200 ;200ms
return

xbutton1::
start := a_tickcount + delay
while (GetKeyState("xbutton1","P")) {
	if (a_tickcount > start) {
		start := 0 ;can re use this variable instead of making a new one
		Send, {MButton}
		break
	}
}
if (start > 0) ;if we held long enough start would still be a large value
	send {xbutton1}
return
Du001
Posts: 3
Joined: 27 Feb 2017, 10:57

Re: Press a button if another has been pressed x time

27 Feb 2017, 15:06

Thank you very much, it works perfectly xD

Solved!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk and 342 guests