mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-23 10:31:24 -08:00
69 lines
1.9 KiB
Java
69 lines
1.9 KiB
Java
package dev.slimevr.gui;
|
|
|
|
import com.melloware.jintellitype.HotkeyListener;
|
|
import com.melloware.jintellitype.JIntellitype;
|
|
import dev.slimevr.VRServer;
|
|
import dev.slimevr.config.KeybindingsConfig;
|
|
import io.eiren.util.OperatingSystem;
|
|
import io.eiren.util.ann.AWTThread;
|
|
import io.eiren.util.logging.LogManager;
|
|
|
|
|
|
public class Keybinding implements HotkeyListener {
|
|
private static final int RESET = 1;
|
|
private static final int QUICK_RESET = 2;
|
|
public final VRServer server;
|
|
|
|
|
|
public final KeybindingsConfig config;
|
|
|
|
@AWTThread
|
|
public Keybinding(VRServer server) {
|
|
this.server = server;
|
|
|
|
this.config = server.getConfigManager().getVrConfig().getKeybindings();
|
|
|
|
if (OperatingSystem.getCurrentPlatform() != OperatingSystem.WINDOWS) {
|
|
LogManager
|
|
.info(
|
|
"[Keybinding] Currently only supported on Windows. Keybindings will be disabled."
|
|
);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
if (JIntellitype.getInstance() instanceof JIntellitype) {
|
|
JIntellitype.getInstance().addHotKeyListener(this);
|
|
|
|
String resetBinding = this.config.getResetBinding();
|
|
JIntellitype.getInstance().registerHotKey(RESET, resetBinding);
|
|
LogManager.info("[Keybinding] Bound reset to " + resetBinding);
|
|
|
|
String quickResetBinding = this.config.getQuickResetBinding();
|
|
JIntellitype.getInstance().registerHotKey(QUICK_RESET, quickResetBinding);
|
|
LogManager.info("[Keybinding] Bound quick reset to " + quickResetBinding);
|
|
}
|
|
} catch (Throwable e) {
|
|
LogManager
|
|
.info(
|
|
"[Keybinding] JIntellitype initialization failed. Keybindings will be disabled. Try restarting your computer."
|
|
);
|
|
}
|
|
}
|
|
|
|
@AWTThread
|
|
@Override
|
|
public void onHotKey(int identifier) {
|
|
switch (identifier) {
|
|
case RESET:
|
|
LogManager.info("[Keybinding] Reset pressed");
|
|
server.resetTrackers();
|
|
break;
|
|
case QUICK_RESET:
|
|
LogManager.info("[Keybinding] Quick reset pressed");
|
|
server.resetTrackersYaw();
|
|
break;
|
|
}
|
|
}
|
|
}
|