txomin 0 Posted August 31, 2007 (edited) Hi everybody, I would like to write some sort of screen saver app, but I'm not sure what would be the best way to have my script to terminate when the user: - moves the mouse OR - press a key on the keyboard or mouse Any suggestions? Edited August 31, 2007 by txomin Share this post Link to post Share on other sites
chenxu 0 Posted August 31, 2007 Hi everybody,I would like to write some sort of screen saver app, but I'm not sure what would be the best way to have my script to terminate when the user:- moves the mouseOR- press a key on the keyboard or mouseAny suggestions?write a while loop to check if the mouse moved or some key pressed, is it happened, exit the script, it seems not very difficult to do what you need Share this post Link to post Share on other sites
txomin 0 Posted August 31, 2007 (edited) write a while loop to check if the mouse moved or some key pressed, is it happened, exit the script, it seems not very difficult to do what you need The only thing I have is to exit on mouse move: While 1 $mpos = MouseGetPos() Sleep(200) if $mpos <> MouseGetPos() then Exit Wend How do I know if there has been a Mouse click? (A function MouseGetClick does not exit) How do I know if user typed on the keyboard? What about the MouseWheel? Anybody knows? Edited August 31, 2007 by txomin Share this post Link to post Share on other sites
chenxu 0 Posted August 31, 2007 The only thing I have is to exit on mouse move: While 1 $mpos = MouseGetPos() Sleep(200) if $mpos <> MouseGetPos() then Exit Wend How do I know if there has been a Mouse click? (A function MouseGetClick does not exit) How do I know if user typed on the keyboard? What about the MouseWheel? Anybody knows?remember the last position of you mouse, and use MouseGetPos to check whether the position has changed to determine whether some key pressed, look into the function _IsPressed Share this post Link to post Share on other sites
PantZ4 0 Posted August 31, 2007 How do I know if there has been a Mouse click? (A function MouseGetClick does not exit) How do I know if user typed on the keyboard? What about the MouseWheel? Anybody knows? About the mouse wheel, here is a little code I have produced myself. GUIRegisterMsg(0x020A ,"CheckMouseWheel") Func CheckMouseWheel($hWndGUI, $MsgID, $WParam, $LParam) If $WParam = 0x00780000 Then ;MouseWheel Up ElseIf $WParam = 0xFF880000 Then ;MouseWheel Down EndIf EndFunc I'm not sure about the values, it worked on my Win XP Home SP2. Hope it can help you Share this post Link to post Share on other sites
txomin 0 Posted September 1, 2007 (edited) Yep, I saw _IsPressed, but it allows a single key check: include <Misc.au3> $dll = DllOpen("user32.dll") While 1 Sleep ( 250 ) If _IsPressed("23", $dll) Then MsgBox(0,"_IsPressed", "End Key Pressed") ExitLoop EndIf WEnd DllClose($dll) I would like to check for all keys at the same time... Anyway, if I don't find anything better I would use a For cicle inside the While cicle... hopefully the cpu usage will not increase too much Edited September 1, 2007 by txomin Share this post Link to post Share on other sites
txomin 0 Posted September 1, 2007 (edited) Just to share with the community... #include <Misc.au3> Func ExitOnSSEvent() $dll = DllOpen("user32.dll") $mposx = MouseGetPos(0) $mposy = MouseGetPos(1) While 1 Sleep(50) If ($mposx <> MouseGetPos(0)) or ($mposy <> MouseGetPos(1)) Then ExitLoop For $i= 1 to 165 If _IsPressed(Hex ($i,2), $dll) Then ExitLoop Next Wend DllClose($dll) EndFunc ExitOnSSEvent() Please tell me if you find something should be different from your perspective. Thank you Edited September 2, 2007 by txomin Share this post Link to post Share on other sites
txomin 0 Posted September 3, 2007 Little update... #include <Misc.au3> Func ExitOnSSEvent() $dll = DllOpen("user32.dll") $mposx = MouseGetPos(0) $mposy = MouseGetPos(1) While 1 Sleep(50) If ($mposx <> MouseGetPos(0)) or ($mposy <> MouseGetPos(1)) Then Exit For $i= 1 to 165 If _IsPressed(Hex ($i,2), $dll) Then Exit Next Wend DllClose($dll) EndFunc ExitOnSSEvent() Share this post Link to post Share on other sites
therks 33 Posted September 6, 2007 Hey, just found this thread from your bug report actually, but I had something I wanted to add. I created this function, it's a modified form of a function that I believe Gary wrote. Sleep(1000) ; Wait a second before getting the lastactive otherwise the script detects movement/keypress and exits right away Global $i_LastActive = _LastActive() While 1 ToolTip(@SEC) ; So you can see the script is active Sleep(1) If $i_LastActive <> _LastActive() Then ExitLoop WEnd Func _LastActive($v_User32Dll = 'user32.dll') Local $str_LastInput = DllStructCreate('uint;dword') DllStructSetData($str_LastInput, 1, DllStructGetSize($str_LastInput)) DllCall($v_User32Dll, 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($str_LastInput)) Return DllStructGetData($str_LastInput, 2) EndFunc My AutoIt Stuff | My Github Share this post Link to post Share on other sites
txomin 0 Posted September 6, 2007 Hey, just found this thread from your bug report actually, but I had something I wanted to add. I created this function, it's a modified form of a function that I believe Gary wrote. Sleep(1000) ; Wait a second before getting the lastactive otherwise the script detects movement/keypress and exits right away Global $i_LastActive = _LastActive() While 1 ToolTip(@SEC) ; So you can see the script is active Sleep(1) If $i_LastActive <> _LastActive() Then ExitLoop WEnd Func _LastActive($v_User32Dll = 'user32.dll') Local $str_LastInput = DllStructCreate('uint;dword') DllStructSetData($str_LastInput, 1, DllStructGetSize($str_LastInput)) DllCall($v_User32Dll, 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($str_LastInput)) Return DllStructGetData($str_LastInput, 2) EndFunc I must say that this script is even better! Thank you Saunders Share this post Link to post Share on other sites
maqleod 1 Posted September 6, 2007 just a suggestion, I would have one script be the screensaver and have a second one (a gui) actually do the detecting of mouse movement or keystroke to terminate the other, or to activate it if it doesn't detect anything after a while or the user initiates it. [u]You can download my projects at:[/u] Pulsar Software Share this post Link to post Share on other sites