473,409 Members | 2,056 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,409 software developers and data experts.

Problem in using 'ImessageFilter' Interface

Hi,

I want to use 'IMessageFilter' interface to monitor my Key and mouse events to let me know the idle time of my application.

But this interface nt works fine. 'PreFilterMessage' function of this interface shows that in every specified time 'MouseMove' event occurs even if there is not movement in mouse.

Also If i open a Modal form from that application than this interface does not give messages related to mousemove event in all the previous forms open in this application.

I also prepare a class that uses API's to hook my keyboard and mouse event. This works fine.

But i want to use IMessageFilter in my application.

Please help me.

Regards,
Ashish
Oct 22 '08 #1
4 3385
tlhintoq
3,525 Expert 2GB
Hi,

I want to use 'IMessageFilter' interface to monitor my Key and mouse events to let me know the idle time of my application.

But this interface nt works fine. 'PreFilterMessage' function of this interface shows that in every specified time 'MouseMove' event occurs even if there is not movement in mouse.

Also If i open a Modal form from that application than this interface does not give messages related to mousemove event in all the previous forms open in this application.

I also prepare a class that uses API's to hook my keyboard and mouse event. This works fine.

But i want to use IMessageFilter in my application.

Please help me.

Regards,
Ashish
As if by magic...
http://www.codeproject.com/KB/miscct...tion_Idle.aspx
Oct 23 '08 #2
As if by magic...
http://www.codeproject.com/KB/miscct...tion_Idle.aspx
hi

Thanks for reply and Sorry for my late response.

The code given in Code Project link was not working well. I have modified that code according to me, it doesn't work. Following is my modified code:

public bool PreFilterMessage(ref Message m)
{
// Just to see the messages.
Console.WriteLine(DateTime.Now + " " + m.ToString());
switch (m.Msg)
{
case WM_KEYDOWN:
lastKeyOrMouse = DateTime.Now;
break;

case WM_KEYUP:
lastKeyOrMouse = DateTime.Now;
break;

case WM_LBUTTONDBLCLK:
lastKeyOrMouse = DateTime.Now;
break;

case WM_LBUTTONDOWN:
lastKeyOrMouse = DateTime.Now;
break;

case WM_LBUTTONUP:
lastKeyOrMouse = DateTime.Now;
break;

case WM_MBUTTONDBLCLK:
lastKeyOrMouse = DateTime.Now;
break;

case WM_MBUTTONDOWN:
lastKeyOrMouse = DateTime.Now;
break;

case WM_MBUTTONUP:
lastKeyOrMouse = DateTime.Now;
break;

case WM_MOUSEMOVE:
lastKeyOrMouse = DateTime.Now;
break;

case WM_MOUSEWHEEL:
lastKeyOrMouse = DateTime.Now;
break;

case WM_RBUTTONDBLCLK:
lastKeyOrMouse = DateTime.Now;
break;

case WM_RBUTTONDOWN:
lastKeyOrMouse = DateTime.Now;
break;

case WM_RBUTTONUP:
lastKeyOrMouse = DateTime.Now;
break;

case WM_SYSKEYDOWN:
lastKeyOrMouse = DateTime.Now;
break;

case WM_SYSKEYUP:
lastKeyOrMouse = DateTime.Now;
break;

case WM_XBUTTONDBLCLK:
lastKeyOrMouse = DateTime.Now;
break;

case WM_XBUTTONDOWN:
lastKeyOrMouse = DateTime.Now;
break;

case WM_XBUTTONUP:
lastKeyOrMouse = DateTime.Now;
break;
}
return false;
}


Previously it was looks like the following code:

public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case WM_KEYDOWN:
case WM_KEYUP:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONDBLCLK:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_MOUSEMOVE:
case WM_MOUSEWHEEL:
case WM_RBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_XBUTTONDBLCLK:
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:
lastKeyOrMouse = DateTime.Now;
break;
}
return false;
}


If my mouse is upon form then MouseMove event occurs in a regular interval, even if no activity done by mouse. My problem still exists.

Regards,
Ashish
Oct 31 '08 #3
tlhintoq
3,525 Expert 2GB
hi

Thanks for reply and Sorry for my late response.

The code given in Code Project link was not working well. I have modified that code according to me, it doesn't work. Following is my modified code:
\
Expand|Select|Wrap|Line Numbers
  1.         public bool PreFilterMessage(ref Message m)
  2.         {
  3.             // Just to see the messages.
  4.             Console.WriteLine(DateTime.Now + "  " + m.ToString());
  5.             switch (m.Msg)
  6.             {
  7.                 case WM_KEYDOWN:
  8.                     lastKeyOrMouse = DateTime.Now;
  9.                     break;
  10.  
  11.                 case WM_KEYUP:
  12.                     lastKeyOrMouse = DateTime.Now;
  13.                     break;
  14.  
  15.                 case WM_LBUTTONDBLCLK:
  16.                     lastKeyOrMouse = DateTime.Now;
  17.                     break;
  18.  
  19.                 case WM_LBUTTONDOWN:
  20.                     lastKeyOrMouse = DateTime.Now;
  21.                     break;
  22.  
  23.                 case WM_LBUTTONUP:
  24.                     lastKeyOrMouse = DateTime.Now;
  25.                     break;
  26.  
  27.                 case WM_MBUTTONDBLCLK:
  28.                     lastKeyOrMouse = DateTime.Now;
  29.                     break;
  30.  
  31.                 case WM_MBUTTONDOWN:
  32.                     lastKeyOrMouse = DateTime.Now;
  33.                     break;
  34.  
  35.                 case WM_MBUTTONUP:
  36.                     lastKeyOrMouse = DateTime.Now;
  37.                     break;
  38.  
  39.                 case WM_MOUSEMOVE:
  40.                     lastKeyOrMouse = DateTime.Now;
  41.                     break;
  42.  
  43.                 case WM_MOUSEWHEEL:
  44.                     lastKeyOrMouse = DateTime.Now;
  45.                     break;
  46.  
  47.                 case WM_RBUTTONDBLCLK:
  48.                     lastKeyOrMouse = DateTime.Now;
  49.                     break;
  50.  
  51.                 case WM_RBUTTONDOWN:
  52.                     lastKeyOrMouse = DateTime.Now;
  53.                     break;
  54.  
  55.                 case WM_RBUTTONUP:
  56.                     lastKeyOrMouse = DateTime.Now;
  57.                     break;
  58.  
  59.                 case WM_SYSKEYDOWN:
  60.                     lastKeyOrMouse = DateTime.Now;
  61.                     break;
  62.  
  63.                 case WM_SYSKEYUP:
  64.                     lastKeyOrMouse = DateTime.Now;
  65.                     break;
  66.  
  67.                 case WM_XBUTTONDBLCLK:
  68.                     lastKeyOrMouse = DateTime.Now;
  69.                     break;
  70.  
  71.                 case WM_XBUTTONDOWN:
  72.                     lastKeyOrMouse = DateTime.Now;
  73.                     break;
  74.  
  75.                 case WM_XBUTTONUP:
  76.                     lastKeyOrMouse = DateTime.Now;
  77.                     break;
  78.             }
  79.             return false;
  80.         }
  81.  
Previously it was looks like the following code:

Expand|Select|Wrap|Line Numbers
  1.         public bool PreFilterMessage(ref Message m)
  2.         {
  3.            switch (m.Msg)
  4.             {
  5.                 case WM_KEYDOWN:
  6.                 case WM_KEYUP:
  7.                 case WM_LBUTTONDBLCLK:
  8.                 case WM_LBUTTONDOWN:
  9.                 case WM_LBUTTONUP:
  10.                 case WM_MBUTTONDBLCLK:
  11.                 case WM_MBUTTONDOWN:
  12.                 case WM_MBUTTONUP:
  13.                 case WM_MOUSEMOVE:
  14.                 case WM_MOUSEWHEEL:
  15.                 case WM_RBUTTONDBLCLK:
  16.                 case WM_RBUTTONDOWN:
  17.                 case WM_RBUTTONUP:
  18.                 case WM_SYSKEYDOWN:
  19.                 case WM_SYSKEYUP:
  20.                 case WM_XBUTTONDBLCLK:
  21.                 case WM_XBUTTONDOWN:
  22.                 case WM_XBUTTONUP:
  23.                     lastKeyOrMouse = DateTime.Now;
  24.                     break;
  25.             }
  26.             return false;
  27.         }
  28.  
If my mouse is upon form then MouseMove event occurs in a regular interval, even if no activity done by mouse. My problem still exists.

Regards,
Ashish
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

Just because your hand isn't on the mouse, doesn't mean there isn't mouse movement. I have seen my wife's laptop wake from mouse movement when she isn't at the desk: Just from the air conditioner blowing on the dangling mouse cord. If you want to really test that there is no mouse movement: Unplug it from your PC. If you still get mouse movement events then there is a true problem.

You could also qualify the mouse movements to make sure it isn't miniscule movements from environmental vibration like the drive motors and cooling fans of your PC. Keep track of the mouse position. Qualify a 'real' move as more than just 1-2 point values within 50 milliseconds. If a person is moving the mouse its going to be big moves in a short time. If it isn't a qualified movement then you don't change your member variable 'lastKeyOrMouse'.

Question: What is the point of your method always returning 'false'? If you are always going to return the same value you might as well just have it be void and return nothing at all. The point to having a method return some value is to tell you something significant. For example if you set a bool to false before the Switch statement any of the cases could turn it to True, then you always return that variable. If the returned value is still false, then none of the cases were executed. If the method returns 'true' then a case was used.

If you had the method return an int, you could return a unique number that even tells WHICH case statement was executed, and thus which mouse or key event took place.

Between lines 25 and 26 insert a line that prints the message value of m to the console, so you can watch what is going on.
Oct 31 '08 #4
The implementation requires a bool return value from PreFilterMessage(), 'false' tells the framework to pass on the message to the default handler, returning 'true' prevents any further handling.
Sep 28 '10 #5

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

Similar topics

1
by: See Sharp | last post by:
Hello all, I have a form class that implements the imessagefilter interface public class frmMain : System.Windows.Forms.Form, IMessageFilter I also have this implemented bool...
7
by: Michael Culley | last post by:
I've added an IMessageFilter to my app but I don't get messages or I get only a few and then it stops. My code is very simple. Am I doing something wrong? public class MF : IMessageFilter {...
1
by: Neil Stevens | last post by:
Hi, I am in the process of developing a popup utility for a project i am working on, the basic idea is that when a user presses the control key a popup menu will be displayed listing the shortcut...
4
by: GrandpaB | last post by:
Hi, I recently had a post about how to block Mousewheel events. The answer was to implement an IMessageFilter. Sadly, I must report that after 24 hours of researching my library and online...
1
by: newscorrespondent | last post by:
I set up an IMessageFilter in an attempt to trap the WM_QUIT message from a plain C# windows forms application. I never get the WM_QUIT message. How come? I also get a number of messages that...
1
by: JDeats | last post by:
If you create a new C# Windows Application project in Visual Studio.NET 2003 or 2005 and proceed to. 1. Make default form size 800x600 2. Drop a CheckBoxList control and dock it to the left 3....
2
by: deciacco | last post by:
IMessageFilter interface allows one to capture messages before they are sent to a control or a form. Is there a way, perhaps by implementing another interface, to capture all messages to an exe. ...
0
by: ah.ping.luk | last post by:
Dear All, i want to catch the application event (WM_CLOSE) in a user control. i create a class that implement the IMessageFIlter interface as follow: ...
0
by: jhop | last post by:
Hello everyone, I am having a slight problem with a program i am working on for a class, I am using Visual Studio 2005. The program only allows the up arrow key as input. In the code it is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.