如何解决部署JS应用后未检测到输入按键,可以在本地正常运行
我有一个JS应用程序,允许用户向面板添加文本框并输入文本。他们可以单击文本框以外的地方,也可以按键盘上的Enter键进行提交。奇怪的是,部署(使用NPM构建)此功能后,似乎没有检测到Enter键的按下事件。我添加了一条console.log消息,当按下Enter键时将其触发,但这仅在本地运行时才会显示。
为什么会发生这种情况?
请参见下面的代码。在本地可以正常运行,但是在我们的AWS实例上部署时似乎不会触发。
onReturnKeyPressed: function() {
if (!textHandler.text || !textHandler.text.length) return;
this.appendPoints();
syncPoints(is.isDragAllPaths || is.isDragLastPath ? true : false);
console.log('textHandler onReturnKeyPressed');
}
编辑:看起来这仅在使用Chrome时发生。 Firefox不在乎该应用程序是本地应用还是基于Web的Enter键始终有效。
编辑2:所以我将console.log添加到事件处理程序中。在本地,所有按键向上和向下事件均在本地记录。部署到我的AWS lightail实例后,它们将不再在Chrome或Edge(铬)中启动。它们确实可以在Firefox和Brave中工作。
以下是抠像和抠像处理程序:
var keyCode;
function onkeydown(e) {
console.log('KeyDown: ',e);
keyCode = e.which || e.keyCode || 0;
if (keyCode == 8 || keyCode == 46) {
if (isBackKey(e,keyCode)) {
}
return;
}
if (keyCode == 13 && is.isText) {
textHandler.onReturnKeyPressed();
return;
}
if (e.metaKey) {
isControlKeyPressed = true;
keyCode = 17;
}
if (!isControlKeyPressed && keyCode === 17) {
isControlKeyPressed = true;
}
}
function onkeyup(e) {
console.log('KeyUp: ',e);
if (e.which == null && (e.charCode != null || e.keyCode != null)) {
e.which = e.charCode != null ? e.charCode : e.keyCode;
}
keyCode = e.keyCode || e.which || 0;
if (keyCode == 8 || keyCode == 46) {
if (isBackKey(e,keyCode)) {
textHandler.writeText(textHandler.lastKeyPress,true);
}
return;
}
// Ctrl + t
if (isControlKeyPressed && keyCode === 84 && is.isText) {
textHandler.showTextTools();
return;
}
// Ctrl + z
if (isControlKeyPressed && keyCode === 90) {
if (points.length) {
points.length = points.length - 1;
drawHelper.redraw();
syncPoints(is.isDragAllPaths || is.isDragLastPath ? true : false);
}
}
// Ending the Control Key
if (typeof e.metaKey !== 'undefined' && e.metaKey === false) {
isControlKeyPressed = false;
keyCode = 17;
}
if (keyCode === 17) {
isControlKeyPressed = false;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。