Is there a way to detect if the mouse has been inactive for a certain time?

Started by Tenacious Stu, Wed 20/04/2011 18:10:09

Previous topic - Next topic

Tenacious Stu

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  ;)

Khris

You are on the right track:

Code: ags
// 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.

barefoot

Game loops are 40 frames a second...

I meant 40 game loops per second..

barefoot
I May Not Be Perfect but I Have A Big Heart ..

Sephiroth

40 is the default game speed, that's why Khris used GetGameSpeed() so that it works with whatever you want.

GetGameSpeed()*1 = 1 second

Khris

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().

SMF spam blocked by CleanTalk