KeyboardEvent.keyCode deprecated. What does this mean in practice?
For instance if you want to detect whether the “Enter”-key was clicked or not: Instead of event.keyCode === 13 Do it like event.key === ‘Enter’
For instance if you want to detect whether the “Enter”-key was clicked or not: Instead of event.keyCode === 13 Do it like event.key === ‘Enter’
See tty standard module. It allows switching from default line-oriented (cooked) mode into char-oriented (cbreak) mode with tty.setcbreak(sys.stdin). Reading single char from sys.stdin will result into next pressed keyboard key (if it generates code): import sys import tty tty.setcbreak(sys.stdin) while True: print ord(sys.stdin.read(1)) Note: solution is Unix (including Linux) only. Edit: On Windows try msvcrt.getche()/getwche(). … Read more
You should use e.charCode in Firefox. $(“#booter”).keypress(function(e){ var code = e.charCode || e.keyCode; var input = $(this).val() + String.fromCharCode(code); $(‘#text’).focus().val(input); return false; }); Try it here: http://jsfiddle.net/REJ4t/ PS If you’re wondering why all this mess: http://www.quirksmode.org/js/keys.html
below solution also work for me. might be useful for others also. var getKeyCode = function (str) { return str.charCodeAt(str.length – 1); } document.getElementById(“a”).onkeyup = function (e) { var kCd = e.keyCode || e.which; if (kCd == 0 || kCd == 229) { //for android chrome keycode fix kCd = getKeyCode(this.value); } alert(kCd) }
Keydown will give you the keyCode of the key pressed, without any modifications. $(“#keypresser”).keydown(function(e){ var keycode = e.keyCode; var valid = (keycode > 47 && keycode < 58) || // number keys keycode == 32 || keycode == 13 || // spacebar & return key(s) (if you want to allow carriage returns) (keycode > 64 … Read more
In newer browsers supporting DOM3 you can use event.location to check the location. In the DOM3 spec, there are 4 constants defined for location, DOM_KEY_LOCATION_STANDARD, DOM_KEY_LOCATION_LEFT, DOM_KEY_LOCATION_RIGHT, andDOM_KEY_LOCATION_NUMPAD. In this case, you can do: if (event.location === KeyboardEvent.DOM_KEY_LOCATION_LEFT){ } else if (event.location === KeyboardEvent.DOM_KEY_LOCATION_RIGHT){ }
You may want to trap the mousedown event, and you also need to prevent the oncontextmenu event to stop the context menu from coming up during the right click event. $(“h2”).live(‘mousedown’, function(e) { if( (e.which == 1) ) { alert(“left button”); }if( (e.which == 3) ) { alert(“right button”); }else if( (e.which == 2) ) … Read more
You can’t do this reliably with the keyup event. If you want to know something about the character that was typed, you have to use the keypress event instead. The following example will work all the time in most browsers but there are some edge cases that you should be aware of. For what is … Read more
keyCodes are different from the ASCII values. For a complete keyCode reference, see http://unixpapa.com/js/key.html For example, Numpad numbers have keyCodes 96 – 105, which corresponds to the beginning of lowercase alphabet in ASCII. This could lead to problems in validating numeric input.
This is what I ended up using. Much cleaner. #include <CoreFoundation/CoreFoundation.h> #include <Carbon/Carbon.h> /* For kVK_ constants, and TIS functions. */ /* Returns string representation of key, if it is printable. * Ownership follows the Create Rule; that is, it is the caller’s * responsibility to release the returned object. */ CFStringRef createStringForKey(CGKeyCode keyCode) { … Read more