aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/util/sys/KeyboardUtils.java
blob: 9c8b471ff6932c765674115233d7373b8c0d463c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package gtPlusPlus.core.util.sys;

import net.minecraft.client.Minecraft;

import org.lwjgl.input.Keyboard;

public class KeyboardUtils {

    public static boolean isCtrlKeyDown() {
        try {
            if (!Keyboard.isCreated()) {
                return false;
            }
            // prioritize CONTROL, but allow OPTION as well on Mac (note: GuiScreen's isCtrlKeyDown only checks for the
            // OPTION key on Mac)
            boolean isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)
                || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
            if (!isCtrlKeyDown && Minecraft.isRunningOnMac)
                isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA);

            return isCtrlKeyDown;
        } catch (Throwable t) {
            return false;
        }
    }

    public static boolean isShiftKeyDown() {
        try {
            if (!Keyboard.isCreated()) {
                return false;
            }
            return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
        } catch (Throwable t) {
            return false;
        }
    }
}