Skip to content

Commit 56bfa75

Browse files
committed
dont spam modules when keybind is held down
1 parent 8d1a72d commit 56bfa75

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.lambda.event.Event
2222
import com.lambda.util.KeyCode
2323
import org.lwjgl.glfw.GLFW.GLFW_PRESS
2424
import org.lwjgl.glfw.GLFW.GLFW_RELEASE
25+
import org.lwjgl.glfw.GLFW.GLFW_REPEAT
2526

2627
sealed class KeyboardEvent {
2728
/**
@@ -48,6 +49,7 @@ sealed class KeyboardEvent {
4849

4950
val isPressed = action >= GLFW_PRESS
5051
val isReleased = action == GLFW_RELEASE
52+
val isRepeated = action == GLFW_REPEAT
5153

5254
fun satisfies(bind: Bind) = bind.key == translated.code && bind.modifiers and modifiers == bind.modifiers
5355
}

src/main/kotlin/com/lambda/gui/components/QuickSearch.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import imgui.flag.ImGuiStyleVar
4040
import imgui.flag.ImGuiWindowFlags
4141
import imgui.type.ImString
4242
import net.minecraft.client.gui.screen.ChatScreen
43-
import org.lwjgl.glfw.GLFW
4443
import kotlin.math.max
4544

4645
// ToDo: Add support for searching of menu bar entries
@@ -304,7 +303,7 @@ object QuickSearch {
304303
}
305304

306305
private fun handleKeyPress(event: KeyboardEvent.Press) {
307-
if ((!event.isPressed || event.action == GLFW.GLFW_REPEAT) ||
306+
if ((!event.isPressed || event.isRepeated) ||
308307
!(event.keyCode == KeyCode.LeftShift.code || event.keyCode == KeyCode.RightShift.code)) return
309308

310309
val currentTime = System.currentTimeMillis()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ abstract class Module(
142142
|| Lambda.mc.currentScreen != null
143143
|| !event.satisfies(keybind)) return@listen
144144

145-
if (event.isPressed) toggle()
145+
if (event.isPressed && !event.isRepeated) toggle()
146146
else if (event.isReleased && disableOnRelease) disable()
147147
}
148148

0 commit comments

Comments
 (0)