Jump to content

can the script stop running by itself when someone use pc?


 Share

Recommended Posts

Is there any way the script stop running by itself when it figures out someone using the mouse? Since the script is auto clicking and I want it stop automatically when someone use my pc while i'm away.

Edited by dangbeau
Link to comment
Share on other sites

You don't need to run your scripts on the desktop.  You can run it on the service level (session 0), and then not worry about any user messing it up.

There is a function=_Timer_GetIdleTime, but your script will trigger it (if it sends keys or moves the mouse), so the user action wouldn't matter.  But you could do adlibregister with that function, and if the timer resets, then sleep until the timer goes over some set amount of time.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

There are several ways to do this, but the simplest might be to use BlockInput and stop anyone else using your PC altogether until a Hotkey is clicked. Be sure you read up on BlockInput though, as you don't want to block that Hotkey. As for the Hotkey, look at the _IsPressed command .... making sure you use the DLL version for repeated calls/checks on a regular basis.

Another method is to regularly check your mouse position.

Personally, I would combine all the above ... both enabling and disabling BlockInput at key moments, providing window of opportunity pauses perhaps. You really do not want an auto-click to go astray.

BE CAREFUL with BlockInput.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • Moderators

@dangbeau it would also help to know what you're trying to accomplish. In all likelihood you could get away from using the mouse if you employ the Control commands. Then it wouldn't matter as much if someone moved the mouse.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Another thought.  If you are interacting with a specific window, then you can create an AdLibRegister to call a function to sleep if that window is not active.

So if a user clicks into a new window, your script will sleep until your window is active again.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Here is a simple but effective way of doing that. It's based on knowing where the mouse clicks, which you obviously do, seeing as how you wrote the code.

In the example the array of expected mouse positions is hard coded, you can change them as you wish if your script has dynamic positions. Please try to figure out how, for yourself. (hint: you should only need two entries in array, where the mouse is, and where it is going to be next)

Global $aMousePositions[3][2]
$aMousePositions[0][0] = 200
$aMousePositions[0][1] = 200

$aMousePositions[1][0] = 300
$aMousePositions[1][1] = 300

$aMousePositions[2][0] = 400
$aMousePositions[2][1] = 400

HotKeySet("{Esc}", "_Exit")
AdlibRegister("_CheckUserMovedMouse")

While 3
    For $i = 0 To UBound($aMousePositions) - 1
        MouseMove($aMousePositions[$i][0], $aMousePositions[$i][1], 0)
        Sleep(1000)
    Next
WEnd


Func _CheckUserMovedMouse()
    Local $aMousePos = MouseGetPos()
    For $i = 0 To UBound($aMousePositions) - 1
        If ($aMousePos[0] = $aMousePositions[$i][0] And $aMousePos[1] = $aMousePositions[$i][1]) Then
            Return ; Mouse is one of your predefined positions;
        EndIf
    Next
    MsgBox(0, "User Active", "Exiting") ; Someone moved mouse.
    Exit
EndFunc   ;==>_CheckUserMovedMouse

EDIT: Obviously I used Move instead of Click, for demonstration purpose.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Since JohnOne was so kind to give an example, I modified it for my thought as well :)

#include <WinAPI.au3>
$iPid = Run("Notepad.exe")
Sleep(2000)

HotKeySet("{Esc}", "_Exit")
AdlibRegister("_PauseIfProcessWinNotActive",500)

Func _PauseIfProcessWinNotActive()
    Local $iTempPid

    _WinAPI_GetWindowThreadProcessId(WinGetHandle("[ACTIVE]"),$iTempPid)
    While $iTempPid <> $iPid

        ConsoleWrite("I'm sleeping!!" & @CRLF)
        Sleep(1000)
        _WinAPI_GetWindowThreadProcessId(WinGetHandle("[ACTIVE]"),$iTempPid)
    WEnd

    ConsoleWrite("I'm not sleeping!!" & @CRLF)
EndFunc   ;==>_CheckUserMovedMouse



Func _Exit()
    Exit
EndFunc



; this will actually be your script:
While True
WEnd

As long as the notepad started...or some window spawned from that process (such as a save as window) is active, the console will output "I'm not sleeping!!"...make anything else active, then you will see console output "I'm sleeping!!"

If you are working with multiple PIDs then you can create an array, and keep adding to it as you create them...then in the adlib func, loop through that array and see if the temppid matches anything in the array (loop through the array)...

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...