A script that allows the mouse button 4 and 5 to cycle through the Hotbar grids in Minecraft?

Ask gaming related questions (AHK v1.1 and older)
Ascend910
Posts: 1
Joined: 22 Mar 2021, 22:23

A script that allows the mouse button 4 and 5 to cycle through the Hotbar grids in Minecraft?

Post by Ascend910 » 07 Jun 2023, 21:09

I have tried

Code: Select all

; Minecraft Hotbar Cycling Script
; Use Mouse Button 4 and 5 to cycle through hotbar slots

#IfWinActive Minecraft ; Only enable the script when Minecraft is active

$XButton1::
    HotbarCycle(-1) ; Cycle to the previous hotbar slot
    Return

$XButton2::
    HotbarCycle(1) ; Cycle to the next hotbar slot
    Return

HotbarCycle(direction) {
    ControlGetFocus, currentControl, MinecraftWindowClass1
    If (currentControl = "Edit1") ; Ignore if typing in chat
        Return

    activeSlot := GetActiveHotbarSlot()
    newSlot := Mod(activeSlot + direction - 1, 9) + 1

    SendInput, {%newSlot% down}{%newSlot% up}
}

GetActiveHotbarSlot() {
    ControlGetFocus, currentControl, MinecraftWindowClass1
    If (currentControl = "Edit1") ; If typing in chat, assume slot 1 is active
        Return 0
    Else {
        StringGetPos, slotNumber, currentControl, Slot
        Return SubStr(currentControl, slotNumber + 4, 1)
    }
}

#IfWinActive ; End context-sensitive Minecraft check
But it didn't work


[Mod action: Moved topic to v1 section since this v1 code. The main section is for v2.]

Return to “Gaming Help (v1)”