Jump to content

Reset Timer OnMouseMove


tappatappa

Recommended Posts

Suppose you have to manually implement some sort of "Timeout" Event on a Form..

 

You have a UniTimer with interval=20000 that must be resetted with each OnMouseMove event. if the mouse does not move, the Application Terminates.

 

What i want is something like this:

function window.Onmousemove(sender, x, y, 
{
  sender.UniTimer1.reset;
}

(yeah, I am a ExtJS newbie)

 

I hope this is a simple question, because what I REALLY want is a global Timer, with a global OnMouseMove handler...

 

(and no, the ServerModule.AjaxTimeOut propery is not enough for me)

 

Link to comment
Share on other sites

Thank you both for the prompt answers, Oliver and HarryG.

 

So, let's say I define two Events

function window.OnAfterrender(sender)
{
  myTimeout = window.setTimeout(function(){myFunc();}, 20000);
}
function window.Onmousemove(sender, x, y, 
{
  sender.clearTimeout(myTimeout);
}

Two problems:

 

1) How do I define myFunc? Do I have to add a call to AddJS(...) somewhere in my Delphi/C++ code?

2) myTimeOut is out of scope!

Link to comment
Share on other sites

use TUniForm.script property for a javascript:
 

function myFunc() {
  alert('do Something after timeout');
}

myTimeout = window.setTimeout(function(){myFunc();}, 20000);

 
and in onMouseMove:

function window.Onmousemove(sender, x, y, 
{
  window.clearTimeout(myTimeout);
  myTimeout = window.setTimeout(function(){myFunc();}, 20000);
}

(not tested ;)

Link to comment
Share on other sites

I've found a way to implement a global listener of mousemove that resets a TUniTimer.

 

In this example I have a component called "TUniTimer1" in the MainForm.

doc=Ext.getDoc();
  doc.on('mousemove',
  function(e) { 
	 timer1=MainForm["UniTimer1"]; 
	 try{timer1.stopAll()}catch(e){};
	 task1=timer1.tasks[0]; 
	 timer1.cEvent=function(sender) {     };
	 timer1.start(task1);
	 task1.taskRunTime=task1.taskStartTime;
  }); 
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...