Sign in to follow this  
Followers 0
cooleko

Need Advice on improving code

4 posts in this topic

I have been working on a project for a while now and it is starting to grow quite large. I was hoping to learn some tips for generating things efficiently or handling certain actions differently to improve the code.

My first question (all about controlsend):

AutoIt randomly activates shift and ctrl when using ControlSend()

reviewing several other threads usually results in people telling the programmer to look for {...down} without {...up} but my code does not use downs and ups (explicitly). I'm wondering if the fact that {} are upper case keys if sending them results in activating shift or if because my control fields are not fleshed out is causing the problem. I was wondering also if maybe it is because I am typing when the script is running (improving script or adding more to it) that when i hit shift and the script sends a key stroke that shift somehow gets stuck active until i hit shift again. The stuff I send is simple key presses

ControlSend("WINDOWNAME", "", "", "{left}{up}{up}")

Also, can someone recommend what actually goes in the other fields? I have reviewed the help page on it and it was informative but i did not know how to find the control values.

my Second Question (all about toggles):

i have a lot of toggles, and variables that i intend to just be true/false. I know you can make an array of toggles and change a toggles output values to what you want. Can anyone give me an example of how to do this?

if $toggle1 = 1 Then
        $toggle1 = True
    Else
        $Toggle1 = False
    EndIf
    
    if $toggle2 = 1 Then
        $toggle2 = True
    Else
        $toggle2 = False
    EndIf 
etc, etc

I'm looking for two things, setting the default values to true/false and generating toggles in an array.

I dont know if the array would make this easier but I also have the code finding if any of the toggles are set

$toggleset = $toggle1 or $toggle2 or $toggle3

If done in an array is it possible to simplify the expression to just checking the toggle array?

How do you give each toggle in an array a name and location, since the array is generated in a for loop how do you change each toggles name/location?

Lastly, when GUICtrlRead($ToggleArray), in an array it would just be a for loop right? I only ask because Autoit might have made it so that guictrlread could return an array of results for every toggle in the array.

My third question (GuiCtrlCreatCombo, GUIctrlSetData)

I wanted to make an input box such that when you hit send button the text in the box disappears and is appended into the setdata list

I could not get this to work

Essentially I could erase the input box and save the last input but i couldnt keep a list of all items sent (I only the last one).

The only thing keeping me back was not being able to grab data out of the set data so I could append onto it. Is there a command for this?

My fourth question (GuiCtrlSetOnEvent)

I have buttons working great but I was wondering if it is possible to make one more complex.

Specifically, If enter key is pressed and input box is active/has text?

As of right now I just have the user click a button labeled send, but I would like to let them hit enter.

My Fifth question (GUI stuff)

I am starting to make my GUI a little crowded, I was wondering if there was a way to make tabs in autoit (I haven't done a google search for this yet and If there is a way I will find it since usually it is very well documented, just figured to toss it in here since im asking for help with the other stuff).

If I want to designate specific labels/toggles to the gui how would this be done?

I really appreciate the wealth of knowledge on the forums. I have been able to pull off some pretty interesting tricks from reading up on the threads. Now that my project is mostly complete I just want to clean it up to be a little more professional.

Share this post


Link to post
Share on other sites



There is no way to troubleshoot your code without seeing it.

The second parameter of ControlSend() is for optional window text that can be used to help identify the target window. The third parameter is to identify the control.

Your question about arrays sounds very confused. There is a good wiki article on arrays that is worth studying.

GuiCtrlRead() doesn't work that way, period. If you have an array of control IDs then you would loop through the array doing GuiCtrlRead() on each one something like this:

For $n = 0 To UBound($aControlIDs) - 1
    $vData = GuiCtrlRead($aControlIDs[$n])
    ConsoleWrite($n & ": " & $vData & @LF)
Next

I'm not even going to bother with the rest of the questions since you obviously haven't even tried the example scripts in the help file.

The help file has some basic tutorials, example scripts under almost every function, and then there are full tutorials like AutoIt 1-2-3 linked in my sig. Start there, and if you get stuck post a short demo script that shows your issue.

:)


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

Share this post


Link to post
Share on other sites

There is no way to troubleshoot your code without seeing it.

Since the error is persistent I made an example script.

Requires an untitled notepad to be opened to run.

Attempt to type/copy text (ctrl c/v)/undo (ctrl z)/highlight (shift - arrows) while running the script (in something other than notepad). You will notice shift and ctrl being randomly held down due to the script running in the background. I wish I knew how to stop it as it makes editing the code while running it a huge pain!

I hope you can help!

The script causes errors on 3 machines, all 64 bit Vista/Win7.

SendBrokenTest.au3

Share this post


Link to post
Share on other sites

For any wondering, the only way to fix this is to use the windows api, PostMessage. Information all over the place about getting postmessage to work.

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