-2

Is there any way to make a keyboard shortcut that will click on a button on a webpage. Like I would like to have a hotkey : Ctrl+S to automatically click on Search on Google.

I've tried this : Shortcut Manager plugin but I'm not sure how to assign it.

1 Answers1

0

This might help:

See this jsFiddle

$(window).keypress(function(e) {
    var keycode = (e.keyCode ? e.keyCode : e.which);
    var rr = $('#report').html();
    $('#report').html(rr + '<br />' + keycode);

    if (e.ctrlKey) alert('Control pressed');
    //if (!(keycode == 115 && e.ctrlKey) && !(keycode == 19)) return true;
    if (!(keycode == 83 && e.ctrlKey) && !(keycode == 17)) return true;
    alert("Ctrl-S pressed");
    $('#gsearch').trigger('click'); //or just .click() also works
    e.preventDefault();
    return false;
});

Note that webkit browsers will not trap ctrl, alt, shift, etc keys. See this article for info

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111