Jump to content
JScript

_AdlibEnhance.au3 (UDF) - Call functions with parameters, pause and resume!

Recommended Posts

JScript

Function Reference


_AdlibEnhance.au3

Adlib function with support for parameters, pause and resume using Call Back!

Sintax:

_Adlib_Register( "Function" [, "Params" [, Time [, RepeatCount ]]] )
_Adlib_Pause( "Function" )
_Adlib_Resume( "Function" )
_Adlib_SetTimer( "Function" [, Time ] )
_Adlib_UnRegister( "Function" )

Supports:

; You can call functions with parameters and native functions also!

Downloads:

Version: 0.10

_AdlibEnhance_(RedirectLink).html

Note: Usage example is included!

Sample:

Posted Image

Fixes:

  • 0.10.1612.2600b
  • 16/10/2012 -> First release!


Regards,

João Carlos.

  • Like 3

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites
darthwhatever

Nice!

Is there any way to call the function with different parameters every time?

the way it it right now, the parameters are stored when _Adlib_Register() is called.

; #FUNCTION# ====================================================================================================================
; Name...........: _Adlib_SetParams
; Description ...: Pauses the Enhanced Adlib functionality for defined function.
; Syntax.........: _Adlib_Pause( "Function", "Params" )
; Parameters ....: Function - The name of the adlib function to pause.
;                  Params - The new parameter(s).
; Return values .: Success - Return 1
; Failure - Return 0
; Author ........: darthWhatever
; Modified.......:
; Remarks .......:
; Related .......: _Adlib_Resume, _Adlib_Register, _Adlib_UnRegister, _Adlib_SetTimer
; Link ..........;
; Example .......; _Adlib_SetParams( "MyFunction", "NewParam1|NewParam2" )
; ===============================================================================================================================
Func _Adlib_SetParams($sFuncName, $sParams)
Local $iIndex = __ADB_GetIndex($sFuncName)
If Not $iIndex Then Return 0
$avADB_CALLS[$iIndex][1] = $sParams
Return 1
EndFunc ;==>_Adlib_SetParams
  • Like 1

[font=arial, sans-serif]How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?[/font][font=arial, sans-serif]<div>This is how you annoy a web developer.</span>[/font]

Share this post


Link to post
Share on other sites
IanN1990

#include "_AdlibEnhance.au3"
_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 500, 1)

While 1
sleep(250)
WEnd

Func _Exit($sTitle, $sText)
ConsoleWrite("Why Does it crash? Exit code: -1073741819" & @CRLF)
EndFunc ;==>_Exit

Taken from your example, every time i try a counted Register. It crashes when it reaches its timer?

Is this the same for anyone else ? Is this how that function is meant to work ?

Edited by IanN1990

Share this post


Link to post
Share on other sites
JScript

Or I did not understand or I do not know what you're talking about!

The above example had no problems for me, it works normal... :huh:

What is the OS you use, which version of AutoIt?

My SciTE output:

>"D:Program FilesAutoIt3SciTEAutoIt3WrapperAutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "D:DropboxAutoIt v3 - ProjectsAdlibEnhanceExample.au3" /UserParams
+>20:35:07 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0416 Keyboard:00010416 OS:WIN_7/ CPU:X64 OS:X86)
>Running AU3Check (1.54.22.0) from:D:Program FilesAutoIt3
+>20:35:07 AU3Check ended.rc:0
>Running:(3.3.8.1):D:Program FilesAutoIt3autoit3.exe "D:DropboxAutoIt v3 - ProjectsAdlibEnhanceExample.au3"
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
+>20:35:20 AutoIT3.exe ended.rc:0
>Exit code: 0 Time: 14.344

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites
IanN1990

Fixed.

I forgot on the laptop ages ago i switched the autoit and autoit64.exe "cant remember why*.

Your Scite Output plus the fact the code worked fine on my dads pc but not the laptop help spark the idea as well.

Sorry for the confusion.

Edited by IanN1990

Share this post


Link to post
Share on other sites
IanN1990

It works, there isnt a problem any more so theres not much output for me to post :D

In the Autoit File i had the 64bit version named 32 "so by default autoit always ran 64 bit". I fear this is what was causing the problem because when i put back the 2 separate version.

AutoIt3.exe

AutoIt3_x64.exe

It works fine again :) So the problem was my fault.

On a completely different note.

#include "_AdlibEnhance.au3"

While 1
sleep(1000)
_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 2000, 1)
WEnd

Func _Exit($sTitle, $sText)
ConsoleWrite("_Exit Has RuN" & @CRLF)
EndFunc ;==>_Exit

The code only runs once, this might be a silly thought but wouldn't it be better when $Count reaches its set limit and the Adlib has finished, the function itself should be de registered as well. So it could be called again later if needed?

Edited by IanN1990

Share this post


Link to post
Share on other sites
JScript

_Adlib_Register( "Function" [, "Params" [, Time [, RepeatCount ]]] )

So

_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 2000)

Runs forever!

Try this:

#include "_AdlibEnhance.au3"

_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 2000)

While 1
    Sleep(1000)
WEnd

Func _Exit($sTitle, $sText)
    ConsoleWrite("_Exit Has RuN" & @CRLF)
EndFunc   ;==>_Exit

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites
IanN1990

hmm not quite what i ment :)

In my code i have a mouse hook, and as i am sure most people know you should not use sleeps, whiles or anything that delays code in a hook. It should be procressed and control returned as fast as possible. So for big codes i would call a AdlibRegister (which will prob be replaced in any event with this improved version :)". I just figured i could have some code that calls your fuction, with a count of 1. So it would only run once until the hook is triggered again.

Random Example i came up with might be like this. Its kinda bad but shows my mind-set ^^ (Yes its not the hook example but that code is long and a example would be complicated)

#include "_AdlibEnhance.au3"

local $hWnd = GUICreate("", 260, 100)
local $Button1 = GUICtrlCreateButton("Button1", 45, 0, 150, 20)
local $Button2 = GUICtrlCreateButton("Button2", 45, 75, 150, 20)
GUISetState()

While True
$Msg = GUIGetMsg()
     Switch $Msg
Case $Button1
_Adlib_Register("TimeOut", "Button1|", 250, 5)
Case $Button2
_Adlib_Register("TimeOut", "Button2|", 250, 5)
     EndSwitch
Wend

Func TimeOut($sTitle, $Text)
ConsoleWrite($sTitle & " Has been Pressed, This is a random function" & @CRLF)
EndFunc ;==>_Exit

So as you can see, you could only click one of the buttons only once, as once the count is finished. The Function is not unregistered and therefore cant be called again.

Edited by IanN1990

Share this post


Link to post
Share on other sites
Mechaflash

Nice UDF. Will be very useful for a few of my projects. Thanks!


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites
DAYANS

down link is broken..

Share this post


Link to post
Share on other sites
Leo1906

So this adlib works just like the normal adlib in Autoit except that you can parse params, right?

That means that the main script is beeing paused when the adlib is called?

 

Edit: even a MsgBox isn't stopping the adlib? :D
What is this? Some kind of "multithreading"?

Edit2: When limiting the calls of the adlib, the function get's automatically unregistered? So there is no need to unregister it myself?

Edited by Leo1906

Share this post


Link to post
Share on other sites
Surf243

Hi @JScript

I love this UDF, but I ran into an error when I used _Adlib_UnRegister.

When I ran the script below it would give me Array Errors

#include "_AdlibEnhance.au3"

Global $iCount = 0
_Adlib_Register("_Test1", "", 500)

While 1
    GUIGetMsg()
WEnd

Func _Test1()
    ConsoleWrite("(Stop @ 5)" & @TAB & "Count: " & $iCount & @CRLF)
    If $iCount = 5 Then
        _Adlib_UnRegister("_Test1")
        ConsoleWrite("Yes! Stopped @ " & $iCount & @CRLF)
    EndIf
    $iCount += 1
EndFunc

I played around a bit and found it works If I pause it first then unregister it.

So I modified the UDF function to kill the timer first as shown below:

Func _Adlib_UnRegister($sFuncName = "")
    Local $iIndex

    $iIndex = __ADB_GetIndex($sFuncName)
    If Not $iIndex Then Return 0
    
    __ADB_KillTimer($avADB_CALLS[$iIndex][4], $iIndex) ; Added This Line

    For $i = $iIndex To UBound($avADB_CALLS) - 2
        For $j = 0 To 9
            $avADB_CALLS[$i][$j] = $avADB_CALLS[$i + 1][$j]
        Next
    Next
    ReDim $avADB_CALLS[$avADB_CALLS[0][0]][10]
    $avADB_CALLS[0][0] -= 1

    Return 0
EndFunc   ;==>_Adlib_UnRegister

Now it works perfectly!

 

Share this post


Link to post
Share on other sites
Surf243

Sadness... 

_Adlib_Pause & _Adlib_UnRegister - Both functions crash when running 64-bit. 32-bit still works though.

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

  • Similar Content

    • Bilgus
      By Bilgus
      Apparently you can't use a function with variables for AdlibRegister
      Like you declare it with a variable even an optional one and it throws an error if you try and call it
      Thats ok though I figured out a hack using eval to get a better result
      Registered_Funct(250);Register Sleep(10000) Registered_Funct(-1);UnRegister Func Registered_Funct($iTime = -1) Local $i_Time = Eval("iTime") If $i_Time > 0 Then AdlibRegister("Registered_Funct", $i_Time) ElseIf $i_Time < 0 Then AdlibUnRegister("Registered_Funct") Else ConsoleWrite("Do Stuff") EndIf EndFunc
      Surely it has an impact on efficiency though...
    • Miliardsto
      By Miliardsto
      Is there any difference in timers and AdlibRegister ?
      in :
      performance usage reliability or any kind of difference I want use few timers at once so it will make difference.
      I have problem with timers and I saw AdlibRegister behaves similar like:
      wont stop crashing slowing program so much maybe is there any trick to make it better?
    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?
    • timmy2
      By timmy2
      I'm writing a small prog that will run in the background and sound an alarm if a certain Gmail message arrives in an otherwise unused account.
      My inclination is to use a simple While/WEnd loop with a 5 minute Sleep between checking for messages, but I've seen examples here of somewhat similar background tasks that employ AdlibRegister so I'm curious which method is the most reliable and least impactful on the CPU.  Below are two simple scripts that begin to do what I want and represent how I think this could be handled.
      While/WEnd with Sleep
      #include <CheckMail.au3> Global $aReturn Global $iEmails While 1 $aReturn = CheckMail("username", "password") $iEmails = @extended If $iEmails > 0 ExitLoop Sleep(300000) ; check for new messages every 5 minutes WEnd ;work with contents of $aReturn array that contains the new message(s) found  
      While/WEnd with Sleep and AdlibRegister
      #include <CheckMail.au3> Global $aReturn Global $iEmails = 0 AdlibRegister('_CallCheckMail',300000) ; check for new messages every 5 minutes While 1 Sleep(500000) ; I had to put something here. Does higher the value = less CPU demand? If $iEmails > 0 ExitLoop WEnd ;work with contents of $aReturn array that contains the new message(s) found Func _CallCheckMail $aReturn = CheckMail("username", "password") $iEmails = @extended Return EndFunc  
    • TheDcoder
      By TheDcoder

      AdlibRegister("ScriptBreaker", 1000 * 10) FileMove($large_10GB_file, $relocated_large_10GB_file) Func ScriptBreaker() Sleep(1000 * 10) EndFunc ; Will adlib break the file or pause the transfer??
×