473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Lock application when idle

4
Hi,

I need to lock my application if it has been idle for 15 minutes. This is a windows application in c#. I have put a timer in the main form and implemented the IMessageFilter interface. In the PreFilterMessage method, I check for the key down and mouse move and mouse down messages. I am able to detect the inactivity if this application is not the active window.

I problem is I can't detect the idle time when the application is the active window, that is, I just leave the application in the foreground and do not do anything at all.

Can anyone help? Thanks.
Sep 17 '07 #1
5 2230
Plater
7,872 Expert 4TB
if your application is the active application....just use it's natural keydown/mousemove events.

Although, if you were correctly watching the keyboard/mouse events then it wouldn't matter what application had the focus as you would get the message from all of them.

See (Global Hooks):
http://www.codeproject.com/csharp/globalhook.asp
Sep 17 '07 #2
hmy
4
Thanks for the reply.

Let me elaborate more. This application is using .NET Framework 2.0, Smart Client Software Factory. My message filter is listening to the key and mouse events as below:

public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
// movements to monitor
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_MOUSEWHEEL:
case WM_XBUTTONDOWN:
dtLastActivity = DateTime.Now;
break;
}
// we're not handling them, just monitoring so return false
return false;
}

Now if my mouse is anywhere on the view but "idle", the inactivity will not be detected. In other scenarios (app in background or minimized), it works perfectly. I tried writing the messages that were received and it looked like WM_MOUSEMOVE is still received even if there is no activity. Any ideas why?
Sep 18 '07 #3
Plater
7,872 Expert 4TB
Well I'm not sure why, but you could try keeping track of a bit more "state" for that message.
Like everytime a mouse move message comes in, if the (X,Y) are not different then the saved (x,y) then ignore it. If they ARE different, update your saved (x,y) with those new values AND update your time of last activity object.
See if that helps?
Sep 18 '07 #4
Hi,
I am trying to do something very similar to the code you have posted.




Thanks for the reply.

Let me elaborate more. This application is using .NET Framework 2.0, Smart Client Software Factory. My message filter is listening to the key and mouse events as below:

public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
// movements to monitor
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_MOUSEWHEEL:
case WM_XBUTTONDOWN:
dtLastActivity = DateTime.Now;
break;
}
// we're not handling them, just monitoring so return false
return false;
}

Now if my mouse is anywhere on the view but "idle", the inactivity will not be detected. In other scenarios (app in background or minimized), it works perfectly. I tried writing the messages that were received and it looked like WM_MOUSEMOVE is still received even if there is no activity. Any ideas why?
Jan 23 '08 #5
Hi,
I am also trying to do something similar to the code you have posted.
I got that sample from the following link:
http://www.thescripts.com/forum/thread256888.html
I am trying to put a breakpoint in the PreFilterMessage(..) function but
not even once this function was called.
Can you please help me in this?
I have done the exact code as posted in the above link. Please let me know if any additional code/settings is needed.

Regards

Thanks for the reply.

Let me elaborate more. This application is using .NET Framework 2.0, Smart Client Software Factory. My message filter is listening to the key and mouse events as below:

public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
// movements to monitor
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_MOUSEWHEEL:
case WM_XBUTTONDOWN:
dtLastActivity = DateTime.Now;
break;
}
// we're not handling them, just monitoring so return false
return false;
}

Now if my mouse is anywhere on the view but "idle", the inactivity will not be detected. In other scenarios (app in background or minimized), it works perfectly. I tried writing the messages that were received and it looked like WM_MOUSEMOVE is still received even if there is no activity. Any ideas why?
Jan 23 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico...
19
by: Frank Rizzo | last post by:
I want to log the user out when there has been a period of inactivity in the application. The key here is inactivity of the application, not the system. I know that you can retrieve the...
5
by: Frank Rizzo | last post by:
Hello, I have a dozen 3rd party controls on my form. I am trying to detect when the application is idle. But even after the mouse and the keyboard are no longer moving, something is still...
4
by: Rick Strahl [MVP] | last post by:
Hi all, I have an ASP.Net application that's online that's 'locking up' from time to time. It doesn't completely lock up but all of a sudden it appears to be stuck for about 20-30 seconds,...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
2
by: henk | last post by:
I have a hard time to get the idle time only from my application. (a relogin box should appear after eg 1 min, when a user switch to word and start typing for 10min, the re-login should not appear....
5
by: Chakravarti Mukesh | last post by:
Hi, I want to get an event if someone locks her/his computer so that I could do some finalizations before actually locking the system. For example how can I ensure that an user close a...
2
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 .........
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.