Jump to content

Frequently Asked Questions (FAQs)


Recommended Posts

As a long time user of these forums, I have come to notice that many of the questions asked by first-time users are repeat questions that can sometimes be easily answered. Most of these answers are not provided in a reasonable time because a current forum user must search for the answer to the OP's question, thereby shifting the work from the OP to the forum frequenter. In other cases, the reponse is given in disgust or anger because the forum user has seen the question asked many times before. Therefore, I am here posting the answers to many of the newcomer's questions. I will number the questions to provide a simple and quick reference point that any forum user can link to.

Q1. How can I debug my script?

A1. This one has a myriad of answers, but the most effective is to begin by using the SciTE4AutoIt3 Editor to create or edit scripts. This program is useful in debugging for the following reasons:

  • Syntax highlighting allows for immediate viewing of any mistakes from unended script tags or quotes. This allows the scripter to visibly see the difference between the following incorrect code

Q18. Why isn't my thread getting any replies?

A1.
Did you give a good description of the problem? If your title or explanation of the issue is not descriptive, users are likely to bypass your issue instead of helping. Post titles such as "Help Me", "I Have A Problem", "Question", "Help me fix my code", "This code doesn't work" or similarly worded question titles will not readily draw forum users to your post. Experienced users (which are your best hope of resolving the issue) will often skip your post altogether in cases like this. An example of a post title descriptive enough to attract users to assist you is "Problem with WinWaitClose", or "Loop never ends".

A2.
Did you post example code? If you have not posted an example of the code you are having an issue with, then you will not recieve support. When posting a non-working script, please do so in the smallest amount of stand-alone code possible. If the code you post cannot run by itself on another person's computer, they will not be able to recreate the issue.

A3.
Did you use proper english? Here are guidelines for posting properly in the english language:
  • Use proper case. THIS IS CONSIDERED YELLING. if you post in ALL UPPERCASE or all lowercase, you look like a doofus when you do.
  • Use proper punctuation. Complete sentences need only one trailing punctuation mark, not three!!! Writing a sentance without simple punctuation such as commas or other punctuation is considered lazy, which is considered a good judge of the poster's coding style. If you cannot summon the strength to write a sentence with correct punctuation, you will most likely miss simple coding mistakes such as unterminated quotes.
EDIT: 11-15-06 - Added changes suggested by Larry and Paulie

Edited by Jon
Who else would I be?
Link to comment
Share on other sites

  • 1 year later...

Q2. How can I debug my script?

A2. You can also debug a script on any computer by adding the following code to your script:

This debugging is completely transparent to the user, and is only viewable with a program such as DebugView from SysInternals http://www.sysinternals.com/Utilities/DebugView.html ...

A broken link to be updated (?) to http://www.microsoft.com/technet/sysintern.../debugview.mspx
OS: Win XP Pro SP2, AutoIt Version: 3.2.8.1 / 3.2.9.10, SciTE: 1.74 11/15/2007
Link to comment
Share on other sites

  • 4 months later...

[Edit: Post retracted for technical imprecision.]

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

  • 1 month later...

I have often answered this question.

Why does the Ctrl key get stuck down after I run my script?

It could equally be the Shift or the Alt key.

If you use Send in a script and you have a problem with keys being stuck down then Send is the most likely culprit. A similar problem can occur with BlockInput. The solution is generally quite simple. If there is a key like Shfit or Alt held down at the start of the Send sequence, but that key is released by the time the Send sequence finishes then the key will get 'stuck' down. As an example of a solution, you could replace the Send function in your script with the _SendEx function below.

;Send the string $ss after the Shift Alt and Ctrl keys are released. Optionally give a warning after 1 sec if any of those keys still down.
;Requires misc.au3 to be included in the script for the _IsPressed function.
  Func _SendEx($ss,$warn = "")
      Local $iT = TimerInit()
      
      While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
          if $warn <> "" and TimerDiff($iT) > 1000 Then
              MsgBox(262144, "Warning", $warn)
          EndIf
        sleep(50)
      WEnd
      Send($ss)
      
  EndFunc;==>_SendEx

EDIT:

shilbiz discovered that the following single line can 'clear' locked down keys

ControlSend("", "", "", "text", 0)

I don't know how he came up with it but it seems to work!

EDIT 2: As explained above, the _SendEx function waits for the Shift, Alt and Ctrl keys to be released or pops up a warning if the $warn parameter is not an empty string. Therefore it is not intended to be used when one of these modifyer keys has been set to be down using any combination of {ALTDOWN}, {SHIFTDOWN} and {ALTDOWN}.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 1 month later...

Q3 is wrong.

I tried and tried and wondered why I'd always get a message that my script is already running when it isn't and a look in the UDF help brought the answer:

Yes.

I think _Singleton is confusing. It might not return or it will return with either the handle to the mutex or the error for the mutex already existing.

I think this is easier.

If _MutexExists("MydeswswScriptName") Then
; We know the script is already running. Let the user know.
    MsgBox(0, "Script Name", "This script is already running. Using multiple copies of this script at the same breaks the [(UltimaCoder)] License!")
    Exit
EndIf

Func _MutexExists($sOccurenceName)
    Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError
    
    $sOccurenceName = StringReplace($sOccurenceName, "\", ""); to avoid error
    $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName)

    $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    Return $lastError[0] = $ERROR_ALREADY_EXISTS
    
EndFunc  ;==>_MutexExists
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Q21. Why my script doesn't work on locked station?

A21. On locked station any window will never be active (active is only dialog with text "Press Ctrl+Alt+Del")

In Windows locked state applications runs hidden (behind that visible dialog) and haven't focus and active status.

So generally don't use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc.

Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc.

This way you may have your script resistive against another active windows.

and it's possibe to run such script from scheduler on locked Windows station.

Edited by Zedna
Link to comment
Share on other sites

  • 2 months later...

Q22. Why can't I decompile my script any more?

Decomplation is not supported any more, and is only available for the older versions of AutoIt (Version 3.2.5.1 and earlier compiled scripts).

Please do not post on this topic, but search the forums for decomplation.

Cheers,

Brett

Link to comment
Share on other sites

  • 3 weeks later...

.

Start AutoIt3 development

For newbies

SciTE4AutoIt3.exe

Editor for AutoIt3 scripts

The AutoIt help File

(F1 hotkey in Scite Editor)

This AutoIt Forum Search engine

AutoIt 1-2-3

Written completely with AutoIt to Demonstrate some of the Capabilities of AutoIt

Learning to Script with AutoIt 3

Tutorial in PDF

KODA FormDesigner

Koda Form Designer is a standalone application for designing forms for AutoIt GUI

Add-on Firefox browser

Posted Image

Add-on Opera browser

Posted Image

. Edited by Jon
My projects : GCS Search 1.07 (GUI Control Styles Search)* Multilingual tool to help about the old scripts, with a dynamic menu.* Easy way to find missing Include files in old scripts downloaded from forums !* Famous Monoceres script added and improved (visual, drag and drop, automatic)* There is an interactive color converter with palettes too, for fun !The best way to start Autoit3 development (for newbies).
Link to comment
Share on other sites

Q24. Where can I learn AutoIt? Are there any tutorials?

For this you have 2 main options availible.

There is AutoIt 1-2-3, an interactive classroom by Valauter. You may find it here:

http://www.autoitscript.com/forum/index.php?showtopic=21048

I have also updated LxP's AutoIt tutorial. You can find it here:

http://www.autoitscript.com/forum/index.php?showtopic=84960

Cheers.

Brett

Edited by BrettF
Link to comment
Share on other sites

  • 1 month later...

Q19.How can I use Pixel functions ?

A1.PixelCheckSum

Description : Generates a checksum for a region of pixels.

Function PixelChecksumReturns the checksum value of the region.

Example :

Posted Image

Q20.Who can help me for begin in autoit ?

Dont forget that AutoIt have helpfile for help you to check functions :)

1.Instead of going to autoit forum and ask for a simple function (Ex : What is GuiCreate ?) use autoit help :

-highlight function

Posted Image

-go to help menu and select "Help F1"

-or press F1

Posted Image

Cheers, FireFox.

Edited by Jon
Link to comment
Share on other sites

  • 2 weeks later...

Question 25- I have run a program, but how can I get the window handle?

Refer to the following example, showing converting and use when manipulating the window. Function is based on work by Smoke_N/Hubertus and Helge

;Run process
$iPID = Run("Notepad.exe")

;Allow window to initialize...
Sleep (500)

;Get HWND.
$hWnd = _GetHwndFromPID($iPID)

;Maximize
WinSetState($hWnd, "", @SW_MAXIMIZE)
Sleep(2000);Wait 2 seconds

;Minimize
WinSetState($hWnd, "", @SW_MINIMIZE)
Sleep(2000);Wait 2 seconds

;Restore window
WinSetState($hWnd, "", @SW_RESTORE)
Sleep(2000);Wait 2 seconds

;Move top left corner of screen, and resize to 800x600
WinMove($hWnd, "", 0, 0, 800, 600)
Sleep(2000);Wait 2 seconds

;Move to center of screen
;Calculate Center of screen.
$x = (@DesktopWidth / 2) - 400; Desktop width divided by 2, then minus half the width of the window
$y = (@DesktopHeight / 2) - 300; Desktop height divided by 2, then minus half the height of the window
WinMove($hWnd, "", $x, $y)

Sleep(2000);Wait 2 seconds

;Close notepad
WinClose($hWnd)

;Function for getting HWND from PID
Func _GetHwndFromPID($PID)
    $hWnd = 0
    $winlist = WinList()
    Do
        For $i = 1 To $winlist[0][0]
            If $winlist[$i][0] <> "" Then
                $iPID2 = WinGetProcess($winlist[$i][1])
                If $iPID2 = $PID Then
                    $hWnd = $winlist[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
    Until $hWnd <> 0
    Return $hWnd
EndFunc  ;==>_GetHwndFromPID

EDIT: Modified example code... Its much faster than my previous tests!

Edited by BrettF
Link to comment
Share on other sites

;Function for getting HWND from PID
Func _GetHwndFromPID($PID)
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc;==>_GetHwndFromPID
Brett,

What's wrong with using the built-in WinGetProcess() in this function instead of the DllCall()? :)

Edit: You had also posted another version by Helge

http://www.autoitscript.com/forum/index.ph...st&p=601027

and Smoke_N made one that was modified by Hubertus.

Hube's original posts are gone, but a copy of the function is in the code in the post here:

http://www.autoitscript.com/forum/index.ph...st&p=621983

Edited by ResNullius
Link to comment
Share on other sites

Good point...

I'll do speed tests, to see whats the fastest... :)

Cheers,

Brett

EDIT:

Results Vs Helge and the one I posted.

Function 1 = Helge's

Function 2 = The other one...

Function 3 = Smokes/Hubertus'

Test 1

Function 1: 245.944692ms

Function 2: 109.311855ms

Function 3: 5.066022ms

Test 2

Function 1: 241.10388ms

Function 2: 109.7961ms

Function 3: 5.805465ms

Test 3

Function 1: 239.468955ms

Function 2: 109.495308ms

Function 3: 4.921413ms

Always visible which is faster. By a long shot too...

Will update my original post.

Edited by BrettF
Link to comment
Share on other sites

  • 3 months later...

Hi, I just want to add a third method to starting your program at start up. I think it will only work on Windows Vista. It is very simple, see below.

Run("schtasks /create /sc onstart /tn "Task name" /tr " & @ScriptFullPath & '"')
;or
Run("schtasks /create /sc ONLOGON /tn "Task name" /tr " & @ScriptFullPath & '"')
Edited by Zachlr
Link to comment
Share on other sites

Hi, I just want to add a third method to starting your program at start up. I think it will only work on Windows Vista. It is very simple, see below.

Run("schtasks /create /sc onstart /tn "Task name" /tr " & @ScriptFullPath & '"')
;or
Run("schtasks /create /sc ONLOGON /tn "Task name" /tr " & @ScriptFullPath & '"')
How about you check the syntax of that, specifically the use of "" and ''...
Link to comment
Share on other sites

  • 1 month later...

Q21. Why my script doesn't work on locked station?

A21. On locked station any window will never be active (active is only dialog with text "Press Ctrl+Alt+Del")

In Windows locked state applications runs hidden (behind that visible dialog) and haven't focus and active status.

So generally don't use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc.

Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc.

This way you may have your script resistive against another active windows.

and it's possibe to run such script from scheduler on locked Windows station.

Hi, i am having a script which opens a command prompt window and then sends commands to it. I want this script to run even if my workstation is locked. Yous said to use controlsend, however i have read that controlsend should not be used for sending commands to command prompt window. So now what to do...PLease help!!!!!!

Link to comment
Share on other sites

  • 1 month later...

I have a window that always has the same name in the title for example: Microsoft Internet Explorer.

But what it´s into this window (Microsoft Internet Explorer) i can´t select the text, so I can´t indentify a new window during a procces, somebody help me?

Link to comment
Share on other sites

I have a window that always has the same name in the title for example: Microsoft Internet Explorer.

But what it´s into this window (Microsoft Internet Explorer) i can´t select the text, so I can´t indentify a new window during a procces, somebody help me?

See post #18.

First, search for other posts on the same topic for the answer.

If you don't find it post your own new topic.

Be careful to post in the correct forum (which General Help and Support is).

Do not post questions into the FAQ sticky topic.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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