user idle check

3 views
Skip to first unread message

jkr...@gmail.com

unread,
Mar 23, 2013, 11:47:44 AM3/23/13
to node-...@googlegroups.com
I have a chat application I have built using node-webkit and was wondering if there is a way to detect if a user is idle. I can do it within the app with a basic mouse event but if the window is minimized, is there any way to hook into the system.

Ideally I would like to query the systems user idle timer but would settle on querying the mouse coordinates periodically and comparing the previous position.

Is this doable? If not, any other suggestions.

Chris Turnbull

unread,
Mar 24, 2013, 3:13:58 PM3/24/13
to node-...@googlegroups.com
Could you use requestAnimationFrame() to record the time that your user last viewed the window? Then you could use a setTimeout() or setInterval() to check if this variable was more than x minutes ago.

If someone had left the window open and viewable then they'd count as active, but if they had the window covered up or minimised then they'd be marked as inactive after x minutes.

Failing that you could try recording the time on any mouse or keyboard events that get fired on your window.

Jeff K

unread,
Mar 25, 2013, 9:12:56 AM3/25/13
to node-...@googlegroups.com
Thanks. That's the plan for now but I have some people who just need to be available but don't use it much if not needed by someone. Its those users that I know will just leave it running when they leave and if I use these methods it will exit them prematurely. 

I may have to introduce a popup nag but would like to have that as a last resort.

I am migrating from Tidesdk which has a system wide idle feature so was hope this platform had the same.

Chris Turnbull

unread,
Mar 25, 2013, 9:45:12 AM3/25/13
to node-...@googlegroups.com
Maybe your problem is that you've not told us exactly what you mean by "idle"? Do you want to know if someone has not used your app in a little while, or mean you want to be notified if someone's not touching anything on their entire computer?

I assumed you meant the former.

--
You received this message because you are subscribed to a topic in the Google Groups "node-webkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-webkit/8XSmzFww5pc/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Philippe Jean

unread,
Mar 25, 2013, 10:40:23 AM3/25/13
to node-...@googlegroups.com
it all depends on what you are trying to achieve.  if you want the second scenario mentioned by chris,  javascript might be a good approach.
the script monitors key press and mouse move from the user and allow to register callbacks when a certain idle time is reached and when idle state is left…..
 

javascript


You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.

Jeff K

unread,
Mar 25, 2013, 11:39:55 AM3/25/13
to node-...@googlegroups.com
Thanks Chris for your feedback and sorry for the lack of clarity.

I basically need to know if the user is still at their computer, so an overall user idle check versus whether or not the user has used the app. So on that note, I am ideally looking for the last user input time (mouse or mouse and keyboard) according to the OS. I can then query at set intervals (like every 15 - 30 mins or so) and a) set the user to an idle status then b) eventually log them out after x mins of idle.

One sort of ugly solution I am looking at is creating a small exe that queries the getlastinputinfo  (on windows as part of user32.dll) and have it write the idle time (shown in milliseconds  to a txt file. I can then have my app call this app every 15/30 mins, read the file it creates then alter status as needed. Again not ideal but it would achieve the end result. I am new to node.js so not sure there is a way to query that natively but from that I have researched, I don't think so.

Thanks for that snippet Philippe!. I think I may use that one one until there is a way to check with the os. 

don...@gmail.com

unread,
Mar 22, 2014, 11:25:22 AM3/22/14
to node-...@googlegroups.com
I made a module which uses some of the methods mentioned in this thread to detect idle time in node. Here you are: https://www.npmjs.org/package/afk

grze...@gmail.com

unread,
Mar 22, 2014, 11:44:38 AM3/22/14
to node-...@googlegroups.com
This topic was already discussed here. Try to find it. You can catch mouse action on the system layer not chrome layer. Relativly easy task to do on Linux where mouse input is writen to /dev/input/mouse  (or somwhere around) but might be harder on Windows. I found that it might new C# wrapper to log into a file first.

Jeff K

unread,
Mar 23, 2014, 8:25:03 AM3/23/14
to node-...@googlegroups.com
I tried using  this and I get 

Error: %1 is not a valid Win32 application. 

referencing idle.node


--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages