问题描述
我有一个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 (将#修改为@)