Jump to content

How to detect if mouse had moved


leuce
 Share

Recommended Posts

G'day everyone

I created a script that takes a fullscreen screenshot once a minute, so that I can check at the end of the day what my kids did on the computer (I don't need any more information than once a minute). However, if they're watching a movie, or if they had gotten up to play outside for a while, the script takes unnecessary screenshots. I thought a reasonably simple way to detect the presence of a human is to ask whether the mouse had moved.

Original script:

#include <date.au3>
#include <ScreenCapture.au3>

SnapDeSnap() ; first snap when script starts

While 1
Sleep ("60000")
SnapDeSnap ()
WEnd

Func SnapDeSnap()
$nowdatetime = StringReplace (StringReplace (_NowCalc(), "/", "-"), ":", "-")
_ScreenCapture_SetJPGQuality(75)
_ScreenCapture_Capture($nowdatetime & " " & @UserName & ".jpg", 0, 0, -1, -1, True)
EndFunc

However, after updating my script with what I had thought would work, it still takes a screenshot every minute, even if I'm not at the computer for several minutes (and no, it aint the cat). Can anyone tell me what is wrong with the updated script?

Updated script:

#include <date.au3>
#include <ScreenCapture.au3>

SnapDeSnap() ; first snap when script starts

While 1
$mousewhereone = MouseGetPos ()
Sleep ("60000")
$mousewheretwo = MouseGetPos ()
If $mousewhereone <> $mousewheretwo Then
SnapDeSnap ()
EndIf
WEnd

Func SnapDeSnap()
$nowdatetime = StringReplace (StringReplace (_NowCalc(), "/", "-"), ":", "-")
_ScreenCapture_SetJPGQuality(75)
_ScreenCapture_Capture($nowdatetime & " " & @UserName & ".jpg", 0, 0, -1, -1, True)
EndFunc

Added:

By the way, in case there is confusion: I don't want a screenshot taken as soon as the mouse moves. I still want one screenshot every minute, but I don't want a screenshot if the mouse didn't move in the past minute.

Thanks in advance

Samuel

Edited by leuce
Link to comment
Share on other sites

i don't think you could two 'arrays' like that. Compare their elements.

Yes, I had hoped that I could keep the code short, but I had a nagging feeling about exactly what you say here. And it worked (thanks!):

While 1
$mousewhereone = MouseGetPos ()
$mousewhereonecalc = $mousewhereone[0] & " " & $mousewhereone[1]
Sleep ("60000")
$mousewheretwo = MouseGetPos ()
$mousewheretwocalc = $mousewheretwo[0] & " " & $mousewheretwo[1]
If $mousewhereonecalc <> $mousewheretwocalc Then
SnapDeSnap ()
EndIf
WEnd

Samuel

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...