Skip to content

Instantly share code, notes, and snippets.

@Jonty800
Created April 7, 2014 21:13
Show Gist options
  • Save Jonty800/10057453 to your computer and use it in GitHub Desktop.
Save Jonty800/10057453 to your computer and use it in GitHub Desktop.
hotkey prototype lwjgl
if (this.currentScreen == null) {
for (int j = 0; j < this.hotKeys.size(); j++) {
// check through all stored hotkeys
HotKeyData hkData = this.hotKeys.get(j);
String label = hkData.label;
String action = hkData.action;
int keyCode = hkData.keyCode;
byte keyMods = hkData.keyMods;
List < Integer > heldKeys = new ArrayList < Integer > ();
if ((keyMods & 1) != 0) heldKeys.add(29); // ctrl (left)
if ((keyMods & 2) != 0) heldKeys.add(42); // shift (left)
if ((keyMods & 4) != 0) heldKeys.add(56); //alt (left)
// Check if the key(s) are pressed
if (Keyboard.getEventKey() == keyCode) {
boolean canSendHotkey = true;
for (int k = 0; k < heldKeys.size(); k++) {
if (!Keyboard.isKeyDown(heldKeys.get(k)))
canSendHotkey = false;
}
if (action.endsWith("\n")) {
// check whether to send message or open window
this.hud.addChat("Sending HotKey: " + label);
action = action.replace("\n", "");
this.networkManager.netHandler.send(PacketType.CHAT_MESSAGE,
new Object[] {
Integer.valueOf(-1), action
});
} else {
// open window
this.hud.addChat("Opening HotKey: " + label);
ChatInputScreenExtension cisExt = new ChatInputScreenExtension();
cisExt.inputLine = action;
this.setCurrentScreen(cisExt);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment