Tampermonkey未检测到钥匙按压
我正在尝试在网页中执行此代码,如果按下移动键,它将警报“ Shift”。
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match ...
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
alert('Loaded!');
var $ = window.jQuery;
$(document).keypress(function(e) {
if (e.which == 16) {
alert("shift");
}
});
})();
该程序提醒“已加载!”但是,当我按Shift按钮时,请勿提醒“ Shift”。谁能帮我弄清楚问题在哪里?
I am trying to execute this code in a webpage, which will alert "shift" if it detects a shift key pressed.
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match ...
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
alert('Loaded!');
var $ = window.jQuery;
$(document).keypress(function(e) {
if (e.which == 16) {
alert("shift");
}
});
})();
The program alerts "Loaded!" but doesn't alert "shift" when I press the shift button. Can anyone please help me figure out where the problem is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按键
事件已弃用。改用键盘
事件。The
keypress
event has been deprecated. Use thekeydown
event instead.