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
[Mod action: Moved topic to v1 section since this v1 code. The main section is for v2.]