Slick input keys

I’m making a chat and i need to catch the Questionmark key (?), however i can’t figure out how to do that, since i can’t find it in Slicks keylist.
The list is attached below.


    public static final int ANY_CONTROLLER = -1;
    private static final int MAX_BUTTONS = 100;
    public static final int KEY_ESCAPE = 1;
    public static final int KEY_1 = 2;
    public static final int KEY_2 = 3;
    public static final int KEY_3 = 4;
    public static final int KEY_4 = 5;
    public static final int KEY_5 = 6;
    public static final int KEY_6 = 7;
    public static final int KEY_7 = 8;
    public static final int KEY_8 = 9;
    public static final int KEY_9 = 10;
    public static final int KEY_0 = 11;
    public static final int KEY_MINUS = 12;
    public static final int KEY_EQUALS = 13;
    public static final int KEY_BACK = 14;
    public static final int KEY_TAB = 15;
    public static final int KEY_Q = 16;
    public static final int KEY_W = 17;
    public static final int KEY_E = 18;
    public static final int KEY_R = 19;
    public static final int KEY_T = 20;
    public static final int KEY_Y = 21;
    public static final int KEY_U = 22;
    public static final int KEY_I = 23;
    public static final int KEY_O = 24;
    public static final int KEY_P = 25;
    public static final int KEY_LBRACKET = 26;
    public static final int KEY_RBRACKET = 27;
    public static final int KEY_RETURN = 28;
    public static final int KEY_ENTER = 28;
    public static final int KEY_LCONTROL = 29;
    public static final int KEY_A = 30;
    public static final int KEY_S = 31;
    public static final int KEY_D = 32;
    public static final int KEY_F = 33;
    public static final int KEY_G = 34;
    public static final int KEY_H = 35;
    public static final int KEY_J = 36;
    public static final int KEY_K = 37;
    public static final int KEY_L = 38;
    public static final int KEY_SEMICOLON = 39;
    public static final int KEY_APOSTROPHE = 40;
    public static final int KEY_GRAVE = 41;
    public static final int KEY_LSHIFT = 42;
    public static final int KEY_BACKSLASH = 43;
    public static final int KEY_Z = 44;
    public static final int KEY_X = 45;
    public static final int KEY_C = 46;
    public static final int KEY_V = 47;
    public static final int KEY_B = 48;
    public static final int KEY_N = 49;
    public static final int KEY_M = 50;
    public static final int KEY_COMMA = 51;
    public static final int KEY_PERIOD = 52;
    public static final int KEY_SLASH = 53;
    public static final int KEY_RSHIFT = 54;
    public static final int KEY_MULTIPLY = 55;
    public static final int KEY_LMENU = 56;
    public static final int KEY_SPACE = 57;
    public static final int KEY_CAPITAL = 58;
    public static final int KEY_F1 = 59;
    public static final int KEY_F2 = 60;
    public static final int KEY_F3 = 61;
    public static final int KEY_F4 = 62;
    public static final int KEY_F5 = 63;
    public static final int KEY_F6 = 64;
    public static final int KEY_F7 = 65;
    public static final int KEY_F8 = 66;
    public static final int KEY_F9 = 67;
    public static final int KEY_F10 = 68;
    public static final int KEY_NUMLOCK = 69;
    public static final int KEY_SCROLL = 70;
    public static final int KEY_NUMPAD7 = 71;
    public static final int KEY_NUMPAD8 = 72;
    public static final int KEY_NUMPAD9 = 73;
    public static final int KEY_SUBTRACT = 74;
    public static final int KEY_NUMPAD4 = 75;
    public static final int KEY_NUMPAD5 = 76;
    public static final int KEY_NUMPAD6 = 77;
    public static final int KEY_ADD = 78;
    public static final int KEY_NUMPAD1 = 79;
    public static final int KEY_NUMPAD2 = 80;
    public static final int KEY_NUMPAD3 = 81;
    public static final int KEY_NUMPAD0 = 82;
    public static final int KEY_DECIMAL = 83;
    public static final int KEY_F11 = 87;
    public static final int KEY_F12 = 88;
    public static final int KEY_F13 = 100;
    public static final int KEY_F14 = 101;
    public static final int KEY_F15 = 102;
    public static final int KEY_KANA = 112;
    public static final int KEY_CONVERT = 121;
    public static final int KEY_NOCONVERT = 123;
    public static final int KEY_YEN = 125;
    public static final int KEY_NUMPADEQUALS = 141;
    public static final int KEY_CIRCUMFLEX = 144;
    public static final int KEY_AT = 145;
    public static final int KEY_COLON = 146;
    public static final int KEY_UNDERLINE = 147;
    public static final int KEY_KANJI = 148;
    public static final int KEY_STOP = 149;
    public static final int KEY_AX = 150;
    public static final int KEY_UNLABELED = 151;
    public static final int KEY_NUMPADENTER = 156;
    public static final int KEY_RCONTROL = 157;
    public static final int KEY_NUMPADCOMMA = 179;
    public static final int KEY_DIVIDE = 181;
    public static final int KEY_SYSRQ = 183;
    public static final int KEY_RMENU = 184;
    public static final int KEY_PAUSE = 197;
    public static final int KEY_HOME = 199;
    public static final int KEY_UP = 200;
    public static final int KEY_PRIOR = 201;
    public static final int KEY_LEFT = 203;
    public static final int KEY_RIGHT = 205;
    public static final int KEY_END = 207;
    public static final int KEY_DOWN = 208;
    public static final int KEY_NEXT = 209;
    public static final int KEY_INSERT = 210;
    public static final int KEY_DELETE = 211;
    public static final int KEY_LWIN = 219;
    public static final int KEY_RWIN = 220;
    public static final int KEY_APPS = 221;
    public static final int KEY_POWER = 222;
    public static final int KEY_SLEEP = 223;
    public static final int KEY_LALT = 56;
    public static final int KEY_RALT = 184;
    private static final int LEFT = 0;
    private static final int RIGHT = 1;
    private static final int UP = 2;
    private static final int DOWN = 3;
    private static final int BUTTON1 = 4;
    private static final int BUTTON2 = 5;
    private static final int BUTTON3 = 6;
    private static final int BUTTON4 = 7;
    private static final int BUTTON5 = 8;
    private static final int BUTTON6 = 9;
    private static final int BUTTON7 = 10;
    private static final int BUTTON8 = 11;
    private static final int BUTTON9 = 12;
    private static final int BUTTON10 = 13;
    public static final int MOUSE_LEFT_BUTTON = 0;
    public static final int MOUSE_RIGHT_BUTTON = 1;
    public static final int MOUSE_MIDDLE_BUTTON = 2;
    private static boolean controllersInited;
    private static ArrayList controllers;
    private int lastMouseX;
    private int lastMouseY;
    protected boolean[] mousePressed;
    private boolean[][] controllerPressed;
    protected char[] keys;
    protected boolean[] pressed;
    protected long[] nextRepeat;
    private boolean[][] controls;
    protected boolean consumed;
    protected HashSet allListeners;
    protected ArrayList keyListeners;
    protected ArrayList keyListenersToAdd;
    protected ArrayList mouseListeners;
    protected ArrayList mouseListenersToAdd;
    protected ArrayList controllerListeners;
    private int wheel;
    private int height;
    private boolean displayActive;
    private boolean keyRepeat;
    private int keyRepeatInitial;
    private int keyRepeatInterval;
    private boolean paused;
    private float scaleX;
    private float scaleY;
    private float xoffset;
    private float yoffset;
    private int doubleClickDelay;
    private long doubleClickTimeout;
    private int clickX;
    private int clickY;
    private int clickButton;
    private int pressedX;
    private int pressedY;
    private int mouseClickTolerance;

Override keyPressed(int, char) in BasicGame or BasicGameState and check the char value against ‘?’.

What davedes said, check the char value in keyPressed. Reason for this is on most keyboards, question mark is a shifted key – the integer codes are for unshifted keys. You could check for KEY_SLASH and shift being down, but that is extremely not recommended, since it’ll break on many non-US keyboards.

How is that actually implemented? I’m really new to Java :slight_smile:
Currently i’m the need of these characters which doesn’t exist by default in Slick:

! ? Æ Ø Å æ ø å

The first two, no problem. The rest … I don’t know how slick deals with the encoding involved, or if it does at all. You could try checking the char value in keyPressed the same as suggested before, perhaps print it to stdout.

There must be a way to get those characters from the keyboard to a string in the render method. No-one knows how to achieve that?

Most people here are probably not using Slick2D.

Seeing as Slick has its Input class already made and keys premade, Im not sure. If you were going to use just LWJGL Keyboard class and create the InputHandler class yourself, it would be easy.

Well, since Slick is built on LWJGL, wouldn’t it be possible to implement that in some way?

the Input class gets passed around inside the update method yeah?


public void update(GameContainer gc, /*What ever the rest is */)

If it is being passed around inside the update method you would have to modify the premade InputHandler class

I guess it does.
Render method:


    public void render(GameContainer gc, Graphics g) throws SlickException {

Update method:


    public void update(GameContainer gc, int delta) throws SlickException {
        Input input = gc.getInput();

Dont think you can, you would need to create your own InputHandler class I think.

I kind of figured, but that doesn’t help me any further :stuck_out_tongue:

This did the trick.


    @Override
    public void keyPressed(int key, char c) {
        if (c == 'Æ') {
            tekst += "Æ";
        } else if (c == 'æ') {
            tekst += "æ";
        }
    }

Closed

It’s good practice to use the unicode character escape codes rather than embedding the characters themselves in your source files; so that your source files make sense to people not using ISO 8859-1 or UTF-8.

In your case that’d be ‘\u00C6’ and ‘\u00E6’ respectively.