Skip to content

Commit

Permalink
Fix: GUI Editor + GUI Search (hannibal002#3226)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
Co-authored-by: CalMWolfs <[email protected]>
  • Loading branch information
3 people authored and DavidArthurCole committed Jan 18, 2025
1 parent 9ab1602 commit 177e856
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/model/TextInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ open class TextInput {
companion object {
private var activeInstance: TextInput? = null

fun isActive() = activeInstance != null

fun activate(instance: TextInput) {
activeInstance = instance
timeSinceKeyEvent = Keyboard.getEventNanoseconds()
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.data.model.TextInput
import at.hannibal2.skyhanni.events.GuiKeyPressEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.minecraft.KeyPressEvent
Expand All @@ -16,6 +17,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.apache.commons.lang3.SystemUtils
import org.lwjgl.input.Keyboard
import org.lwjgl.input.Mouse
import kotlin.time.Duration.Companion.milliseconds

@SkyHanniModule
object KeyboardManager {
Expand Down Expand Up @@ -71,29 +73,35 @@ object KeyboardManager {

if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1) {
val key = Mouse.getEventButton() - 100
KeyPressEvent(key).post()
postEvent(key)
lastClickedMouseButton = key
return
}

if (Keyboard.getEventKeyState() && Keyboard.getEventKey() != 0) {
val key = Keyboard.getEventKey()
KeyPressEvent(key).post()
postEvent(Keyboard.getEventKey())
lastClickedMouseButton = -1
return
}

if (Mouse.getEventButton() == -1 && lastClickedMouseButton != -1) {
if (lastClickedMouseButton.isKeyHeld()) {
KeyPressEvent(lastClickedMouseButton).post()
postEvent(lastClickedMouseButton)
return
}
lastClickedMouseButton = -1
}

// This is needed because of other keyboards that don't have a key code for the key, but is read as a character
if (Keyboard.getEventKey() == 0) {
KeyPressEvent(Keyboard.getEventCharacter().code + 256).post()
postEvent(Keyboard.getEventCharacter().code + 256)
}
}

private fun postEvent(keyCode: Int) {
DelayedRun.runDelayed(150.milliseconds) {
if (TextInput.isActive()) return@runDelayed
KeyPressEvent(keyCode).post()
}
}

Expand Down

0 comments on commit 177e856

Please sign in to comment.