Skip to content

Commit aff794e

Browse files
committed
fixed keycode issue in macOS and ubuntu
1 parent 5b0503f commit aff794e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

current-scripts/Demos/useful-scripts/scripts/input_functions/input_functions.gml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
function translate_native_to_js_keycode(_keycode) {
2+
switch (os_type) {
3+
case os_macosx:
4+
if (_keycode == 222) return vk_single_quote;
5+
else if (_keycode == 50) return vk_backtick;
6+
else return _keycode;
7+
break;
8+
9+
case os_linux:
10+
if (_keycode == 192) return vk_single_quote;
11+
else if (_keycode == 223) return vk_backtick;
12+
else return _keycode;
13+
break;
14+
15+
default:
16+
// Windows, Web, etc.
17+
return _keycode;
18+
}
19+
}
20+
121
/// @func keycode_to_string(keycode)
222
/// @desc converts keycode to name of key as a string
323
/// @param {integer} keycode
@@ -167,9 +187,10 @@ function keycode_to_string(_keycode) {
167187
/// @param {Sprite} icons
168188
function get_keyboard_icon_index(_keycode, _icons) {
169189
if (_keycode < 0) return sprite_get_number(_icons) - 1;
170-
return global.keyboard_icon_map[_keycode] == -1
190+
var _js_keycode = translate_native_to_js_keycode(_keycode);
191+
return global.keyboard_icon_map[_js_keycode] == -1
171192
? sprite_get_number(spr_keyboard_icons) - 1
172-
: global.keyboard_icon_map[_keycode];
193+
: global.keyboard_icon_map[_js_keycode];
173194
}
174195

175196
/// @func get_gamepad_icon_index(button_code, icons)

0 commit comments

Comments
 (0)