How to obtain the keycodes in Python

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

Can javascript tell the difference between left and right shift key?

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){ }

Jquery: detect if middle or right mouse button is clicked, if so, do this:

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

How to convert ASCII character to CGKeyCode?

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