Skip to content

Commit 2f34589

Browse files
author
Ian Macphail
committed
[[ Emscripten ]] Ignore alt-key state when passing key events
This patch masks the alt key state for key events, so that characters that require an alt+key combination to be entered can be input into a field. Without doing so, such inputs would be interpreted as e.g. alt+# rather than alt+3 (the combo that produces '#') or just '#' and assumed to be a menu shortcut instead of a character to be added to the field.
1 parent de0f611 commit 2f34589

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

engine/src/em-event.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,10 @@ mergeInto(LibraryManager.library, {
148148
return LiveCodeEvents._getStackForWindow(window);
149149
},
150150

151-
_encodeModifiers: function(uiEvent) {
151+
_encodeModifiers: function(pShift, pAlt, pCtrl, pMeta) {
152152
return Module.ccall('MCEmscriptenEventEncodeModifiers', 'number',
153153
['number', 'number', 'number', 'number'],
154-
[uiEvent.shiftKey, uiEvent.altKey,
155-
uiEvent.ctrlKey, uiEvent.metaKey]);
154+
[pShift, pAlt, pCtrl, pMeta]);
156155
},
157156

158157
// ----------------------------------------------------------------
@@ -540,8 +539,18 @@ mergeInto(LibraryManager.library, {
540539
const kKeyStatePressed = 2;
541540

542541
var stack = LiveCodeEvents._getStackForCanvas(pCanvas);
543-
var mods = LiveCodeEvents._encodeModifiers(e);
544-
542+
/* TODO - reenable alt key detection
543+
* As there is no direct way to tell the difference between an alt+<key>
544+
* combination that produces a different character, and holding alt down
545+
* while typing that character directly, for now we ignore the state of
546+
* the alt key so that typing such characters is possible.
547+
*/
548+
var mods = LiveCodeEvents._encodeModifiers(e.shiftKey, false, e.ctrlKey, e.metaKey);
549+
550+
// Ignore alt key presses
551+
if (e.key == 'Alt')
552+
return;
553+
545554
// ignore key events during IME composing
546555
if (e.isComposing || e.keyCode === 229)
547556
return;
@@ -735,7 +744,7 @@ mergeInto(LibraryManager.library, {
735744

736745
var target = LiveCodeEvents._eventTarget(e);
737746
var stack = LiveCodeEvents._getStackForCanvas(target);
738-
var mods = LiveCodeEvents._encodeModifiers(e);
747+
var mods = LiveCodeEvents._encodeModifiers(e.shiftKey, e.altKey, e.ctrlKey, e.metaKey);
739748
var pos = LiveCodeEvents._encodeMouseCoordinates(e);
740749

741750
// ignore events for non-lc elements

0 commit comments

Comments
 (0)