Mouse/Key Messages in Windows Service
-
I would like to be able to perform background work in my C# .net Windows Service if no mouse messages or key messages have be received for 10 minutes. It involves downloading, uploading and processing, I would like to be able to tell if the computer has been idle from the user to a 10 minute period and then I would start these routines/processes. I see how to do this with Forms with overriding the WinProc method, but I need Windows Messages for a Service, and I think the Forms WinProc method only gets events when the mouse is moved over top of it. I need Messages that occure anywhere within Windows/OS/Desktop. Is there any Windows API methods to import or any idea how to do this? Thanks in advance.
-
I would like to be able to perform background work in my C# .net Windows Service if no mouse messages or key messages have be received for 10 minutes. It involves downloading, uploading and processing, I would like to be able to tell if the computer has been idle from the user to a 10 minute period and then I would start these routines/processes. I see how to do this with Forms with overriding the WinProc method, but I need Windows Messages for a Service, and I think the Forms WinProc method only gets events when the mouse is moved over top of it. I need Messages that occure anywhere within Windows/OS/Desktop. Is there any Windows API methods to import or any idea how to do this? Thanks in advance.
krisp wrote: I see how to do this with Forms with overriding the WinProc method, but I need Windows Messages for a Service, and I think the Forms WinProc method only gets events when the mouse is moved over top of it. I need Messages that occure anywhere within Windows/OS/Desktop. You'll need to use a system-wide hook DLL, which cannot be written from C# - you'll probably want to write it in C++. You can then use this from your C# application.
**"Worry not that no one knows of you; seek to be worth knowing." -- Confucius
-
I would like to be able to perform background work in my C# .net Windows Service if no mouse messages or key messages have be received for 10 minutes. It involves downloading, uploading and processing, I would like to be able to tell if the computer has been idle from the user to a 10 minute period and then I would start these routines/processes. I see how to do this with Forms with overriding the WinProc method, but I need Windows Messages for a Service, and I think the Forms WinProc method only gets events when the mouse is moved over top of it. I need Messages that occure anywhere within Windows/OS/Desktop. Is there any Windows API methods to import or any idea how to do this? Thanks in advance.
If you are using Windows 2000 or above, you can use the GetLastInputInfo API call. You get a structure with the tick count when the last input event happened.
-
I would like to be able to perform background work in my C# .net Windows Service if no mouse messages or key messages have be received for 10 minutes. It involves downloading, uploading and processing, I would like to be able to tell if the computer has been idle from the user to a 10 minute period and then I would start these routines/processes. I see how to do this with Forms with overriding the WinProc method, but I need Windows Messages for a Service, and I think the Forms WinProc method only gets events when the mouse is moved over top of it. I need Messages that occure anywhere within Windows/OS/Desktop. Is there any Windows API methods to import or any idea how to do this? Thanks in advance.
I've a similar question. I'm being with a project which can create shortcuts for windows. Is it possible to get a signal if for example the "P" button is pressed Jonathan Slenders
-
If you are using Windows 2000 or above, you can use the GetLastInputInfo API call. You get a structure with the tick count when the last input event happened.
Awesome, thanks alot Jeff, that is exaclty what I needed, i guess I can just call it in a seperate thread every minute or so. Thanks again :) The GetLastInputInfo function retrieves the time of the last input event. Syntax: BOOL GetLastInputInfo( PLASTINPUTINFO plii ); Parameters: plii - [out] - Pointer to a LASTINPUTINFO structure that receives the time of the last input event. Return Value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Remarks: This is useful for input idle detection. Function Information: Header Declared in Winuser.h, include Windows.h Import library User32.lib Minimum operating systems Windows 2000 See Also: Keyboard Input, LASTINPUTINFO