Jemt / Fit.UI

Fit.UI is a JavaScript based UI framework built on Object Oriented principles
http://fitui.org
GNU Lesser General Public License v3.0
19 stars 7 forks source link

Cross browser support for obtaining KeyCode and KeyChar #123

Open FlowIT-JIT opened 3 years ago

FlowIT-JIT commented 3 years ago

Text below has been extracted from #113

We should probably expose Fit.Events.GetKeyCode(evArg) which uses modern APIs when available, and revert to legacy APIs when not. Also supply Fit.Events.GetKeyChar(evArg) which on modern browsers leverage the .key property, while on older browsers use something like String.fromCharCode(evArg.charCode || evArg.keyCode). Remember, we can trust evArg.keyCode to return a real character code just like evArg.charCode when evArgs.type returns "keypress", while for OnKeyDown and OnKeyUp, the keyCode might represent any key, which might produce odd results when passed to String.fromCharCode(..) - for instance keyCode 119 (F8) results in a return value of "w" while the meta key (e.g. Cmd key on Mac) returns "[". We probably want Fit.Events.GetKeyChar(..) to return "" when keyCode is in the range of 0-46 (excluding: 9 = tab (\t), 13 = line feed (\r), 32 = space), and 91-222 (http://gcctech.org/csc/javascript/javascript_keycodes.htm). Also see https://stackoverflow.com/questions/7694486/browser-key-code-list