3030
3131# Use #include <emscripten/dom_pk_codes.h> in your code to access these IDs.
3232
33+ import os
3334import sys
3435import random
3536
@@ -276,8 +277,16 @@ def longest_key_code_length():
276277 return max (map (len , [x [1 ] for x in input_strings ]))
277278
278279
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+
281290
282291# Generate the output file:
283292
@@ -289,10 +298,10 @@ def longest_key_code_length():
289298 * found in the LICENSE file.
290299 *
291300 * 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:
294303 *
295- * tools/create_dom_pk_codes.py
304+ * tools/maint/ create_dom_pk_codes.py
296305 *
297306 * in Emscripten root directory to regenerate this file.
298307 */
@@ -303,13 +312,16 @@ def longest_key_code_length():
303312
304313''' )
305314
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+ */
313325
314326#include <emscripten/dom_pk_codes.h>
315327''' )
@@ -332,20 +344,20 @@ def longest_key_code_length():
332344''' )
333345
334346c_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) {
337348 if (!keyCodeString) return 0;
338349
339350 /* Compute the collision free hash. */
340351 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) {
349361''' % (k1 , k2 ))
350362
351363for s in input_strings :
@@ -355,10 +367,8 @@ def longest_key_code_length():
355367 }
356368}
357369
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) {
362372''' )
363373
364374for s in input_strings :
0 commit comments