Merge pull request #57 from uefibootkit/master

Fixed Bind system doesn't detect mouse keys
This commit is contained in:
cattyn
2026-03-29 15:11:42 +03:00
committed by GitHub
4 changed files with 35 additions and 13 deletions
@@ -44,7 +44,12 @@ public class BindButton
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
if (this.isHovering(mouseX, mouseY)) {
if (this.isListening) {
if (mouseButton != 0 && mouseButton != 1) {
this.setting.setValue(new Bind(-mouseButton - 2));
this.onMouseClick();
}
} else if (this.isHovering(mouseX, mouseY)) {
mc.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1f));
}
}
@@ -28,17 +28,19 @@ public class Bind implements Util {
}
public boolean isEmpty() {
return this.key < 0;
return this.key == -1;
}
public String toString() {
return this.isEmpty() ? "None" : (this.key < 0
? "None"
: this.capitalise(InputConstants.getKey(new KeyEvent(this.key, 0, 0)).getName()));
if (this.isEmpty()) return "None";
if (this.key < -1) return "Mouse " + (-this.key - 1);
return this.capitalise(InputConstants.getKey(new KeyEvent(this.key, 0, 0)).getName());
}
public boolean isDown() {
return !this.isEmpty() && GLFW.glfwGetKey(mc.getWindow().handle(), this.getKey()) == 1;
if (this.isEmpty()) return false;
if (this.key < -1) return GLFW.glfwGetMouseButton(mc.getWindow().handle(), -this.key - 2) == 1;
return GLFW.glfwGetKey(mc.getWindow().handle(), this.getKey()) == 1;
}
private String capitalise(String str) {
@@ -56,18 +58,19 @@ public class Bind implements Util {
public Bind doBackward(JsonElement jsonElement) {
String s = jsonElement.getAsString();
if (s.equalsIgnoreCase("None")) {
return Bind.none();
if (s.equalsIgnoreCase("None")) return Bind.none();
if (s.toLowerCase().startsWith("mouse ")) {
try {
return new Bind(-Integer.parseInt(s.substring(6)) - 1);
} catch (Exception e) {
}
}
int key = -1;
try {
key = InputConstants.getKey(s.toUpperCase()).getValue();
} catch (Exception exception) {
// empty catch block
}
if (key == 0) {
return Bind.none();
} catch (Exception e) {
}
if (key == 0) return Bind.none();
return new Bind(key);
}
}
@@ -6,6 +6,7 @@ import me.alpha432.oyvey.event.impl.entity.DeathEvent;
import me.alpha432.oyvey.event.impl.entity.player.TickEvent;
import me.alpha432.oyvey.event.impl.entity.player.UpdateWalkingPlayerEvent;
import me.alpha432.oyvey.event.impl.input.KeyInputEvent;
import me.alpha432.oyvey.event.impl.input.MouseInputEvent;
import me.alpha432.oyvey.event.impl.network.ChatEvent;
import me.alpha432.oyvey.event.impl.network.PacketEvent;
import me.alpha432.oyvey.event.impl.render.Render2DEvent;
@@ -80,6 +81,13 @@ public class EventManager extends Feature {
OyVey.moduleManager.onKeyPressed(event.getKey());
}
@Subscribe
public void onMouseInput(MouseInputEvent event) {
if (event.getAction() == 1) {
OyVey.moduleManager.onMouseClicked(event.getButton());
}
}
@Subscribe
public void onChatSent(ChatEvent event) {
String message = event.getMessage();
@@ -122,6 +122,12 @@ public class ModuleManager implements Jsonable, Util {
stream().filter(module -> module.getBind().getKey() == key).forEach(Module::toggle);
}
public void onMouseClicked(int button) {
if (mc.screen != null) return;
int key = -button - 2;
stream().filter(module -> module.getBind().getKey() == key).forEach(Module::toggle);
}
@Override
public JsonElement toJson() {
JsonObject object = new JsonObject();