From 19231489adc73aa7aa41c89ff90eaff6d9dd7bd4 Mon Sep 17 00:00:00 2001 From: nea Date: Mon, 4 Sep 2023 16:28:00 +0200 Subject: Add chat peeking keybinding --- .../nea/firmament/keybindings/SavedKeyBinding.kt | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/main/kotlin/moe/nea/firmament/keybindings') diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt index e538ff0..ac73366 100644 --- a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt @@ -6,11 +6,11 @@ package moe.nea.firmament.keybindings -import org.lwjgl.glfw.GLFW import kotlinx.serialization.Serializable +import moe.nea.firmament.util.MC import net.minecraft.client.MinecraftClient import net.minecraft.client.util.InputUtil -import moe.nea.firmament.util.MC +import org.lwjgl.glfw.GLFW @Serializable data class SavedKeyBinding( @@ -38,24 +38,28 @@ data class SavedKeyBinding( } } - fun isPressed(): Boolean { + fun isPressed(atLeast: Boolean = false): Boolean { if (this.keyCode == GLFW.GLFW_KEY_UNKNOWN) return false val h = MC.window.handle if (!InputUtil.isKeyPressed(h, keyCode)) return false val ctrl = if (MinecraftClient.IS_SYSTEM_MAC) { InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) } else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT) val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) + if (atLeast) + return (ctrl >= this.ctrl) && + (alt >= this.alt) && + (shift >= this.shift) return (ctrl == this.ctrl) && - (alt == this.alt) && - (shift == this.shift) + (alt == this.alt) && + (shift == this.shift) } override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { -- cgit