Sign in to follow this  
Followers 0
Linda

makng If _IsPressed("01",$dll) more robust ?

6 posts in this topic

Hi,

And no i am not producing an keylogger,but a simple recorder for taking some screenshots and make some steps fully automatically between language versions of a webpage (recording a base version and play the "click path" on the language versions meanwhile taking screenshots)

Now, to my suprise _isPressed seems to be a bit so-so when it comes to actually fires upon click. I have to add that i have "a lot" on cpu things going on here. The _isPressed function is within a while loop and there are two screencapture ongoing...resize them with freeImage library etc so it might depend on that...but still..it miss some events.

Dont know what to share..but the code is straightforwad..something like:

if ($isActive==1) Then
        If _IsPressed("01",$dll) Then
        $voice = ObjCreate("SAPI.SpVoice")
        $voice.Speak ("ok")
        $voice = ""

 ToolTip("Now perform the Actions")

$pos = MouseGetPos()
_XMLCreateChildWAttr("parent/Item[1]", "mousex", "value", $pos[0])
_XMLCreateChildWAttr("parent/Item[1]", "mousey", "value", $pos[1])

 ConsoleWrite($pos[0] & "," & $pos[1])
 $counter=$counter+1

$hBMPs=_ScreenCapture_Capture("",$pos[0]-150, $pos[1]-150,$pos[0]+150,$pos[1]+150)
$hBmp = _ScreenCapture_Capture ("")

Any insights ?

Thanks!

Share this post


Link to post
Share on other sites



A working example would be nice. I can't replicate your issue.

I've created a monitoring script that counts mouseclicks:

#include<misc.au3>
$i = 1
While True
    If _IsPressed("01") Then
        ConsoleWrite($i & @CRLF)
        $i += 1
        While _IsPressed("01")
            Sleep(10)
        WEnd
    Else
        Sleep(10)
    EndIf
WEnd

And use this to send 1000 clicks in 40 sec: (be carefull running that. Make sure you're mouse is in a spot where the clicking won't trigger a response and start the script with the keyboard)

Opt("MouseClickDownDelay",20)
Opt("MouseClickDelay",20)
MouseClick("Left",Default,Default,1000)

The capturing script always returns 1000 for me, meaning that both the first and the second _IsPressed perform as expected, or that through some amazing coinsidence their errors canceled eachother out. Every time I tried it.

I'm guessing that your script doesn't always get to the _IsPressed line during a mouseclick.

An other option is interference from a combination of physical and scripted mouseclicks. You don't want to combine the two when using _IsPressed.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi Tvern,

Thanks for that. Yes your script seems to work as inteded.But when i add a screencap it simply cant keep up with the clicks. I am also adding some XML elements (_XMLDOMWrapper) inside the loop upon left click. Is this a cpu problem ? Since there are no callbacks from these function how am i suppose to know when they finish..somehow i need to simply prevent futher clicks until they have all finished.

just add this for simplicty and see if it works for you.If like mine,you wont hear "ok" and the consolwrite.

Cheers from Sweden! =)

Global $counter
Global $isActive=1
Global $dll = DllOpen("user32.dll")

While 1

if ($isActive==1) Then
If _IsPressed("01",$dll) Then
 $voice = ObjCreate("SAPI.SpVoice")
    $voice.Speak ("ok")
    $voice = ""

$pos = MouseGetPos()
;Add mouse coord attr.
;_XMLCreateChildWAttr("parent/Item[1]", "mousex", "value", $pos[0])
;_XMLCreateChildWAttr("parent/Item[1]", "mousey", "value", $pos[1])

   ConsoleWrite($pos[0] & "," & $pos[1])
 $counter=$counter+1

$hBmp = _ScreenCapture_Capture ("")

_ScreenCapture_SaveImage (@ScriptDir&"\image\Image_seq"&$counter&".jpg", $hBmp)


;_XMLCreateChildWAttr("parent/Item[1]", "image", "value", @ScriptDir&"\image\Image_seq"&$counter&".jpg")
;_XMLCreateChildWAttr("parent/Item[1]", "imageZoom", "value", @ScriptDir&"\image\Image_seq_zoom"&$counter&".jpg")
;_XMLCreateChildWAttr("parent/Item[1]", "comment", "value", GUICtrlRead($edit2))


EndIf

 While _IsPressed("01")
        Sleep(10)
        WEnd




   EndIf



   Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btn
                


            Case $button1
                ;Parse the xml and play!
            Case $button2
                
            Case $buttonclose
                ExitLoop
        GUIDelete()



Case Else
        EndSwitch

WEnd
Edited by Linda

Share this post


Link to post
Share on other sites

That helps. I can replicate your problem now.

_IsPressed can only function if the script reaches that line while you still have the mouse down. At first I thought that creating the speach object and the screencapture took allot of time, but my test script. (basically just a bunch of added consolewrites) shows that it's just the speach not returning untill it's done saying "ok". Which takes 1.3 sec and gives plenty of time for keypresses that would go unregistered.

I know that sounds can be played in the background, so maibe you'd have to record a sound and include that in the script. Perhaps the speach object can be implemented in a different way. Either way that's where the problem is coming from.

Here is the script I used to pin down the issue:

#include <ScreenCapture.au3>
#include <misc.au3>
Global $counter
Global $isActive = 1
Global $dll = DllOpen("user32.dll")


While 1
    If ($isActive == 1) Then
        If _IsPressed("01", $dll) Then
            Local $timer = TimerInit()
            $voice = ObjCreate("SAPI.SpVoice")
            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)
            $voice.Speak("ok")
            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)
            $voice = ""
            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)
            $pos = MouseGetPos()
            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)
            $counter = $counter + 1
            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)
            $hBmp = _ScreenCapture_Capture("")
            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)
            _ScreenCapture_SaveImage(@ScriptDir & "\image\Image_seq" & $counter & ".jpg", $hBmp)
            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)

            ConsoleWrite(Round(TimerDiff($timer),0) & "ms. Line " & @ScriptLineNumber-1 & @CRLF)
            ConsoleWrite($pos[0] & "," & $pos[1] & @CRLF)
        EndIf
        While _IsPressed("01")
            Sleep(10)
        WEnd
    EndIf

    Switch GUIGetMsg()
        Case -3

            ExitLoop
    EndSwitch

WEnd

And here is the script with duggested changes:

#include <ScreenCapture.au3>
#include <misc.au3>
Global $counter
Global $isActive = 1
Global $dll = DllOpen("user32.dll")
$voice = ObjCreate("SAPI.SpVoice") ;<<<<< creating the object outside the loop should speed things up. (if you keep using this object)

While 1
    If ($isActive == 1) Then
        If _IsPressed("01", $dll) Then
            $voice.Speak("ok") ;<<<<< some non-blocking sound output here.
            $pos = MouseGetPos()
            ConsoleWrite($pos[0] & "," & $pos[1] & @CRLF)
            $counter = $counter + 1
            $hBmp = _ScreenCapture_Capture("")
            _ScreenCapture_SaveImage(@ScriptDir & "\image\Image_seq" & $counter & ".jpg", $hBmp)
            _WinAPI_DeleteObject($hBmp) ;<<<Deleting the bitmap handle to free up memory.
        EndIf
        While _IsPressed("01")
            Sleep(10)
        WEnd
    EndIf

    Switch GUIGetMsg()
        Case -3

            ExitLoop
    EndSwitch

WEnd

$voice = "" ;<<<<< take this outside the loop too.

If your _XML stuff takes a long time you might still run into similar problems, but it shouldn't be nearly as notable as the 1.3 seconds the sound takes.

If I get the time I'll have a look for background sound playback.

Share this post


Link to post
Share on other sites

Tvern,

That is brilliant! It works! Very clever to use that debug method,thank you thank you thank you ! :);)

I can solve the feedback thing (sound in this case) in a other way.

Again,very very kind of you to actually do all this just ..solving my problem..!

Have a nice day Tvern!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It's a pleasure when the response is this positive. Good luck with the script!

Edit: Just found out that "$voice.Speak("ok",1)" results in background playback.

Edited by Tvern

Share this post


Link to post
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
Sign in to follow this  
Followers 0