51 lines
1.2 KiB
Java
51 lines
1.2 KiB
Java
package eu.oskar3123.tapemouse;
|
|
|
|
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
|
|
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
|
|
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
|
|
import net.minecraft.client.util.InputUtil;
|
|
import net.minecraft.util.Identifier;
|
|
import org.lwjgl.glfw.GLFW;
|
|
|
|
class KeyBindingHandler
|
|
{
|
|
|
|
private FabricKeyBinding keyBinding = FabricKeyBinding.Builder.create(
|
|
new Identifier("tapemouse", "toggle"),
|
|
InputUtil.Type.KEYSYM,
|
|
GLFW.GLFW_KEY_F6,
|
|
"key.categories.tapemouse").build();
|
|
private boolean pressedLastTick = false;
|
|
|
|
KeyBindingHandler()
|
|
{
|
|
KeyBindingRegistry.INSTANCE.register(keyBinding);
|
|
ClientTickCallback.EVENT.register(e ->
|
|
{
|
|
if (keyBinding.isPressed() != pressedLastTick)
|
|
{
|
|
pressedLastTick = keyBinding.isPressed();
|
|
if (pressedLastTick)
|
|
{
|
|
onPress();
|
|
}
|
|
else
|
|
{
|
|
onRelease();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void onPress()
|
|
{
|
|
TapeMouse.toggle();
|
|
}
|
|
|
|
private void onRelease()
|
|
{
|
|
|
|
}
|
|
|
|
}
|