javascript - Is there a way to prevent alternate characters from being inserted by OSX's Long Press character menu? -


i'm working on structured input class in javascript handles keydown/keypress events ensure types of input allowed in fields (for example, number cannot inserted alphabetic-only field). structured input throw out invalid characters before make input field.

i discovered on osx, if hold down keys short interval, you're presented popup menu of alternate options key (like long-pressing u key presents options û, ü, etc). if choose 1 of these options popup menu , you're focused on input field being watched structured input class, character inserted field regardless of whether or not character valid.

long press menu open holding "u" alternate character inserted

from can tell, happening because os adding character , not triggering normal javascript events expect fire when keying in text (keydown, keypress, keyup). however, input , change events fired. considered listening input event remove these non-standard characters, since character entered not included inside input event (there no e.which, e.keycode, e.charcode), i'd required lot of additional analysis on content of input field i'm trying avoid.

my question is, there events being fired i'm not aware of can use accurately capture mac osx long-pressed character popup? or out of luck?

edit: i've added example of how i'm checking keyboard events reference.

the event listeners in constructor:

    // point keyboard related events handlekeyevents() method, knows how     // deal key syphoning , event propogation.     self.element.on('keydown.mask keypress.mask ' + self.env.pasteevent, null, function(e) {       self.handlekeyevents(self, e);     }); 

and actual key handling method:

// catch-all event handling keyboard events within input field. grabs information keys // being pressed, event type, matching pattern characters, , determines them.   handlekeyevents: function(self, e) {     var evt = e || window.event,       eventtype = evt.originalevent.type,       key = e.which,       typedchar = string.fromcharcode(key);      // set original value if doesn't exist.     if (!self.initvalue) {       self.initvalue = self.element.val();     }      if (eventtype === 'keydown') {       // backspace || delete       if (key === 8 || key === 46 || (self.env.iphone && key === 127)) {         self.handlebackspace(evt);       } else if (key === 13) { // enter         self.element.trigger('blur', evt);       } else if (key === 27) { // escape         self.handleescape(evt);       } else if (36 < key && key < 41) { // arrow keys (in firefox)         return;       } else if (evt.shiftkey && 36 < key && key < 41) { // arrow keys , shift key (for moving cursor)         return;       }     }      if (eventtype === 'keypress') {       // ignore of these keys or combinations containing these keys       if (evt.ctrlkey || evt.altkey || evt.metakey || key < 32) {         return;       // need additionally check arrow key combinations here because browsers       // fire keydown , keypress events arrow keys.       } else if (evt.shiftkey && 36 < key && key < 41 && typedchar !== '(') {         return;       } else if ((36 < key && key < 41) && typedchar !== '\'' && typedchar !== '(')  {         // '(' keycode 40 on browsers         // '/' keycode 39 on browsers         return;       }       if (self.mode === 'number') {         self.processnumbermask(typedchar, evt);       } else {         self.processmask(typedchar, evt);       }     }      if (eventtype === 'paste') {       self.handlepaste(evt);     } 

i recommend doing check on validity of fields before submitting content. way non-osx users intended experience in event long-press behavior occurs, can still catch before it's submitted.

another option periodically check contents of field using setinterval

i know sounds duplicating logic without consistent input methods impossible write generic solution.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -