Skip to content

Commit f09fdac

Browse files
committed
Support non-QWERTY locale input
1 parent 71a76e8 commit f09fdac

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Keyboard layout localization for [Input for GameMaker 2024.8](https://github.com
88
InputLocalizeGetLocale() // Returns enum, user's keyboard locale
99
1010
InputLocalizeBinding( // Returns a localized binding
11-
binding, // Binding, a virtual key constant from QWERTY layout
12-
[locale]) // Enum, destination locale. User's locale, if undefined
11+
binding, // Binding, virtual key constant
12+
[localeInput], // Enum, source locale. INPUT_KEYBOARD_LOCALE.QWERTY, if undefined
13+
[localeOutput]) // Enum, destination locale. User's locale, if undefined
1314
1415
enum INPUT_KEYBOARD_LOCALE
1516
.QWERTY // English Latin key layout
@@ -20,7 +21,7 @@ enum INPUT_KEYBOARD_LOCALE
2021
### Example Usage
2122

2223
```
23-
//Set localized key definitions
24+
// Set localized key definitions
2425
InputDefineVerb(INPUT_VERB.WALK_FORWARD, "forward", InputLocalizeBinding("W"), -gp_axislv);
2526
InputDefineVerb(INPUT_VERB.STRAFE_LEFT, "left", InputLocalizeBinding("A"), -gp_axislh);
2627
InputDefineVerb(INPUT_VERB.WALK_BACK, "back", InputLocalizeBinding("S"), gp_axislv);
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Feather disable all
22

3-
function InputLocalizeBinding(_binding, _locale = undefined)
3+
function InputLocalizeBinding(_binding, _localeInput = INPUT_KEYBOARD_LOCALE.QWERTY, _localeOutput = undefined)
44
{
55
static _system = __InputLocalizeSystem();
66

@@ -9,10 +9,20 @@ function InputLocalizeBinding(_binding, _locale = undefined)
99
_binding = ord(_binding);
1010
}
1111

12-
if (_locale == undefined)
12+
if (_localeInput == _localeOutput)
1313
{
14-
_locale = InputLocalizeGetLocale();
14+
return _binding;
1515
}
1616

17-
return _system.__localeKeycodeMapArray[_locale][? _binding] ?? _binding;
18-
}
17+
if (_localeOutput == undefined)
18+
{
19+
_localeOutput = InputLocalizeGetLocale();
20+
}
21+
22+
if (_localeInput != INPUT_KEYBOARD_LOCALE.QWERTY)
23+
{
24+
_binding = _system.__localeKeycodeToQWERTYArray[_localeInput][? _binding] ?? _binding;
25+
}
26+
27+
return _system.__localeQWERTYtoKeycodeArray[_localeOutput][? _binding] ?? _binding;
28+
}

scripts/__InputLocalizeSystem/__InputLocalizeSystem.gml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enum INPUT_KEYBOARD_LOCALE
88
__SIZE,
99
}
1010

11-
InputPlugInDefine("Alynne.Localization", "alynne", "1.0", "10.0", function(){ return; });
11+
InputPlugInDefine("Alynne.Localization", "alynne", "1.1", "10.0", function(){ return; });
1212

1313
__InputLocalizeSystem();
1414
function __InputLocalizeSystem()
@@ -19,7 +19,8 @@ function __InputLocalizeSystem()
1919
_system = {};
2020
with(_system)
2121
{
22-
__localeKeycodeMapArray = [];
22+
__localeKeycodeToQWERTYArray = [];
23+
__localeQWERTYtoKeycodeArray = [];
2324
__locale = undefined;
2425

2526
//Set locale per ISO 639-1 and ISO 3166-1
@@ -52,25 +53,39 @@ function __InputLocalizeSystem()
5253
}
5354

5455
//Set localisation maps
55-
repeat (INPUT_KEYBOARD_LOCALE.__SIZE) array_push(__localeKeycodeMapArray, ds_map_create());
56+
repeat (INPUT_KEYBOARD_LOCALE.__SIZE)
57+
{
58+
array_push(__localeKeycodeToQWERTYArray, ds_map_create());
59+
array_push(__localeQWERTYtoKeycodeArray, ds_map_create());
60+
}
61+
62+
var _SetLocaleMapping = function(_locale, _keycodeArray)
63+
{
64+
var _keycodeInput = undefined;
65+
var _keycodeOutput = undefined;
5666

57-
//AZERTY ';' -> 'M' -> ',' -> ';'
58-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.AZERTY][? vk_semicolon] = ord("M");
59-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.AZERTY][? ord("M") ] = vk_comma;
60-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.AZERTY][? vk_comma ] = vk_semicolon;
67+
var _i = 0;
68+
var _length = array_length(_keycodeArray);
69+
repeat(_length)
70+
{
71+
_keycodeInput = _keycodeArray[_i];
72+
_keycodeOutput = _keycodeArray[(_i + 1) mod _length];
6173

62-
//AZERTY 'Q' <-> 'A'
63-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.AZERTY][? ord("Q")] = ord("A");
64-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.AZERTY][? ord("A")] = ord("Q");
74+
if (is_string(_keycodeInput )) _keycodeInput = ord(_keycodeInput);
75+
if (is_string(_keycodeOutput)) _keycodeOutput = ord(_keycodeOutput);
6576

66-
//AZERTY 'W' <-> 'Z'
67-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.AZERTY][? ord("W")] = ord("Z");
68-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.AZERTY][? ord("Z")] = ord("W");
77+
__localeQWERTYtoKeycodeArray[@ _locale][? _keycodeInput ] = _keycodeOutput;
78+
__localeKeycodeToQWERTYArray[@ _locale][? _keycodeOutput] = _keycodeInput;
6979

70-
//QWERTZ 'Y' <-> 'Z'
71-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.QWERTZ][? ord("Y")] = ord("Z");
72-
__localeKeycodeMapArray[@ INPUT_KEYBOARD_LOCALE.QWERTZ][? ord("Z")] = ord("Y");
80+
++_i;
81+
}
82+
}
83+
84+
_SetLocaleMapping(INPUT_KEYBOARD_LOCALE.QWERTZ, ["Y", "Z"]);
85+
_SetLocaleMapping(INPUT_KEYBOARD_LOCALE.AZERTY, ["Q", "A"]);
86+
_SetLocaleMapping(INPUT_KEYBOARD_LOCALE.AZERTY, ["W", "Z"]);
87+
_SetLocaleMapping(INPUT_KEYBOARD_LOCALE.AZERTY, [vk_semicolon, "M", vk_comma]);
7388
}
7489

7590
return _system;
76-
}
91+
}

0 commit comments

Comments
 (0)