gpt4 book ai didi

Javascript 获得更快的指针事件

转载 作者:行者123 更新时间:2023-12-03 12:28:31 32 4
gpt4 key购买 nike

我正在为 Microsoft Surface 创建分析应用程序。应用程序应该能够在绘图时从 MS 手写笔收集数组中的数据(现在我正在使用 HTML5 canvas )。
我正在使用 electron使其成为桌面,用于手写笔数据收集HTML5 Pointer Events API .

所以,现在有事件监听器,当触笔在 Canvas 上移动时触发

canvas.addEventListener("pointermove", collectData, false);



collectData(event)函数看起来像:
function collectData(event) {
array.push({
a: event.tiltX,
l: event.tiltY,
p: event.pressure,
t: Date.now()
});
}

问题是,这个事件监听器每秒触发大约 70 次,对我来说这似乎是性能限制。出于我的目的,这个值非常小,我想将这个值增加两倍甚至更多。

有什么方法可以增加它,或者可能有另一种更有效的方法来从 JS 中的手写笔收集数据?

最佳答案

这是光标在屏幕上根据鼠标(输入设备)分辨率移动的次数,没有更多的值,所以你不能只增加它。但是你可以interpolate为了增加数据中的点数。

https://w3c.github.io/uievents/#mousemove

A user agent MUST dispatch this event when a pointing device is moved while it is over an element. The frequency rate of events while the pointing device is moved is implementation-, device-, and platform-specific, but multiple consecutive mousemove events SHOULD be fired for sustained pointer-device movement, rather than a single event for each instance of mouse movement. Implementations are encouraged to determine the optimal frequency rate to balance responsiveness with performance.

关于Javascript 获得更快的指针事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55416462/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com