Is it Possible to invoke keyboard Function keys using Chrome Extensions

I am working on Chrome Extensions. I want to know that is it Possible to invoke keyboard Function keys using Chrome Extensions.

Thanks, NVN.


EDIT: Do you want to simulate function key presses on a page or listen for physical key presses from the user? If you want want to procedurally trigger function key actions, you can't. As Rob pointed out, scripted events only activate scripted event listeners, and do not trigger default behavior.

In order to detect function key presses, you need to bind your events to keyup -- not to keypress, which doesn't fire for several non-printable keystrokes, like function keys and arrow keys.

document.documentElement.addEventListener("keyup", function(e) {
    if(e.keyCode == 113) {
        // if F2 is pressed...
        // F1 is keycode 112, and it increments from there

Some function keys do things already (F1 opens help, F5 refreshes, etc.). If you have a good reason for preventing this behavior (e.g. you're making an immersive full-screen app like a VNC viewer that shouldn't exhibit normal browser behavior), you can use preventDefault on keydown to stop that potentially disruptive action:

document.documentElement.addEventListener("keydown", function(e) {
    if(e.keyCode == 112) {
        // if F1 is pressed, don't open help

To see how to handle key presses for your Chrome extension, see my answer on Activate extension via short cut key; that should be exactly what you need for the rest. Briefly:

  • the code I gave above goes in a content script that gets added to each page

  • the event handlers functions perform some action, either within the content script on the page or by passing a message to the background page

Need Your Help

Help me improve this Erlang?

syntax erlang roman-numerals

So I'm really interested in Erlang. I can't find an excuse to use it for anything big, but I try to use it for toy problems from time to time.

Outlook 2010 email fixed width issue

email outlook width installation

I have an html email .oft (Outlook File Template) created in Outlook 2010 with a table layout width set to 600px. This ecard template is distributed to others at the company who might want to add a...