How do I add a custom keybind to a button on any website?

1

1

I am doing annotation work and the web interface is not user friendly at all. I would like to add my own keybinds to buttons like "clear current field" or "switch to a previous field" so I don't have to keep reaching for my mouse every few seconds. Is that possible and how can I do it? I have some HTML background and can identify the element that presses the button on the website, but don't know anything about scripts unfortunately.

It is a third party website. This is how it looks like:

The code for one of the buttons is this:

</button><button onclick="void(0);" class="t-Button " type="button"  id="buttonClearField"><span class="t-Button-label">Clear Field</span></button><button onclick="void(0);" class="t-Button " type="button"  id="btnSaveHeaderFields"><span class="t-Button-label">Save</span></button>

I want to be able to press a specific keybind (for example ctrl+A) instead of clicking on the buttons every time.

I got it going! I used the code from one of the answers here Is it possible to set keyboard shortcuts on a webpage? and it worked. Yay!

Chris

Posted 2019-11-27T08:54:22.937

Reputation: 11

Question was closed 2019-11-28T12:42:17.920

1Your question is unclear. Are you working on a third-party website? Can you show a screenshot and a concrete example of what you are trying to achieve? – slhck – 2019-11-27T08:58:09.393

1Normally shift + tab will return the cursor to the previous element. CTRL + A will select all in the current field. You might want to consider something like AutoHotKey to write macros. – Burgi – 2019-11-27T09:31:36.620

Sounds like something you’d solve with a browser extension. For example, if your browser is Firefox, you could install https://addons.mozilla.org/en-US/firefox/addon/shortcutkey2url and write a little JavaScript representing each button-click

– Jim Danner – 2019-11-27T09:52:22.273

Got it working! See my edits. – Chris – 2019-11-27T18:34:49.457

Answers

-2

The following code will make the key W show an alert saying "UP":

$(document).keypress(function(e){
  if(e.shiftKey && e.keyCode === 87){ // capital W
    alert('UP');
  }
});

Patric Phoneix

Posted 2019-11-27T08:54:22.937

Reputation: 1

1Please don't just post code without explanation. Tell us what this does and where it has to be entered. – slhck – 2019-11-27T09:01:08.970

Now that's fixed, the code is still not very usable. First, it assumes that the site uses jQuery. Second, it triggers on a letter that would normally occur during writing text, so it'll be very randomly triggered. Third, it only creates an alert, but does not do anything of what the OP listed as example actions. – slhck – 2019-11-27T15:26:09.310