Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Slick input keys  (Read 2353 times)
0 Members and 1 Guest are viewing this topic.
Offline Reck

Senior Newbie





« Posted 2012-12-05 08:51:17 »

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.

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  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
    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;
Offline davedes
« Reply #1 - Posted 2012-12-05 17:43:43 »

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

Offline sproingie

JGO Kernel


Medals: 201



« Reply #2 - Posted 2012-12-05 20:41:05 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Reck

Senior Newbie





« Reply #3 - Posted 2012-12-05 20:46:53 »

How is that actually implemented? I'm really new to Java :-)
Currently i'm the need of these characters which doesn't exist by default in Slick:
1  
! ? Æ Ø Å æ ø å
Offline sproingie

JGO Kernel


Medals: 201



« Reply #4 - Posted 2012-12-05 20:53:08 »

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.


Offline Reck

Senior Newbie





« Reply #5 - Posted 2012-12-05 21:50:33 »

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?
Offline Phased
« Reply #6 - Posted 2012-12-05 22:16:24 »

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.
Offline Reck

Senior Newbie





« Reply #7 - Posted 2012-12-05 22:23:36 »

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?
Offline Phased
« Reply #8 - Posted 2012-12-05 22:26:58 »

the Input class gets passed around inside the update method yeah?
1  
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
Offline Reck

Senior Newbie





« Reply #9 - Posted 2012-12-05 22:32:45 »

I guess it does.
Render method:
1  
    public void render(GameContainer gc, Graphics g) throws SlickException {


Update method:
1  
2  
    public void update(GameContainer gc, int delta) throws SlickException {
        Input input = gc.getInput();
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Phased
« Reply #10 - Posted 2012-12-05 22:34:12 »

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

Senior Newbie





« Reply #11 - Posted 2012-12-05 22:37:17 »

I kind of figured, but that doesn't help me any further :-P
Offline Reck

Senior Newbie





« Reply #12 - Posted 2012-12-05 22:44:34 »

This did the trick.

1  
2  
3  
4  
5  
6  
7  
8  
    @Override
    public void keyPressed(int key, char c) {
        if (c == 'Æ') {
            tekst += "Æ";
        } else if (c == 'æ') {
            tekst += "æ";
        }
    }


Closed
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #13 - Posted 2012-12-06 00:12:25 »

This did the trick.

1  
2  
3  
4  
5  
6  
7  
8  
    @Override
    public void keyPressed(int key, char c) {
        if (c == 'Æ') {
            tekst += "Æ";
        } else if (c == 'æ') {
            tekst += "æ";
        }
    }


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.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (17 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!