Conditional no-user-activity trigger

Asked by Hatim

Hello

I was wondering if sikuli has the ability to monitor user no-action for a time threshold and then perform SAVE and CLOSE action on a specific windows app. What are the triggers to do such a thing.

Thanks in advance

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Hatim
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Since everything with SikuliX is visual, it depends, how you are able to visually track activity/inactivity.

Another option might be, to continually track the mouse position and do your job, if the mouse is no longer moved for some time.

lastPos = Mouse.at()
lastMove = time.time()
maxWait = 15 #seconds
saved = False
while True:
    wait(1)
    currentPos = Mouse.at()
    if lastPos.x == currentPos.x and lastPos.y == currentPos.y:
        if lastMove + maxWait < time.time and not saved:
            #here you should do your actions
            saved = True
    else:
        lastMove = time.time()
        lastPos = currentPos

... you might add something, to make this endless loop interruptible - otherwise you have to kill it.

Revision history for this message
Hatim (hatim.eissa) said :
#2

OK great. I'll try it out.
Thanks a lot

On Thu, Mar 2, 2017 at 1:19 AM, RaiMan <<email address hidden>
> wrote:

> Your question #497368 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/497368
>
> Status: Open => Answered
>
> RaiMan proposed the following answer:
> Since everything with SikuliX is visual, it depends, how you are able to
> visually track activity/inactivity.
>
> Another option might be, to continually track the mouse position and do
> your job, if the mouse is no longer moved for some time.
>
> lastPos = Mouse.at()
> lastMove = time.time()
> maxWait = 15 #seconds
> saved = False
> while True:
> wait(1)
> currentPos = Mouse.at()
> if lastPos.x == currentPos.x and lastPos.y == currentPos.y:
> if lastMove + maxWait < time.time and not saved:
> #here you should do your actions
> saved = True
> else:
> lastMove = time.time()
> lastPos = currentPos
>
> ... you might add something, to make this endless loop interruptible -
> otherwise you have to kill it.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/497368/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/497368
>
> You received this question notification because you asked the question.
>

Revision history for this message
Hatim (hatim.eissa) said :
#3

Actually what you provided seems very reasonable to me. But unfortunately I
didn't get the time to try it out until now. Hopefully to test it tonight
or tomorrow morning. I'll let you know asap.

Thanks a lot for your concern really
On Thu, Mar 2, 2017 at 9:30 PM Hatim <email address hidden>
wrote:

> Your question #497368 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/497368
>
> Status: Answered => Open
>
> You are still having a problem:
> OK great. I'll try it out.
> Thanks a lot
>
> On Thu, Mar 2, 2017 at 1:19 AM, RaiMan <
> <email address hidden>
> > wrote:
>
> > Your question #497368 on Sikuli changed:
> > https://answers.launchpad.net/sikuli/+question/497368
> >
> > Status: Open => Answered
> >
> > RaiMan proposed the following answer:
> > Since everything with SikuliX is visual, it depends, how you are able to
> > visually track activity/inactivity.
> >
> > Another option might be, to continually track the mouse position and do
> > your job, if the mouse is no longer moved for some time.
> >
> > lastPos = Mouse.at()
> > lastMove = time.time()
> > maxWait = 15 #seconds
> > saved = False
> > while True:
> > wait(1)
> > currentPos = Mouse.at()
> > if lastPos.x == currentPos.x and lastPos.y == currentPos.y:
> > if lastMove + maxWait < time.time and not saved:
> > #here you should do your actions
> > saved = True
> > else:
> > lastMove = time.time()
> > lastPos = currentPos
> >
> > ... you might add something, to make this endless loop interruptible -
> > otherwise you have to kill it.
> >
> > --
> > If this answers your question, please go to the following page to let us
> > know that it is solved:
> >
> https://answers.launchpad.net/sikuli/+question/497368/+confirm?answer_id=0
> >
> > If you still need help, you can reply to this email or go to the
> > following page to enter your feedback:
> > https://answers.launchpad.net/sikuli/+question/497368
> >
> > You received this question notification because you asked the question.
> >
>
> --
> You received this question notification because you asked the question.
>

Revision history for this message
RaiMan (raimund-hocke) said :
#4

no problem, take your time.

Of course I am happy, if my ideas help others.
But my main motivation is, to find out, wether a situation can be supported with SikuliX. If not, it might be something to think about becoming a feature or amendment.

Revision history for this message
Hatim (hatim.eissa) said :
#5

I've been looking at the code you suggested and thought that the point
where Mouse.at() is should be specific, which is not the case here. What if
i wanted the mouse pointer to be any where on the screen and not moving for
the defined time before taking action.
Is there any way that i can define my mouse pointer position to be anywhere
on the screen?

Thanks in advance

On Fri, Mar 3, 2017 at 2:44 PM, RaiMan <<email address hidden>
> wrote:

> Your question #497368 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/497368
>
> Status: Open => Answered
>
> RaiMan proposed the following answer:
> no problem, take your time.
>
> Of course I am happy, if my ideas help others.
> But my main motivation is, to find out, wether a situation can be
> supported with SikuliX. If not, it might be something to think about
> becoming a feature or amendment.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/497368/+confirm?answer_id=3
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/497368
>
> You received this question notification because you asked the question.
>

Revision history for this message
Hatim (hatim.eissa) said :
#6

I figured it out.

Thanks for your help.