Skip to content

Instantly share code, notes, and snippets.

@hfsaito
Created October 26, 2024 20:52
Show Gist options
  • Save hfsaito/153afdfcf5f4ae8709823538bfa735d3 to your computer and use it in GitHub Desktop.
Save hfsaito/153afdfcf5f4ae8709823538bfa735d3 to your computer and use it in GitHub Desktop.
#Requires AutoHotkey v2.0
class MouseToggler {
__New() {
this.left_state := false
this.right_state := false
}
Left() {
If this.left_state := !this.left_state
Click 'Down'
Else
Click 'Up'
}
Right() {
If this.right_state := !this.right_state
Click 'Down Right'
Else
Click 'Up Right'
}
}
class BoosterOpener {
static STATES := {
PICKING: 1,
POSITIONING: 2,
OPENING: 3,
END: 4,
}
static INTERVALS := {
PICKING: 20,
POSITIONING: 8,
OPENING: 300,
END: 0,
}
__New() {
this.toggler := false
this.state := BoosterOpener.STATES.END
this.tick_count := 0
SetTimer(ObjBindMethod(this, "Tick"), 100)
}
Toggle() {
this.toggler := !this.toggler
this.SetState(BoosterOpener.STATES.END)
}
SetState(new_state) {
if (this.state = new_state)
return
switch this.state {
case BoosterOpener.STATES.PICKING:
Click 'Up Right'
; case BoosterOpener.STATES.POSITIONING:
case BoosterOpener.STATES.OPENING:
Click 'Up'
; case BoosterOpener.STATES.END:
}
switch new_state {
case BoosterOpener.STATES.PICKING:
Click 'Down Right'
case BoosterOpener.STATES.POSITIONING:
Send 'r'
case BoosterOpener.STATES.OPENING:
Click 'Down'
; case BoosterOpener.STATES.END:
}
this.state := new_state
this.tick_count := 0
}
Tick() {
if (!this.toggler) {
return
}
switch this.state {
case BoosterOpener.STATES.PICKING:
if (this.tick_count >= BoosterOpener.INTERVALS.PICKING) {
this.SetState(BoosterOpener.STATES.POSITIONING)
}
case BoosterOpener.STATES.POSITIONING:
if (this.tick_count >= BoosterOpener.INTERVALS.POSITIONING) {
this.SetState(BoosterOpener.STATES.OPENING)
}
case BoosterOpener.STATES.OPENING:
if (this.tick_count >= BoosterOpener.INTERVALS.OPENING) {
this.SetState(BoosterOpener.STATES.END)
}
case BoosterOpener.STATES.END:
if (this.tick_count >= BoosterOpener.INTERVALS.END) {
this.SetState(BoosterOpener.STATES.PICKING)
}
}
this.tick_count++
}
}
mouse_toggler := MouseToggler()
booster_opener := BoosterOpener()
F2::mouse_toggler.Left()
F3::mouse_toggler.Right()
F5::booster_opener.Toggle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment