Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Hotkey function to input text in a specific URL

I want to perform the following action.

When I open the URL http://google.com, if I press the keyboard combination (or hotkey) Z + P , then google should input in the searchbox How to make userscripts and when I press the keyboard combination (or hotkey) Z + O then google should input in the searchbox How to run userscripts

Please guide me as to how can I achieve this function as I am a complete novice Thanks and regards, Vicky.

Edit: For the following code

document.onkeyup=functione{
  var e = e || window.event; // for IE to cover IEs window event-object
  if(e.altKey && e.which == 65) {
    alert('Keyboard shortcut working!');
    return false;
  }
}

For the above code, when http://google.com is loaded and I press the Alt + A button, a pop up should be there with Keyboard shortcut working!. How to put this up in Tampermonkey? Please guide. @evolutionbox

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As mentioned in the comments, you can use a browser plugin like Tampermonkey for Firefox. Userscripts allow you to set rules so that they automatically run once those conditions are met. I wrote up a basic userscript that should be able to do what you requested. I tested it using tampermonkey and Firefox.

Note: It is probably more ideal to use key modifiers (shift, alt, ctrl) to create hotkeys with JavaScript, as the logic can be somewhat simplified, but hopefully this will give you something to play with.

// ==UserScript==
// @name         Google HotKeys
// @version      0.1
// @include      https://www.google.com/
// @run-at document-end
// ==/UserScript==

//store the first condition as false to start
var firstCondition = false;

//change the input value
function performAction(s){
    document.querySelector(`[aria-label="Search"]`).value = s;
}
//listen for keydown event
document.onkeydown = function(e){
    if(firstCondition){
        //if first condition is true, then look for second condition
        if(e.key == "o"){
            //if o is pressed after z, then do this...
            performAction("How to run userscripts")
        }else if(e.key == "p"){
            //otherwise, if p is pressed after z, then do this...
            performAction("How to make userscripts")
        }
        //either way, reset the first condition
        firstCondition = false;
    }else{
        //if the first condition is false, then check if "z" was pressed
        firstCondition = e.key == "z";
    }
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!