Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda