Added multi key and mouse binds · lambda-client/lambda@cc19dbf · GitHub
Skip to content

Commit cc19dbf

Browse files
committed
Added multi key and mouse binds
1 parent 668b540 commit cc19dbf

7 files changed

Lines changed: 71 additions & 36 deletions

File tree

src/main/kotlin/com/lambda/config/settings/complex/KeybindSetting.kt

Lines changed: 46 additions & 20 deletions

src/main/kotlin/com/lambda/event/events/KeyboardEvent.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.event.events
1919

20+
import com.lambda.config.settings.complex.Bind
2021
import com.lambda.event.Event
2122
import com.lambda.util.KeyCode
2223
import org.lwjgl.glfw.GLFW.GLFW_MOD_ALT
@@ -54,6 +55,8 @@ sealed class KeyboardEvent {
5455
val isPressed = action == GLFW_PRESS
5556
val isReleased = action == GLFW_RELEASE
5657

58+
fun satisfies(bind: Bind) = bind.key == keyCode && bind.modifiers == modifiers
59+
5760
val hasShift = modifiers and GLFW_MOD_SHIFT != 0
5861
val hasControl = modifiers and GLFW_MOD_CONTROL != 0
5962
val hasAlt = modifiers and GLFW_MOD_ALT != 0

src/main/kotlin/com/lambda/event/events/MouseEvent.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.event.events
1919

20+
import com.lambda.config.settings.complex.Bind
2021
import com.lambda.event.callback.Cancellable
2122
import com.lambda.event.callback.ICancellable
2223
import com.lambda.util.Mouse
@@ -50,6 +51,8 @@ sealed class MouseEvent {
5051
position
5152
)
5253

54+
fun satisfies(bind: Bind) = bind.modifiers == modifiers && bind.mouse == button
55+
5356
val isMainButton = button <= 2
5457
val isSideButton = button > 2
5558
val isLeftButton = button == 0

src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.module
1919

20-
import com.lambda.Lambda.mc
20+
import com.lambda.Lambda
2121
import com.lambda.command.LambdaCommand
2222
import com.lambda.config.AbstractSetting
2323
import com.lambda.config.Configurable
@@ -135,13 +135,24 @@ abstract class Module(
135135

136136
init {
137137
listen<KeyboardEvent.Press>(alwaysListen = true) { event ->
138-
onButtonPress(event.keyCode, event.isPressed, event.isReleased)
138+
if (Lambda.mc.options.commandKey.isPressed
139+
|| Lambda.mc.currentScreen != null
140+
|| !event.satisfies(keybind)) return@listen
141+
142+
if (event.isPressed) toggle()
143+
else if (event.isReleased && disableOnRelease) disable()
139144
}
140145

141146
listen<MouseEvent.Click>(alwaysListen = true) { event ->
142147
val pressed = event.action == Mouse.Action.Click.ordinal
143148
val released = event.action == Mouse.Action.Release.ordinal
144-
onButtonPress(event.button, pressed, released)
149+
150+
if (mc.options.commandKey.isPressed
151+
|| mc.currentScreen != null
152+
|| !event.satisfies(keybind)) return@listen
153+
154+
if (pressed) toggle()
155+
else if (released && disableOnRelease) disable()
145156
}
146157

147158
onEnable { LambdaSound.MODULE_ON.play() }
@@ -155,14 +166,6 @@ abstract class Module(
155166
listen<ConnectionEvent.Disconnect> { if (autoDisable) disable() }
156167
}
157168

158-
private fun onButtonPress(code: Int, pressed: Boolean, released: Boolean) {
159-
if (mc.options.commandKey.isPressed) return
160-
if (mc.currentScreen != null) return
161-
if (code != keybind.code) return
162-
if (pressed) toggle()
163-
else if (released && disableOnRelease) disable()
164-
}
165-
166169
fun enable() {
167170
isEnabled = true
168171
}

src/main/kotlin/com/lambda/module/hud/ModuleList.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object ModuleList : HudModule(
3939

4040
enabled.forEach {
4141
text(it.name); sameLine()
42-
val color = if (it.keybind.code == KeyCode.UNBOUND.code) Color.RED else Color.GREEN
42+
val color = if (it.keybind.key == 0 && it.keybind.mouse == -1) Color.RED else Color.GREEN
4343

4444
withStyleColor(ImGuiCol.Text, color) { text(" [${it.keybind.name}]") }
4545
}

src/main/kotlin/com/lambda/util/Communication.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ object Communication {
179179
}
180180
literal("Keybind: ")
181181
color(ClickGuiLayout.primaryColor) {
182-
if (module.keybind.code != -1) {
183-
literal(module.keybind.code.toString())
182+
if (module.keybind.key != 0 || module.keybind.mouse > -1) {
183+
literal(module.keybind.name)
184184
} else {
185185
literal("Unbound")
186186
}

src/main/kotlin/com/lambda/util/InputUtils.kt

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)