Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically logouts user after 10 min

Status
Not open for further replies.

eyeshield21

Programmer
Aug 13, 2014
62
PH
Is it possible with foxpro if a user did not move the mouse or do nothing on the screen after 10 min, then automatically log outs the current user asking to log in again just like on windows..

if it is possible..can you give me some ideas on how to do it?
tnx in advance...
 
It's possible. You need two pieces:

1) A timer that fires every <n> seconds/minutes and compares the current time against the last time the current user "did something"

2) Every form and every control needs to set that most recent time every time the user does "something"

It's up to you to decide what that "something" is. If it's moving the mouse, then every object that has MouseMove must set the most recent time there every time MouseMove fires. (Hint: it fires OFTEN!) If it's typing a keystroke, then Keypress() is a good place to set the most recent time.

There's quite a lot that you might want to have set the "most recent" property but it can all be done at the highest level control classes IF AND ONLY IF you've used your own subclasses of VFP's controls rather than using VFP's native controls directly.
 
can u give me a sample plz?

thinking something like this one...
if mousemove=F
do form...
else
do nothing
endif
 
if mousemove=F

No, that's not right.

What you need to do is to trap the MouuseMove event. Every object has this event. To determine if the user moves the mouse, you would need to write code in the MouseMove event of every control in your application. If you have a proper class hierarchy in place, it's much easier: you would only need to write the code in the MouseMove event of each of your root classes, that is, the root classes for labels, textboxes, edit boxes, pageframes, grids, .... in fact, every control that can be placed on a form (plus that of the form itself).

In every case, the code would record the time that the even fires. For simplicity, let's assume you use a public variable for this. Then, in the timer (see Dan's post, above), you would compare that time with the current time. If there is a difference of more than ten minutes, you fire your logging out routine.

Of course, you would also need to trap keystrokes in a similar same way. The principle is the same, except that you use the Keypress event.

I have simplified the above explanation. In fact, the whole thing is more complicated than you might think. For example, what if the user has minimised your app in order to use another app? Is it right to log them out in those circumstances? Or what if some unusually long background process is running, such as big database query?

Maybe it would be better to rely on the Windows screen saver to solve the problem?

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Another idea is in the FAQ section:
FAQ184-4467: How do I auto release or shut application on inactivity ?

A couple of points to keep in mind with the technique suggedted by the above FAQ:

1. It doesn't trap mouse movements, only mouse clicks. If the user just moves the mouse around (or uses the mouse to do things that are trapped by Windows, like using scroll bars), the action won't register.

2. The FAQ suggests setting the timer to half the shutdown interval. In this case, you want to shut down after ten minutes, so you would set the timer to five minutes. I suggest that's too long. In the worst case, it means that the shutdown might not execute until 15 minutes after the last mouse or key action, rather than ten. I would set the interval to one minute at the most.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If you ask me, the solution provided by Chrstof you can find by following dans link is perhaps the best solution, as it only is active at the timer interval and in case Bindevent is triggered by mouse moves, clicks or key presses. But it needs VFP9 at least because of BINDEVENT() to Windows events.

The only thing I'd change is This.Reset() the timer in case of a event signaling activity instead of storing a datetime(). Then the Timer() event itself is the event of inactivity for the timerinterval set, as it only happens, when the timer hasn't been resetted for the interval of the timer itself. You'll have less events and are getting the inactivity event as precise as a timer is. What Christof says about long running queries and other long taking commands is true, during that time the timer won't fire. You'll never have an event exactly after 10 Minutes inactivity, but that shouldn't matter much.

Bye, Olaf.

 
There are step by step instructions in that FAQ code. Please read the blue section between #IF .F. and #ENDIF.

Bye, Olaf.
 
i followed it but nothing happens.
tried to call the form using do form but it doesn't work...
something is missing on how to call my form..tnx in advance
 
here is on my main.prg
still it doesn't close after 6 seconds.

ON SHUTDOWN DO myShutDown
LOCAL loMyform
DO FORM form1 NAME loMyform LINKED

Read Events

#IF .f. && Just to avoid explanations from being run
DEFINE CLASS ShutTimer AS Timer
Interval = .1 * (60*1000/2) && 6 seconds
*Interval = 10 * (60*1000/2) && 10 minutes
Name = "ShutTimer1"

PROCEDURE Init
IF VARTYPE(ptLastUsed) = "U"
PUBLIC ptLastUsed
ENDIF
m.ptLastUsed = DATETIME()
ON KEY LABEL MOUSE m.ptLastUsed = DATETIME()
ENDPROC

PROCEDURE Timer
IF ( DATETIME()- m.ptLastUsed )*1000 > This.Interval * 2
* ThisForm.Release && if only form to be released
DO myShutDown && if application to be shutdown
ENDIF
ENDDEFINE

PROCEDURE myShutDown
CLEAR EVENTS
QUIT
#ENDIF && end of explanations


 
Minimum needed fo use of Ramanis sample is a Project (PJX) with a main.prg (main file of the project) and a form where you want to oserve activity, your own form.
And then you follow all the instructions.

If your applications has many forms, you'd rather want to use another solution than Ramanis.

Bye, Olaf.
 
Ouch, don't copy the #IF .f. and #ENDIF, this'll make the compiler not compile this portion.
Also copy out the single things, not the whole.
In short: Follow the instructions correctly.

For example step 1: Add this Timer class definition at the end of your Main.Prg

The timer class definition is what follows between DEFINE CLASS and ENDDEFINE, no more and no less.

Bye, Olaf.
 
tnx for your help..
but i think i followed it correctly..
i have only one form which is form1.scx and one main.prg..
i have followed the steps on form as well as the main.prg..

on Ramani's sample of use, he created a form using code in his main.prg...
it works but if i created a form on the documents tab and put the code which is on the steps of Ramani,
it just opens the form and nothing works...
 
Well, you only put the code into the form, that should be put inside the form. The steps tell you what.

You have to take several smaller snippets, if you follow the instructions step by step. What you do is rather copy &paste the whole thing, which is not, what the instruction says.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top