Skip to content

Commit 03ccf3a

Browse files
[SDL1] Add implementation of SDL_GetScancodeFromKey (#18060)
Fixes: #17711
1 parent 0c564ef commit 03ccf3a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/library_sdl.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3711,7 +3711,9 @@ var LibrarySDL = {
37113711
SDL_GetCurrentAudioDriver: function() {
37123712
return allocateUTF8('Emscripten Audio');
37133713
},
3714-
3714+
SDL_GetScancodeFromKey: function (key) {
3715+
return SDL.scanCodes[key];
3716+
},
37153717
SDL_GetAudioDriver__deps: ['SDL_GetCurrentAudioDriver'],
37163718
SDL_GetAudioDriver: function(index) { return _SDL_GetCurrentAudioDriver() },
37173719

test/test_other.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,18 @@ def test_sdl_endianness(self):
19391939
self.run_process([EMXX, 'main.cpp'])
19401940
self.assertContained('1234, 1234, 4321\n', self.run_js('a.out.js'))
19411941

1942+
def test_sdl_scan_code_from_key(self):
1943+
create_file('main.cpp', r'''
1944+
#include <stdio.h>
1945+
#include <SDL/SDL_keyboard.h>
1946+
1947+
int main() {
1948+
printf("%d\n", SDL_GetScancodeFromKey(35));
1949+
return 0;
1950+
}
1951+
''')
1952+
self.do_runf('main.cpp', '204\n')
1953+
19421954
def test_sdl2_mixer_wav(self):
19431955
self.emcc(test_file('browser/test_sdl2_mixer_wav.c'), ['-sUSE_SDL_MIXER=2'], output_filename='a.out.js')
19441956

0 commit comments

Comments
 (0)