Holding down a key

Get help with using AutoHotkey and its commands and hotkeys
throwawayahkuser
Posts: 3
Joined: 10 Jan 2016, 11:51

Holding down a key

10 Jan 2016, 12:06

Hello, I'm looking for a little bit of assistance with getting my AHK script working.

The need for this is that I am playing a game where I need to press F3 quite frequently. It was Alt + F3 at first but I managed to only set it to F3 by editing the script. Anyways, I need to press F3 quite frequently because it enables some information that I require during certain situations in this game.

A rundown of how it works currently is that, when you press F3, it shows the information, and when you press F3 again, it disappears.

I want to make it so that when I press my middle mouse button down, it presses F3 and displays the information, and when I release my middle mouse button, it presses F3 again and hides the information.

Code: Select all

MButton::
Send {F3 Down}{F3 Up}
return

MButton Up::
Send {F3 Down}{F3 Up}
return
It's barely working, and I want it to be more stable. If I frequently tap my middle mouse button, the game thinks that the information is actually enabled even when my middle mouse button is up. Also, when I hold my middle mouse button down, it spams F3. I want this to not be the case.

Excuse my brievity, if you need me to explain something in greater detail I'll be more than happy to try.
Zachatoo
Posts: 4
Joined: 04 Jan 2016, 02:56

Re: Holding down a key

10 Jan 2016, 12:22

Some games don't like AHK, could you try this and see if it works? Try adjusting the Sleep time as well.

Code: Select all

MButton::
Send {F3 Down}
Sleep 20
Send {F3 Up}
return

MButton Up::
Send {F3 Down}
Sleep 20
Send {F3 Up}
return
throwawayahkuser
Posts: 3
Joined: 10 Jan 2016, 11:51

Re: Holding down a key

10 Jan 2016, 12:34

Hi there, it works fine for holding the key down now, but the issue that I am now facing is that when I quickly tap the middle mouse button it stays with the information box on, just like I just pressed F3 once to toggle it on.
User avatar
Nextron
Posts: 1378
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Holding down a key

10 Jan 2016, 13:54

How's this:

Code: Select all

MButton::
	SetKeyDelay,30,30 ;Make key represses long so game detects them
	Send {F3} ;Turn info on
	Sleep 300 ;Regardless of how long you press MButton, keep info on this long, YMMV
	KeyWait MButton ;Wait for MButton release
	Send {F3} ;Turn info off
Return
throwawayahkuser
Posts: 3
Joined: 10 Jan 2016, 11:51

Re: Holding down a key

10 Jan 2016, 17:18

Thank you a lot to the both of you, it's almost working perfectly now but it's most certainly better than my code.

Return to “Ask For Help”

Who is online

Users browsing this forum: FanaticGuru, Gio, grossermanitu and 59 guests