0

I have a shortcut, for example CMD+0 (on macOS) and i would like to run it on the browser every x minutes, maybe using a script in the browser console like this:

function performMyShortcut(){
    // perform shortcut
    console.log("shortcut performed"); 
} setInterval(performMyShortcut,60000)

How can i do it?

  • Does [this](https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically) answer your query? –  Apr 26 '20 at 13:31
  • @VedantBang, unfortunately no, I would need a script to be inserted in the google console that performs the combination of buttons every 10 minutes for example –  Apr 26 '20 at 13:45
  • If you don't want to simulate key press events programmatically, it isn't clear then what "run shortcut" means. – Álvaro González Apr 26 '20 at 14:24
  • If you notice between the answers it is not possible to do it apparently, because **programmatic keyboard events will have led to spoofing attacks.** so I think I will do it via python –  Apr 26 '20 at 14:42

1 Answers1

0

I solved it by writing a simple python script that performs the combination of keys every x seconds, however the script must be run locally,

import threading
import keyboard

shortcut = 'Command+0'

def performShortcut():
  threading.Timer(200.0, performShortcut).start()
  keyboard.press_and_release(shortcut)

performShortcut()