Minimal TamperMonkey template for keypress-triggered events
This template allows you to build your own TamperMonkey scripts that react on keypresses on a specific page.
This script shows an alert message when you press Alt+Q.
// ==UserScript==
// @name TamperMonkey keypress example
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://techoverflow.net/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function onAltQ() {
alert("Alt Q pressed!");
}
function onKeydown(evt) {
// Use https://keycode.info/ to get keys
if (evt.altKey && evt.keyCode == 81) {
onAltQ();
}
}
document.addEventListener('keydown', onKeydown, true);
})();