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

276
Views
How do I detect a keydown event in google docs with a JS bookmarklet?

I have been trying to make a JS bookmarklet that will make a sound on any keydown and keyup events, and on most websites it's been working. However, it doesn't work in google docs, where I wanted to use it the most. This may sound like a duplicate of this question, but I promise that I tried all of the solutions and they did not work, probably because the question's from 11 years ago. Here's my code:

function random(min,max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1) + min);
}

function makeListeners(kind) {
  const generic = [];
  const space = [];
  const enter = [];
  const backspace = [];

  for (let x = 0;x < 3;x++) {
    generic.push(new Audio(`https://you-dont-need-to-know-my-website.com/audio1.mp3`));
    space.push(new Audio(`https://you-dont-need-to-know-my-website.com/audio2.mp3`));
    enter.push(new Audio(`https://you-dont-need-to-know-my-website.com/audio3.mp3`));
    backspace.push(new Audio(`you-dont-need-to-know-my-website.com/audio4.mp3`));
  }
  document.addEventListener(kind, function(e) {
    if (e.code != 'Space' && e.code != 'Enter' && e.code !='Backspace') {
      generic[random(0,2)].play();
    }
    else {
      eval(e.code.toLowerCase())[random(0,2)].play();
    }
  });
}

makeListeners('keydown');
makeListeners('keyup');
about 4 years ago · Juan Pablo Isaza
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!