How to detect mouse acceleration in javascript?

心不动则不痛 提交于 2020-03-20 23:06:10

问题


I'm logging the mouse movements in a web app.

I'd like to detect the mouse acceleration on a platform (e.g. Windows). Is it possible to do it from javascript, even just in an approximated way? I could ask the user to check their settings with a questionnaire, but it would be much better to detect it automatically.

Cheers


回答1:


Check distance the mouse has moved over a set interval of time:

var mX:Number = _xmouse;
var mY:Number = _ymouse;

function checkDistance()
{
    clear();
    //trace('new distance: ' + Math.sqrt(Math.pow((mY - _ymouse), 2) + Math.pow((mX - _xmouse), 2)));
    lineStyle(1, 0x000000);
    moveTo(mX, mY);
    lineTo(_xmouse, _ymouse);
    mX = _xmouse;
    mY = _ymouse;
}

setInterval(checkDistance, 1000);

from http://www.kirupa.com/forum/showthread.php?t=332961



来源:https://stackoverflow.com/questions/3619348/how-to-detect-mouse-acceleration-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!