30
30
31
31
# Use #include <emscripten/dom_pk_codes.h> in your code to access these IDs.
32
32
33
+ import os
33
34
import sys
34
35
import random
35
36
@@ -276,8 +277,16 @@ def longest_key_code_length():
276
277
return max (map (len , [x [1 ] for x in input_strings ]))
277
278
278
279
279
- h_file = open ('system/include/emscripten/dom_pk_codes.h' , 'w' )
280
- c_file = open ('system/lib/html5/dom_pk_codes.c' , 'w' )
280
+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
281
+ root = os .path .dirname (os .path .dirname (script_dir ))
282
+
283
+ h_filename = os .path .join (root , 'system/include/emscripten/dom_pk_codes.h' )
284
+ c_filename = os .path .join (root , 'system/lib/html5/dom_pk_codes.c' )
285
+ print (f'Writing: { h_filename } ' )
286
+ print (f'Writing: { c_filename } ' )
287
+ h_file = open (h_filename , 'w' )
288
+ c_file = open (c_filename , 'w' )
289
+
281
290
282
291
# Generate the output file:
283
292
@@ -289,10 +298,10 @@ def longest_key_code_length():
289
298
* found in the LICENSE file.
290
299
*
291
300
* This file was automatically generated from script
292
- * tools/create_dom_pk_codes.py. Edit that file to make changes here.
293
- * Run
301
+ * tools/maint/ create_dom_pk_codes.py. Edit that file to make changes here.
302
+ * Then run:
294
303
*
295
- * tools/create_dom_pk_codes.py
304
+ * tools/maint/ create_dom_pk_codes.py
296
305
*
297
306
* in Emscripten root directory to regenerate this file.
298
307
*/
@@ -303,13 +312,16 @@ def longest_key_code_length():
303
312
304
313
''' )
305
314
306
- c_file .write ('''/* This file was automatically generated from script
307
- tools/create_dom_pk_codes.py. Edit that file to make changes here.
308
- Run
309
-
310
- python tools/create_dom_pk_codes.py
311
-
312
- in Emscripten root directory to regenerate this file. */
315
+ c_file .write ('''\
316
+ /*
317
+ * This file was automatically generated from script
318
+ * tools/maint/create_dom_pk_codes.py. Edit that file to make changes here.
319
+ * Then run:
320
+ *
321
+ * tools/maint/create_dom_pk_codes.py
322
+ *
323
+ * in Emscripten root directory to regenerate this file.
324
+ */
313
325
314
326
#include <emscripten/dom_pk_codes.h>
315
327
''' )
@@ -332,20 +344,20 @@ def longest_key_code_length():
332
344
''' )
333
345
334
346
c_file .write ('''
335
- DOM_PK_CODE_TYPE emscripten_compute_dom_pk_code(const char *keyCodeString)
336
- {
347
+ DOM_PK_CODE_TYPE emscripten_compute_dom_pk_code(const char *keyCodeString) {
337
348
if (!keyCodeString) return 0;
338
349
339
350
/* Compute the collision free hash. */
340
351
unsigned int hash = 0;
341
- while(*keyCodeString) hash = ((hash ^ 0x%04XU) << %d) ^ (unsigned int)*keyCodeString++;
342
-
343
- /* Don't expose the hash values out to the application, but map to fixed IDs. This is useful for
344
- mapping back codes to MDN documentation page at
345
-
346
- https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code */
347
- switch(hash)
348
- {
352
+ while (*keyCodeString) hash = ((hash ^ 0x%04XU) << %d) ^ (unsigned int)*keyCodeString++;
353
+
354
+ /*
355
+ * Don't expose the hash values out to the application, but map to fixed IDs.
356
+ * This is useful for mapping back codes to MDN documentation page at
357
+ *
358
+ * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code
359
+ */
360
+ switch (hash) {
349
361
''' % (k1 , k2 ))
350
362
351
363
for s in input_strings :
@@ -355,10 +367,8 @@ def longest_key_code_length():
355
367
}
356
368
}
357
369
358
- const char *emscripten_dom_pk_code_to_string(DOM_PK_CODE_TYPE code)
359
- {
360
- switch(code)
361
- {
370
+ const char *emscripten_dom_pk_code_to_string(DOM_PK_CODE_TYPE code) {
371
+ switch (code) {
362
372
''' )
363
373
364
374
for s in input_strings :
0 commit comments