auto scope when aiming

Ask gaming related questions (AHK v1.1 and older)
war3player
Posts: 1
Joined: 06 Jul 2015, 09:43

auto scope when aiming

14 Nov 2015, 01:48

I am trying to do a script for a TPS called ZMR: If I click and hold RButton to aim, it automatically scopes by sending a WheelUp.
If you are using a weapon with a scope attached, you have an additional option when aiming: Click or spin the middle mouse wheel to zoom in through the scope.
I tried

Code: Select all

~RButton::
Sleep 500
MouseClick, WheelUp, , , 1
but it can't on/off toggle the auto-scope.
Then I did the trick in an awkward way by adapting an example code found in AHK help files into the following:

Code: Select all

#MaxThreadsPerHotkey 3
LWin::  ; LWin hotkey (change this hotkey to suit your preferences).
#MaxThreadsPerHotkey 1
if KeepLWinRunning  ; This means an underlying thread is already running the loop below.
{
    KeepLWinRunning := false  ; Signal that thread's loop to stop.
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
; Otherwise:
KeepLWinRunning := true
Loop
{
    ; The next four lines are the action you want to repeat (update them to suit your preferences):
    MouseClick, WheelUp, , , 1
    Sleep, 500
    ; But leave the rest below unchanged.
    if not KeepLWinRunning  ; The user signaled the loop to stop by pressing LWin again.
        break  ; Break out of this loop.
}
KeepLWinRunning := false  ; Reset in preparation for the next press of this hotkey.
return
The above code does auto scope, but as a side effect it sends many WheelUps when used. And I have to carefully pause the whole script at times to prevent it from interfering with other PC operations. I need a working code that is sleek.
Could you please help me on this?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: auto scope when aiming

15 Nov 2015, 03:18

Maybe this will give you an idea:

Code: Select all

~RButton::
    Send, {MButton}    
    keywait, RButton
    Send, {MButton}
return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: auto scope when aiming

16 Nov 2015, 06:05

Adjust HoldLength to the amount of time that you need to hold RButton for it to consider it a hold, not a click

Code: Select all

#SingleInstance force
HoldLength := 250

RButton::
	; On down event of RButton, wait for <HoldLength> ms before sending WheelUp
	SetTimer, DoScope, % -HoldLength	; The - is important! It means only fire once!
	return

RButton up::
	; If RButton is released before the DoScope timer fired, cancel firing of timer
	SetTimer, DoScope, Off
	return

; <HoldLength> ms elapsed while holding RButton - Send the WheelUp
DoScope:
	Send {WheelUp}
	return
[Edit] You may need to change RButton to ~RButton if you wish to preserve the normal function that RButton performs in the game.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: ReyAHK, Rohwedder and 72 guests