按键触发事件的最小 TamperMonkey 模板
此模板允许你构建自己的 TamperMonkey 脚本,对特定页面上的按键做出反应。
当你按 Alt+Q 时,此脚本显示一条警告消息。
tampermonkey-keypress.user.js
// ==UserScript==
// @name TamperMonkey 按键示例
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 尝试接管世界!
// @author 你
// @match https://techoverflow.net/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function onAltQ() {
alert("Alt Q 已按下!");
}
function onKeydown(evt) {
// 使用 https://keycode.info/ 获取键
if (evt.altKey && evt.keyCode == 81) {
onAltQ();
}
}
document.addEventListener('keydown', onKeydown, true);
})();Check out similar posts by category:
Javascript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow