aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-19 09:50:51 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-19 09:50:51 +0200
commit3c9a36985344f748628c763c1898452727a8d4cc (patch)
treec771709386134a3ca2bc4be2d1934211a0efbfcd /src/main/java/at/hannibal2/skyhanni/utils
parent454c1e59167851b40b9d7a6fccd75d7bedcf194c (diff)
downloadskyhanni-3c9a36985344f748628c763c1898452727a8d4cc.tar.gz
skyhanni-3c9a36985344f748628c763c1898452727a8d4cc.tar.bz2
skyhanni-3c9a36985344f748628c763c1898452727a8d4cc.zip
Replacing Keyboard.isKeyDown and KeybindHelper.isKeyDown with OSUtils.isKeyHeld
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt15
2 files changed, 18 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 71dfb1edb..4641c566c 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -267,9 +267,9 @@ object LorenzUtils {
}
}
- fun isShiftKeyDown() = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)
+ fun isShiftKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LSHIFT) || OSUtils.isKeyHeld(Keyboard.KEY_RSHIFT)
- fun isControlKeyDown() = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)
+ fun isControlKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LCONTROL) || OSUtils.isKeyHeld(Keyboard.KEY_RCONTROL)
// MoulConfig is in Java, I don't want to downgrade this logic
fun <T> onChange(vararg properties: Property<out T>, observer: Observer<T>) {
@@ -409,8 +409,8 @@ object LorenzUtils {
val tileSign = (this as AccessorGuiEditSign).tileSign
return (tileSign.signText[1].unformattedText.removeColor() == "^^^^^^"
- && tileSign.signText[2].unformattedText.removeColor() == "Set your"
- && tileSign.signText[3].unformattedText.removeColor() == "speed cap!")
+ && tileSign.signText[2].unformattedText.removeColor() == "Set your"
+ && tileSign.signText[3].unformattedText.removeColor() == "speed cap!")
}
fun inIsland(island: IslandType) = inSkyBlock && skyBlockIsland == island
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
index 254d8ad09..981ea87c3 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
@@ -1,7 +1,9 @@
package at.hannibal2.skyhanni.utils
+import io.github.moulberry.moulconfig.internal.KeybindHelper
import net.minecraft.client.settings.KeyBinding
import org.lwjgl.input.Keyboard
+import org.lwjgl.input.Mouse
import java.awt.Desktop
import java.io.IOException
import java.net.URI
@@ -32,7 +34,7 @@ object OSUtils {
fun KeyBinding.isActive(): Boolean {
if (!Keyboard.isCreated()) return false
try {
- if (Keyboard.isKeyDown(this.keyCode)) return true
+ if (isKeyHeld(keyCode)) return true
} catch (e: IndexOutOfBoundsException) {
println("KeyBinding isActive caused an IndexOutOfBoundsException with keyCode: $keyCode")
e.printStackTrace()
@@ -40,4 +42,15 @@ object OSUtils {
}
return this.isKeyDown || this.isPressed
}
+
+ fun isKeyHeld(keyCode: Int): Boolean {
+ if (keyCode == 0) return false
+ return if (keyCode < 0) {
+ Mouse.isButtonDown(keyCode + 100)
+ } else {
+ KeybindHelper.isKeyDown(keyCode)
+ }
+ }
+
+ fun getKeyName(keyCode: Int): String = KeybindHelper.getKeyName(keyCode)
}