Continous scroll wheel input (maybe a ffew hundred milliseconds)

Ask gaming related questions (AHK v1.1 and older)
justsda89
Posts: 3
Joined: 18 May 2024, 14:52

Continous scroll wheel input (maybe a ffew hundred milliseconds)

18 May 2024, 15:00

hi im struggling a lot with a macro for a game, it's very important that during the loop of the script, it accurately mimics the real life action of me scrolling the mouse wheel up for a few hundred milliseconds, while holding shift, however, i seemingly can only get the scrollwheel to be activated a single time (which makes sense as it's just calling WheelUp a single time) as opposed to continuously after the shift key is clicked. Current code snippet (part of code contained from recording software (inefficient but i'm just testing this, i've never used ahk before)

Code: Select all

Click, 1217, 462, 0 Send, {LShift Up}
Sleep, 15
Click, 1218, 461, 0
Sleep, 47
Click, WheelUp
Sleep, 47

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Rohwedder
Posts: 7735
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Continous scroll wheel input (maybe a ffew hundred milliseconds)

19 May 2024, 02:10

Hallo,
too little code to say anything, except: Send, {LShift Up} is not executed, see:

Code: Select all

#InstallKeybdHook
#InstallMouseHook

Click, 1217, 462, 0 Send, {LShift Up}
Sleep, 15
Click, 1218, 461, 0
Sleep, 47
Click, WheelUp
Sleep, 47

KeyHistory
perhaps?:

Code: Select all

*LShift::TimerOn("Continous_scroll_wheel_input", 200) ; every 200 ms
*LShift Up::TimerOff("Continous_scroll_wheel_input")

Continous_scroll_wheel_input:
Click, 1217, 462, 0
Sleep, 15
Click, 1218, 461, 0
Sleep, 47
Click, WheelUp
Return

TimerOn(Label, Period, Instantly := True ){
    Global
    If (%Label%)
        Return
    SetTimer,% Label,% %Label% := Period
    IF Instantly
        Gosub, %Label%
}
TimerOff(Label){
    SetTimer,% Label, Delete,% %Label% := False
}
justsda89
Posts: 3
Joined: 18 May 2024, 14:52

Re: Continous scroll wheel input (maybe a ffew hundred milliseconds)

19 May 2024, 10:56

Hi, you're correct, It was my mistake accidentally not putting the Send {Lshift Up} on the second line in this post. I will describe my intention with this code more in depth: I want to create an ahk program that does the same action over and over until I pause it, I don't want any user input, just a hardcoded script to do this.

Code: Select all

#Persistent  ; Keep the script running

toggle := false
paused := false

F12::  ; Toggle key
    toggle := !toggle
    if (toggle)
    {
        WinActivate, Minecraft* 1.20.4 - Singleplayer ahk_class GLFW30
        while (toggle)
        {
            if (paused)
            {
                Sleep, 100
                continue
            }
This is the current structure of my code, the part I need help with is what's in the while loop. My intention is as follows: move the mouse to a specific position, then press and hold the shift key and hold down the scroll wheel so that it delivers constant scrollwheel up input like a real person and not just a bunch of singular scrolls. Then the program moves the mouse, right clicks, moves again, left clicks, and that is the end of one while loop cycle. Everything works except the continuous LShift and WheelUp input, i found SetScrollLockState, but can't figure out how to use that to continuously scroll.

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
gregster
Posts: 9096
Joined: 30 Sep 2013, 06:48

Re: Continous scroll wheel input (maybe a ffew hundred milliseconds)

19 May 2024, 11:03

@justsda89, there seems to be some confusion about the application of code tags. In the post above, you just put square [ ] brackets around the code - which didn't do anything. I removed them and replaced them with code tags: [code]code goes here[/code]
This is one way how you can do it by using the full editor:

ctags.png
ctags.png (14.18 KiB) Viewed 441 times
Rohwedder
Posts: 7735
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Continous scroll wheel input (maybe a ffew hundred milliseconds)

20 May 2024, 01:24

I suggest the following structure:

Code: Select all

; #Persistent  ; not necessary as Hotkeys are in the script
toggle := false
paused := false

F12::SetTimer, Minecraft,% (toggle:=!toggle)?100:"Off" ;toggles: every 100 ms/off

Minecraft:
WinActivate, Minecraft* 1.20.4 - Singleplayer ahk_class GLFW30
if (paused)
	Return
...
hold down the scroll wheel so that it delivers constant scrollwheel up input like a real person and not just a bunch of singular scrolls
When you hold down the scroll wheel, a single MButton Click is sent, not multiple WheelUps!
The mouse does not autorepeat like the keyboard.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 48 guests