Screensaver: keyboard and mouse hook and kill screensaver
-
In a application i writing, i want: - read if the user enabled system screen saver - read screen saver timeout - disable screen saver - the computer is connected to a external device: when this device is "sleeping", i starts to counts time and when it arrives to screen saver timeout, starts the screen saver. Until here i don't have problems: they start from here: - if the user move mouse or hit key, screen saver has to stop: is used this: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/3d9bb875-8e79-4c1e-b2ef-b24503e6abbd/how-to-create-a-keyboard-and-mouse-hook-in-visual-c-2005?forum=windowssdk[^] but it works only if the focus is on my application, don't works if focus it's on another window. - when the device "wake-up", the screen saver have to stop: i used this: http://msdn.microsoft.com/en-us/magazine/cc301462.aspx[[^](http://msdn.microsoft.com/en-us/magazine
/cc301462.aspx "New Window")] but it's works only the first time: if the screen saver starts another time it don't works no more; i have to exit and starts again my application and then it works again only one time. Thanks Drugo -
In a application i writing, i want: - read if the user enabled system screen saver - read screen saver timeout - disable screen saver - the computer is connected to a external device: when this device is "sleeping", i starts to counts time and when it arrives to screen saver timeout, starts the screen saver. Until here i don't have problems: they start from here: - if the user move mouse or hit key, screen saver has to stop: is used this: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/3d9bb875-8e79-4c1e-b2ef-b24503e6abbd/how-to-create-a-keyboard-and-mouse-hook-in-visual-c-2005?forum=windowssdk[^] but it works only if the focus is on my application, don't works if focus it's on another window. - when the device "wake-up", the screen saver have to stop: i used this: http://msdn.microsoft.com/en-us/magazine/cc301462.aspx[[^](http://msdn.microsoft.com/en-us/magazine
/cc301462.aspx "New Window")] but it's works only the first time: if the screen saver starts another time it don't works no more; i have to exit and starts again my application and then it works again only one time. Thanks DrugoI find a error in the thread code: i call stop to screen saver in the other thread, more slow, than the thread where check if is all in stop; so the first don't know that if is all stopped; now it works - i'm sorry. At the moment remains the problem regarding the hook: if i have the focus in my application, it works, but if i open the notepad and change focus, this hook don't works. Feel like the hook is "attacked" only on my application: It's due to the fact that the winthread object is called inside my application ? I have to change hook code ? Thank you Drugo
-
I find a error in the thread code: i call stop to screen saver in the other thread, more slow, than the thread where check if is all in stop; so the first don't know that if is all stopped; now it works - i'm sorry. At the moment remains the problem regarding the hook: if i have the focus in my application, it works, but if i open the notepad and change focus, this hook don't works. Feel like the hook is "attacked" only on my application: It's due to the fact that the winthread object is called inside my application ? I have to change hook code ? Thank you Drugo
Today i'm find the correct way to work; i don't know why, but i'm fixed on the way to count time for starts screen saver inside my application, so i need hooks; i try to use hooks (i need global hook) and it works, but i think it's better in another way: the correct way is leave the screen saver administration to the system and enable it or disable it when occurs; the correct way is: - Read if the screen saver is enabled from the system (so i know if i have to use it) - If disabled i do nothing - If enabled, disable it - Run all on my application - If device is sleeping for 1 minute, enable screen saver and reset counting - If device is current in use, disable screen saver and reset counting The rest it' better leave to the system: in this way i have only a delay of one minute for screen saver starting. Now it works fine; i'm sorry for these post. Thank you Drugo