Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tenacious Stu on Wed 20/04/2011 18:10:09

Title: Is there a way to detect if the mouse has been inactive for a certain time?
Post by: Tenacious Stu on Wed 20/04/2011 18:10:09
Hi there,

I searched for this one, but found nothing, it may be a unique issue. I want to detect when the mouse has been inactive for a certain period of time? I would imagine you would start a timer if mouse is inactive and if mouse moves then reset timer. When the timer runs out then{ Do whatever, but how would I implement this? Can I implement this?

On a side note, how many loops would 10 Minutes be?

Thanks in advance for any Replies  ;)
Title: Re: Is there a way to detect if the mouse has been inactive for a certain time?
Post by: Khris on Wed 20/04/2011 18:41:21
You are on the right track:

// top of GlobalScript.asc
// inactivity vars
int omx, omy;  // old mouse x/y
int inactivity_mins = 10;
bool idling;

// inside repeatedly_execute

  // mouse inactivity?
  if (mouse.x != omx || mouse.y != omy) {  // has mouse moved since last frame?
    omx = mouse.x;
    omy = mouse.y;
    SetTimer(1, GetGameSpeed()*60*inactivity_mins); // reset timer to inactivity_mins minutes
    if (idling) StopIdle();
  }

  if (IsTimerExpired(1)) {
    // start screen saver/idle stuff/whatever
    idling = true;
    StartIdle();
  }


// top of on_mouse_click / on_key_press

  // reset inactivity timer
  SetTimer(1, GetGameSpeed()*60*inactivity_mins); // set timer to inactivity_mins minutes
  if (idling) StopIdle();


As you can see I'd use two custom functions called StartIdle() and StopIdle() to run/remove whatever is supposed to happen after 10 minutes of inactivity.
Title: Re: Is there a way to detect if the mouse has been inactive for a certain time?
Post by: barefoot on Wed 20/04/2011 19:45:05
Game loops are 40 frames a second...

I meant 40 game loops per second..

barefoot
Title: Re: Is there a way to detect if the mouse has been inactive for a certain time?
Post by: Sephiroth on Wed 20/04/2011 19:47:17
40 is the default game speed, that's why Khris used GetGameSpeed() so that it works with whatever you want.

GetGameSpeed()*1 = 1 second
Title: Re: Is there a way to detect if the mouse has been inactive for a certain time?
Post by: Khris on Wed 20/04/2011 19:47:25
Or rather, there are 40 game loops per second.
This is only the default value though, GetGameSpeed() will return the current value.

So to get from seconds to loops, just multiply the seconds with GetGameSpeed().