Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Mouse-tracking

Hello everyone,

Is it possible to track the movements of the mouse in online experiments?

What I'm looking to create is a sort of mask so that only the part of the display surrounding the cursor location will be visible.

Basically, I'd like to something like this: https://psyarxiv.com/rsdwg/ but I'm not sure if such a javascript plugin would work in OS? And also, there might be simpler solutions.

Any help would be greatly appreciated :)

Cheers,

Jasper

Comments

  • edited June 2021

    So I think I got a solution that actually works quite nicely :)

    • I use a sequence with a sketchpad and an inline javascript that repeats 1000 times
    • The sketchpad is shown 1 ms (i.e. one screen refresh)
    • The location of the mask in the sketchpad is determined by vars.x_mouse and vars.y_mouse
    • The inline js contains the code below.
    • Of course any ideas to improve on this are very welcome! I've only tested in Chrome on a Mac.


    onmousemove = function(e){vars.x_mouse = e.clientX; vars.y_mouse = e.clientY}
    if (vars.x_mouse == vars.x_mouse2) {
        console.log('no x movement');
    } else {
        vars.x_mouse -= 512; //half of display width
    }
    if (vars.y_mouse == vars.y_mouse2) {
        console.log('no y movement');
    } else {
        vars.y_mouse -= 384; //half of display height
    }
    vars.x_mouse2 = vars.x_mouse; //for use on the next cycle
    vars.y_mouse2 = vars.y_mouse;
    



    Cheers,

    Jasper

  • Hi Jasper,

    Thanks for sharing! That might be quite useful.

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.