NUI Detect Key Press

I’m using NUI with an event listener to detect which key is being pressed. However, only works when it is focused. While is it focused, control for the game is lost until focus is taken from NUI.

Is there any way to have the NUI script still work, but retain control of the game?

I’m trying to get a more straightforward way of binding keys. If anybody has any other ideas that would work, would be nice. Thanks

No. This is, again, intentional.

If I understood you right, you can just do this:

Bad stuff that you should not follow

of course you need to program a routine to display something… or let something happen when the key is pressed. Otherway nothing will work by itself. GTA is programmed like this. Every action key is calling a function.
When you press a key, you can do something like this:

GUI.time = 0
if( IsControlPressed(1, Keys["G"]) and (GetGameTimer() - GUI.time) > 1000 ) then
 blah blah blah
    GUI.time = GetGameTimer()
end

so the function is called only one time per second, if the key is focused…

I hope I understood you right and could help you.

Those aren’t ‘keys’ those are controls, meaning they can differ for every player and are different for each keyboard layout.

k, now some things make sense hahah

First I heard of it being intentional – I wasn’t sure. Haven’t seen it anywhere else.

Is there any “easy” (working) way to get the control ID from a keypress, just so we know what is assigned to what? Or is it just a trial and error sort of thing to figure it out? I’ve figured out a lot of the keys from using GET_CONTROL_INSTRUCTIONAL_BUTTON in a loop with the IDs, but only letter and number keys show up using this function. Keys like the arrows, insert, home, etc. I am clueless to. Any idea on how to grab those?

Because controls != keys, there are far less controls then keys.

Well yeah. That I know. I’ve seen some resources using arrow keys, though. I know every single key is not mapped. I’m just looking to get the controls/keys that are mapped, and that don’t happen to be a number or letter. Like the arrow keys. I have seen in somebody’s resource that the arrow keys are used, but how would I go about detecting those control IDs without simply sifting through everybody’s resources and hoping everything is there?

What about the phone keys? Like those are actual controls & are defaulted to the arrow keys.

How do I get the integer ID for the control though? Should I just loop through IsControlPressed() while increasing a variable by 1, or is there another way to get that ID?

I found a list with all the IDs: Displaying Help Text - Documentation - GTAForums

I have a QWERTY keyboard with default controls, and this is what I have managed to find with a lot of tedious loops.I got the instructional button and drew that to find each key. Anything with a t_# is simply that key. For example, t_V is V. Everything else was a bit different and I typed out what it actually is (for me at least).

[details=List of controls and their default key (Click)]> 0 :: t_V

1 :: b_112 - MOUSE R/L
2 :: b_113 - MOUSE U/D
3 :: b_110 - MOUSE UP
4 :: b_111 - MOUSE DOWN
5 :: b_108 - MOUSE LEFT
6 :: b_109 - MOUSE RIGHT
7 :: t_L
8 :: t_S%t_W
9 :: t_D%t_A
10 :: b_1009 - PG UP
11 :: b_1010 - PG DN
12 :: b_-1 - ???
13 :: b_-1 - ???
14 :: b_116 - MOUSE WHEEL DOWN
15 :: b_115 - MOUSE WHEEL UP
16 :: b_116 - MOUSE WHEEL DOWN
17 :: b_115 - MOUSE WHEEL UP
18 :: b_100 - L CLICK
19 :: b_1015 - LEFT ALT
20 :: t_Z
21 :: b_1000 - L SHIFT
22 :: b_2000 - SPACE
23 :: t_F
24 :: b_100 - LEFT CLICK
25 :: b_101 - RIGHT CLICK
26 :: t_C
27 :: b_194 - UP ARROW
28 :: b_995 - ???
29 :: t_B
30 :: t_D%t_A
31 :: t_S%t_W
32 :: t_W
33 :: t_S
34 :: t_A
35 :: t_D
36 :: b_1013 - L CTRL
37 :: b_1002 - TAB
38 :: t_E
39 :: b_117 - MOUSE WHEEL UP/DOWN
40 :: b_115 - MOUSE WHEEL UP
41 :: b_116 - MOUSE WHEEL DOWN
42 :: b_115 - MOUSE WHEEL UP
43 :: b_116 - MOUSE WHEEL DOWN
44 :: t_Q
45 :: t_R
46 :: t_E
47 :: t_G
48 :: t_Z
49 :: t_F
50 :: b_117 - MOUSE WHEEL UP/DOWN
51 :: t_E
52 :: t_Q
53 :: b_995 - ???
54 :: t_E
55 :: b_2000 - SPACE
56 :: b_178 - F9
57 :: b_179 - F10
58 :: t_G
59 :: t_D%t_A
60 :: b_1013%b_1000 - L SHIFT / L CTRL
61 :: b_1000 - L SHIFT
62 :: b_1013 - L CTRL
63 :: t_A
64 :: t_D
65 :: b_995 - ???
66 :: b_112 - MOUSE R/L
67 :: b_113 - MOUSE U/D
68 :: b_101 - R CLICK
69 :: b_100 - L CLICK
70 :: b_1014 - R CTRL
71 :: t_W
72 :: t_S
73 :: t_X
74 :: t_H
75 :: t_F
76 :: b_2000 - SPACE
77 :: t_W
78 :: t_S
79 :: t_C
80 :: t_R
81 :: t_.
82 :: t_,
83 :: t_=
84 :: t_-
85 :: t_Q
86 :: t_E
87 :: t_W
88 :: t_S
89 :: t_A
90 :: t_D
91 :: b_101 - R CLICK
92 :: b_100 - L CLICK
93 :: b_995 - ???
94 :: b_995 - ???
95 :: b_113 - MOUSE U/D
96 :: b_115 - MOUSE WHEEL UP
97 :: b_116 - MOUSE WHEEL DOWN
98 :: b_112 - MOUSE R/L
99 :: b_115 - MOUSE WHEEL UP
100 :: t_[
101 :: t_H
102 :: b_2000 - SPACE
103 :: t_E
104 :: t_H
105 :: t_X
106 :: b_100 - L CLICK
107 :: b_142%b_140 - NUM 4 / NUM 6
108 :: b_140 - NUM 4
109 :: b_142 - NUM 6
110 :: b_141%b_144 - NUM 8 / NUM 5
111 :: b_144 - NUM 8
112 :: b_141 - NUM 5
113 :: t_G
114 :: b_2000 - SPACE
115 :: b_115 - MOUSE WHEEL UP
116 :: t_[
117 :: b_143 - NUM 7
118 :: b_145 - NUM 9
119 :: t_E
120 :: t_X
121 :: b_200 - INSERT
122 :: b_100 - L CLICK
123 :: b_142%b_140 - NUM 4 / NUM 6
124 :: b_140 - NUM 4
125 :: b_142 - NUM 6
126 :: b_141%b_144 - NUM 8 / NUM 5
127 :: b_144 - NUM 8
128 :: b_141 - NUM 5
129 :: t_W
130 :: t_S
131 :: b_1000 - L SHIFT
132 :: b_1013 - L CTRL
133 :: t_A
134 :: t_D
135 :: b_100 - L CLICK
136 :: t_W
137 :: b_1012 - CAPS
138 :: t_Q
139 :: t_S
140 :: t_R
141 :: t_Q
142 :: b_100 - L CLICK
143 :: b_2000 - SPACE
144 :: b_100 - L CLICK
145 :: t_F
146 :: t_D%t_A
147 :: t_A
148 :: t_D
149 :: t_S%t_W
150 :: t_W
151 :: t_S
152 :: t_Q
153 :: t_E
154 :: t_X
155 :: b_1000 - L SHIFT
156 :: b_995 - ???
157 :: t_1
158 :: t_2
159 :: t_6
160 :: t_3
161 :: t_7
162 :: t_8
163 :: t_9
164 :: t_4
165 :: t_5
166 :: b_174 - F5
167 :: b_175 - F6
168 :: b_176 - F7
169 :: b_177 - F8
170 :: b_172 - F3
171 :: b_1012 - CAPS
172 :: b_194 - UP ARROW
173 :: b_195 - DOWN ARROW
174 :: b_196 - LEFT ARROW
175 :: b_197 - RIGHT ARROW
176 :: b_1003 - ENTER
177 :: b_1004 - BACKSPACE
178 :: b_198 - DEL
179 :: b_2000 - SPACE
180 :: b_116 - MOUSE WHEEL DOWN
181 :: b_115 - MOUSE WHEEL UP
182 :: t_L
183 :: t_G
184 :: b_102 - MIDDLE MOUSE
185 :: t_F
186 :: t_X
187 :: b_195 - DOWN ARROW
188 :: b_194 - UP ARROW
189 :: b_196 - LEFT ARROW
190 :: b_197 - RIGHT ARROW
191 :: b_1003 - ENTER
192 :: b_1002 - TAB
193 :: b_2000 - SPACE
194 :: b_1004 - BACKSPACE
195 :: t_D%t_A
196 :: t_S%t_W
197 :: t_]%t_[
198 :: b_117 - MOUSE WHEEL UP/DOWN
199 :: t_P
200 :: b_199 - ESC
201 :: b_1003 - ENTER
202 :: b_199 - BACKSPACE
203 :: b_2000 - SPACE
204 :: b_1002 - TAB
205 :: t_Q
206 :: t_E
207 :: b_1010 - PG DN
208 :: b_1009 - PG UP
209 :: b_1000 - L SHIFT
210 :: b_1013 - L CTRL
211 :: b_1002 - TAB
212 :: b_1008 - HOME
213 :: b_1008 - HOME
214 :: b_198 - DEL
215 :: b_1003 - ENTER
216 :: b_2000 - SPACE
217 :: b_1012 - CAPS
218 :: t_D%t_A
219 :: t_S%t_W
220 :: b_112 - MOUSE R/L
221 :: b_113 - MOUSE U/D
222 :: b_101 - R CLICK
223 :: b_100 - L CLICK
224 :: b_1013 - L CTRL
225 :: b_101 - R CLICK
226 :: b_995 - ???
227 :: b_995 - ???
228 :: b_995 - ???
229 :: b_100 - L CLICK
230 :: b_995 - ???
231 :: b_995 - ???
232 :: t_W
233 :: t_S
234 :: t_A
235 :: t_D
236 :: t_V
237 :: b_100 - L CLICK
238 :: b_101 - R CLICK
239 :: b_112 - MOUSE R/L
240 :: b_113 - MOUSE U/D
241 :: b_115 - MOUSE WHEEL UP - WHEEL UP
242 :: b_116 - MOUSE WHEEL DOWN - WHEEL DOWN
243 :: t_`
244 :: t_M
245 :: t_T
246 :: t_Y
247 :: b_995 - ???
248 :: b_995 - ???
249 :: t_N
250 :: t_R
251 :: t_F
252 :: t_X
253 :: t_C
254 :: b_1000 - L SHIFT
255 :: b_1003 - ENTER
256 :: b_198 - DEL
257 :: b_100 - L CLICK
258 :: b_995 - ???
259 :: b_995 - ???
260 :: b_995 - ???
261 :: b_995 - ???
262 :: b_995 - ???
263 :: b_995 - ???
264 :: b_995 - ???
265 :: b_995 - ???
266 :: b_995 - ???
267 :: b_995 - ???
268 :: b_995 - ???
269 :: b_995 - ???
270 :: b_995 - ???
271 :: b_995 - ???
272 :: b_995 - ???
273 :: b_995 - ???
274 :: b_995 - ???
275 :: b_995 - ???
276 :: b_995 - ???
277 :: b_995 - ???
278 :: b_995 - ???
279 :: b_995 - ???
280 :: b_995 - ???
281 :: b_995 - ???
282 :: b_995 - ???
283 :: b_995 - ???
284 :: b_995 - ???
285 :: b_995 - ???
286 :: b_995 - ???
287 :: b_995 - ???
288 :: b_170 - F1
289 :: b_171 - F2
290 :: b_112 - MOUSE R/L
291 :: b_113 - MOUSE U/D
292 :: b_110 - MOUSE UP
293 :: b_111 - MOUSE DOWN
294 :: b_108 - MOUSE LEFT
295 :: b_109 - MOUSE RIGHT
296 :: b_198 - DEL
297 :: b_198 - DEL
298 :: b_2000 - SPACE
299 :: b_195 - DOWN ARROW
300 :: b_194 - UP ARROW
301 :: t_M
302 :: t_S
303 :: t_U
304 :: t_H
305 :: t_B
306 :: t_N
307 :: b_197 - RIGHT ARROW
308 :: b_196 - LEFT ARROW
309 :: t_T
310 :: t_R
311 :: t_K
312 :: t_[
313 :: t_]
314 :: b_131 - NUM +
315 :: b_130 - NUM -
316 :: b_1009 - PG UP
317 :: b_1010 - PG DN
318 :: b_174 - F5
319 :: t_C
320 :: t_V
321 :: b_2000 - SPACE
322 :: b_199 - ESC
323 :: t_X
324 :: t_C
325 :: t_V
326 :: b_1013 - L CTRL
327 :: b_174 - F5
328 :: b_2000 - SPACE
329 :: b_100 - L CLICK
330 :: b_101 - R CLICK
331 :: b_2000 - SPACE
332 :: b_113 - MOUSE U/D
333 :: b_112 - MOUSE R/L
334 :: b_117 - MOUSE WHEEL UP/DOWN
335 :: b_115 - MOUSE WHEEL UP
336 :: b_116 - MOUSE WHEEL DOWN
337 :: t_X
338 :: t_A
339 :: t_D
340 :: b_1000 - L SHIFT
341 :: b_1013 - L CTRL
342 :: b_1013%b_1000 - L SHIFT / L CTRL
343 :: t_D%t_A
344 :: b_102 - MIDDLE MOUSE BUTTON
345 :: b_1002 - TAB[/details]

This is everything I have been needing, and hopefully it will help somebody else out as well.

3 Likes

Controls are NOT keys. They van always be changed. Also on a controller everything is different.

I am very much aware of this. That is why I explicitly stated it was with a QWERTY keyboard using default controls. I may have wrongly worded my post, but I do know everything can change.

Do note your users might not.

Indeed. That is certainly understood. I only intend on having a relatively small player base of friends and such. I’ve already been making sure they are all aware of the control “dilemma”. I also plan on using the instructional buttons just to make sure everybody knows what key is for them, although almost all (if not everybody) playing should have the same control setup as I do.

I do appreciate your input on this though.