GML How to check that mouse is moving?

J

Jonar

Guest
I think the title explains the question that I am asking pretty well. Thanks in advance to anyone that answers.
 
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
}
 

Simon Gust

Member
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) {
    
}
 
J

Jonar

Guest
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) {
  
}
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 by a moderator:

Gamebot

Member
I have just a few lines where:

CREATE:
GML:
mx = mouse_x;
my = mouse_y;
STEP:
GML:
if ( mx = mouse_x && my = mouse_y ) {
   window_set_cursor(cr_none);
} 
else {
  window_set_cursor(cr_arrow);
}

mx = mouse_x;
my = mouse_y;
You can set an alarm of course and double check in the alarm for mx and my = mouse_x and mouse_y.
 
Top