Desktop: Easiest Way to timeout user

I’m writing a mutiwindow database app where I will need to logout a user after a certain period of inactivity… say 15-20 minutes.

The obvious way would be a timer that gets reset with any app activity.But how do that without a lot of work?

Some combination of resetting the timer in each window’s events in:
MouseMoved, Moved, Open, Close
Can be done easily by subclassing Window

Could also use App.Activate and App.Deactivate events.

All that that gets part of the way there but is the too little or not enough?

Some windows users work primarily from the keyboard without touching a mouse much.

Window.KeyDown could get intercepted by other controls… instead of that I was wondering if there was a way to detect change of focus…(but listboxes changing rows by keyboard would not be detected by that!)

Obviously I could subclass all controls that can eat keypresses in a window and add it there (as well as listbox row changes) … But I would rather not do all that.

Is there a better way. Am I overthinking this?

Thanks,
-karen

1 Like

The way I’d do such a thing is to have two properties.

  • hasMoved as boolean
  • lastMoved as double

Use declares or a plugin to create a NSEventMonitor, that simply sets hasMoved to true on mouse move or keypress. NSEventMonitor allows you to be notified of keypresses and mouse actions with little impact to the OS or the application. Set a boolean on action to keep the cost of capturing this as low as possible.

Use a timer with a period of one minute.

  1. if hasMoved then set lastMoved to ticks or microseconds.
  2. if ticks - lastMoved > timeout then log user out.

NSEventMonitor can capture globally, if you’d rather only capture event for your application, there might be a NSEventMonitor flag or simply utilize the app.activate and app.deactivate events.

You’d of course need the Windows equivalent of NSEventMonitor, for Windows.

1 Like

Does the database handle timeouts? Then it’s the job of the database to handle the timeout. Anything else is going to get really complicated.

Thanks Sam, but this needs to be Xplatform and I am not facile with declares.

Too bad Xojo does not provide a way to to do this… but I understand only a small subset of apps need this.

-Karen

1 Like

Sorry, I can only assist with the Mac, but I haven’t written the declares to utilize NSEventMonitor and it’s available as part of my App Kit, I needed to monitor modify keys so I can display the correct icon for a control when the user presses the control key, while the mouse is over a control (without the control having focus).

Perhaps Christian can assist with a plugin for both the Mac and Windows?

Now I’m not a database person and I’m not sure if the database system you are using even supports this, but how we achieved exactly this, was to store the users last activity time in a table in the database, then we had a database stored procedure set to run at regular intervals, say every half hour, which would check the delta between the last activity time and the current time then disconnect the user if too large.

That way it was all handled by the DB, now don’t ask me the SQL to do this, as I said I’m not a DB person and one of our DBA’s did the work.

TC

Thus app will be used on common computers not just at people’s desks.

I should have been more specific… When someone “logs in” I do connect to the DB with there credentials, get some info about teh user and then close teh connection, retain i login info in the database subclass and reconnect with those credentials when they perform operations (data entry before doing a DB operation)could take awhile.

In this case login out just means Closing any open windows, and NILing the DB object and opening up the login window for someone else to login

I just can’t leave the ability for someone to use someone else’s credits if the last user forgets to log off.

The thing is I don’t want to auto logout someone out just because they are taking too long doing data entry ( having to physically check things between entries on a window… so typing with breaks but no mouse movement in-between.

-Karen

I know that is It’s doable with the DB (though I don’t know how to get a stored procedure to run at set intervals).

Not ideal for reasons given in the previous post, but given I keep connecting and disconnecting for DB operations, I could implement that on the client side easily.

Maybe that is what I will do or combine it with some of the above.

-karen