Handling key-press events (F1-F12) using JavaScript and jQuery, cross-browser

I agree with William that in general it is a bad idea to hijack the function keys. That said, I found the shortcut library that adds this functionality, as well as other keyboard shortcuts and combination, in a very slick way. Single keystroke: shortcut.add(“F1”, function() { alert(“F1 pressed”); }); Combination of keystrokes: shortcut.add(“Ctrl+Shift+A”, function() { … Read more

How to generate keyboard events?

It can be done using ctypes: import ctypes from ctypes import wintypes import time user32 = ctypes.WinDLL(‘user32’, use_last_error=True) INPUT_MOUSE = 0 INPUT_KEYBOARD = 1 INPUT_HARDWARE = 2 KEYEVENTF_EXTENDEDKEY = 0x0001 KEYEVENTF_KEYUP = 0x0002 KEYEVENTF_UNICODE = 0x0004 KEYEVENTF_SCANCODE = 0x0008 MAPVK_VK_TO_VSC = 0 # msdn.microsoft.com/en-us/library/dd375731 VK_TAB = 0x09 VK_MENU = 0x12 # C struct definitions wintypes.ULONG_PTR … Read more

Firing a Keyboard Event in Safari, using JavaScript

I am working on DOM Keyboard Event Level 3 polyfill . In latest browsers or with this polyfill you can do something like this: element.addEventListener(“keydown”, function(e){ console.log(e.key, e.char, e.keyCode) }) var e = new KeyboardEvent(“keydown”, {bubbles : true, cancelable : true, key : “Q”, char : “Q”, shiftKey : true}); element.dispatchEvent(e); //If you need legacy … Read more