GML How to check that mouse is moving?

Discussion in 'Programming' started by Jonar, Jul 11, 2019.

Tags:
  1. Jonar

    Jonar Member

    Joined:
    Dec 9, 2018
    Posts:
    31
    I think the title explains the question that I am asking pretty well. Thanks in advance to anyone that answers.
     
  2. JML

    JML Wabbajackalope

    Joined:
    Jun 22, 2016
    Posts:
    349
    Code:
    //start event
    moveit = 0
    mxp = mouse_x
    myp = mouse_y
    
    //step event
    
    if mxp != mouse_x or myp != mouse_y
    {
    if moved != 1 {moved = 1}
    }else{
    if moved != 0 {moved = 0}
    }
    
    if mxp != mouse_x {mxp = mouse_x}
    if myp != mouse_y {myp = mouse_y}
    
    if moved = 1
    {
    //the mouse just moved, go do something in between these brackets
    }
    
    [​IMG]
     
  3. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,182
    Couldn't you just do this?
    create
    Code:
    mx = mouse_x;
    my = mouse_y;
    
    step
    Code:
    // get distance from fake mouse to real mouse
    var moving = point_distance(mx, my, mouse_x, mouse_y);
    
    // update positions of fake mouse
    mx = mouse_x;
    my = mouse_y;
    
    // if they are apart
    if (moving) {
        
    }
    
     
  4. Jonar

    Jonar Member

    Joined:
    Dec 9, 2018
    Posts:
    31
    I like this method a lot! To be honest, I didn't even know that point_distance() existed before this...

    edit: I used this system to make the mouse hide if you haven't moved it for 3 seconds:
    Code:
    // step
    if point_distance(mouse_x_past, mouse_y_past, mouse_x, mouse_y) 
    { // if mouse is moving
        window_set_cursor(cr_default);
    }
    else if alarm[2] <= 0 alarm[2] = sec(3);
    mouse_x_past = mouse_x;
    mouse_y_past = mouse_y;
    
    // alarm[2]
    window_set_cursor(cr_none); 
     
    Last edited: Jul 12, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice