Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda