AutoHotkey Community

It is currently May 27th, 2012, 5:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: March 14th, 2010, 12:02 pm 
Offline

Joined: August 16th, 2009, 2:02 pm
Posts: 20
A script I have switches specific folders in a program on/off, but only one a time with radio buttons. I want to use checkboxes instead so I can a switch on/off all folders with the same script.

If I click the first checkbox, the code executes. With the other two checkboxes it doesn't. It doesn't loop either.

I'm trying to get a part of the script to repeat for each checkbox clicked (Loop).
If the first checkbox is clicked, in the loop the down key should be pressed x times.

What am I missing here?

Thanks!

Code:
SetTitleMatchMode 2

CoordMode, Mouse, Relative

Gui, Add, Checkbox, x36 y7 w90 h30 vCheckbox, &Deutsch
Gui, Add, Checkbox, xp yp+30 wp hp , &English
Gui, Add, Checkbox, xp yp+30 wp hp , &Français
Gui, Add, Button, xp y127 w70 h30 Default gOK, &OK
Gui, Add, Button, xp+80 yp wp hp gCancel, &Abbrechen
Gui, Show, w330 h185, Sprache in PhraseExpress aktivieren
Return

Cancel:
GuiEscape:
GuiClose:
    ExitApp
   
OK:
   Gui, Submit, NoHide
   ToolTip, Du hast Radiobutton %Checkbox% gedrückt!
   Sleep, 400
   ToolTip
   Send ^!p
   WinWaitActive ahk_class TpexMWnd4
   Sleep 1500
   click 100, 100
   Sleep 500
   Send {home} ; geht zum obersten Ordner / Select top folder
   Sleep 200
   Send ^+{left} ; collapse all folders
   Sleep 500
   send {down 2} ; move to "Texte"
   Sleep 400
   Send {right} ; Ordner "Texte" erweitern / expand folder "texte"
   Sleep 400
   send {down}{right} ; Ordner "Sprachen" erweitern / expand folder "sprachen"
   sleep 400
   
   Loop, %checkbox%
   {
   Send {down %Checkbox%} ; Deutsch, English, Français
   sleep 400
   Send +{f10} ; Menutaste / Menu key
   Sleep 400
   send {Down 8} ; Aktiv wählen / Choose state "active"
   Sleep 400
   send {Enter} ; bestätigen / confirm
   Sleep 1000 ; 1 Sek. wartezeit mindestens, weil das Ändern des Zustands von aktiv zu inaktiv lange dauern kann
   send {left}
   Sleep 500
}

   Send !{F4} ; pex schliessen / close PhraseExpress
   Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 1:18 pm 
Offline

Joined: February 6th, 2010, 5:17 pm
Posts: 57
Each checkbox has to have a unique variable. It looks like you had the radio button variable set up to contain 1, 2, or 3 depending on which one was selected. The checkbox variables contain either 0 (not checked) or 1 (checked).

I think this would work:
Code:
SetTitleMatchMode 2

CoordMode, Mouse, Relative

Gui, Add, Checkbox, x36 y7 w90 h30 vCheckbox1, &Deutsch
Gui, Add, Checkbox, xp yp+30 wp hp vCheckbox2, &English
Gui, Add, Checkbox, xp yp+30 wp hp vCheckbox3, &Français
Gui, Add, Button, xp y127 w70 h30 Default gOK, &OK
Gui, Add, Button, xp+80 yp wp hp gCancel, &Abbrechen
Gui, Show, w330 h185, Sprache in PhraseExpress aktivieren
Return

Cancel:
GuiEscape:
GuiClose:
    ExitApp
   
OK:
   Gui, Submit, NoHide
   ToolTip, Du hast Radiobutton %Checkbox% gedrückt!
   Sleep, 400
   ToolTip
   Send ^!p
   WinWaitActive ahk_class TpexMWnd4
   Sleep 1500
   click 100, 100
   Sleep 500
   Send {home} ; geht zum obersten Ordner / Select top folder
   Sleep 200
   Send ^+{left} ; collapse all folders
   Sleep 500
   send {down 2} ; move to "Texte"
   Sleep 400
   Send {right} ; Ordner "Texte" erweitern / expand folder "texte"
   Sleep 400
   send {down}{right} ; Ordner "Sprachen" erweitern / expand folder "sprachen"
   sleep 400
   
   switch(checkbox1)
   switch(checkbox2 * 2)
   switch(checkbox3 * 3)

   Send !{F4} ; pex schliessen / close PhraseExpress
   Return

switch(n) {
  Loop, %n%
   {
   Send {down %n%} ; Deutsch, English, Français
   sleep 400
   Send +{f10} ; Menutaste / Menu key
   Sleep 400
   send {Down 8} ; Aktiv wählen / Choose state "active"
   Sleep 400
   send {Enter} ; bestätigen / confirm
   Sleep 1000 ; 1 Sek. wartezeit mindestens, weil das Ändern des Zustands von aktiv zu inaktiv lange dauern kann
   send {left}
   Sleep 500
   }
   Return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 1:46 pm 
Offline

Joined: August 16th, 2009, 2:02 pm
Posts: 20
Thanks! It's much better.
The loop works! Selecting multiple checkboxes does manipulate the correct Folder.

However:
If the 1st checkbox is selected, the script works all right.
If the 2nd checkbox is selected, the script repeats this twice. the script first activates the 2nd folder then deactivates it.
If the 3rd checkbox is selected, the script repeats 3x for the 3rd folder.

Doesn't this line
Code:
Loop, %n%

cause this problem?

Quote:
It looks like you had the radio button variable set up to contain 1, 2, or 3 depending on which one was selected.

Nope.
Original code:
Code:
Gui, Add, Radio, x36 y7 w90 h30 vRadio, &Deutsch
Gui, Add, Radio, xp yp+30 wp hp, &English
Gui, Add, Radio, xp yp+30 wp hp, &Français
Gui, Add, Button, xp y127 w70 h30 Default gOK, &OK
Gui, Add, Button, xp+80 yp wp hp gCancel, &Abbrechen
Gui, Show, w330 h185, Sprache in PhraseExpress aktivieren
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 2:04 pm 
Offline

Joined: February 6th, 2010, 5:17 pm
Posts: 57
Yeah, if you take out that loop it should fix it. I wasn't sure if that was needed since I couldn't test it.

[EDIT]Actually you'd have to do it a little different without the loop:
Code:
SetTitleMatchMode 2

CoordMode, Mouse, Relative

Gui, Add, Checkbox, x36 y7 w90 h30 vCheckbox1, &Deutsch
Gui, Add, Checkbox, xp yp+30 wp hp vCheckbox2, &English
Gui, Add, Checkbox, xp yp+30 wp hp vCheckbox3, &Français
Gui, Add, Button, xp y127 w70 h30 Default gOK, &OK
Gui, Add, Button, xp+80 yp wp hp gCancel, &Abbrechen
Gui, Show, w330 h185, Sprache in PhraseExpress aktivieren
Return

Cancel:
GuiEscape:
GuiClose:
    ExitApp
   
OK:
   Gui, Submit, NoHide
   ToolTip, Du hast Radiobutton %Checkbox% gedrückt!
   Sleep, 400
   ToolTip
   Send ^!p
   WinWaitActive ahk_class TpexMWnd4
   Sleep 1500
   click 100, 100
   Sleep 500
   Send {home} ; geht zum obersten Ordner / Select top folder
   Sleep 200
   Send ^+{left} ; collapse all folders
   Sleep 500
   send {down 2} ; move to "Texte"
   Sleep 400
   Send {right} ; Ordner "Texte" erweitern / expand folder "texte"
   Sleep 400
   send {down}{right} ; Ordner "Sprachen" erweitern / expand folder "sprachen"
   sleep 400
   
   If (checkbox1)
      switch(checkbox1)
   If (checkbox2)
      switch(checkbox2 * 2)
   If (checkbox3)
      switch(checkbox3 * 3)

   Send !{F4} ; pex schliessen / close PhraseExpress
   Return

switch(n) {
   Send {down %n%} ; Deutsch, English, Français
   sleep 400
   Send +{f10} ; Menutaste / Menu key
   Sleep 400
   send {Down 8} ; Aktiv wählen / Choose state "active"
   Sleep 400
   send {Enter} ; bestätigen / confirm
   Sleep 1000 ; 1 Sek. wartezeit mindestens, weil das Ändern des Zustands von aktiv zu inaktiv lange dauern kann
   send {left}
   Sleep 500
   Return
}


AutoHotkey Help wrote:
The radio button's associated output variable (if any) receives the number 1 for "on" and 0 for "off". However, if only one button in a radio group has a variable, that variable will instead receive the number of the currently selected button: 1 is the first radio button (according to original creation order), 2 is the second, and so on.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 2:40 pm 
Offline

Joined: August 16th, 2009, 2:02 pm
Posts: 20
So great, many thanks! Saved my day, been tinkering with this for months on and off! :D :D :D

Out of curiosity:
What does this mean?
switch(checkbox2 * 2)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 3:11 pm 
Offline

Joined: February 6th, 2010, 5:17 pm
Posts: 57
If the checkbox is checked, it's 1 * 2 = 2. If it's not checked it's 0 * 2 = 0. The way I had it written to start with, the loop was acting as an IF statement so that it wouldn't loop (Loop, 0) if the box was not checked. But it looped twice if it was checked, which is not what you wanted, so I had to change it.

It could be more simply written:
Code:
If (checkbox1)
  switch(1)
If (checkbox2)
  switch(2)
If (checkbox3)
  switch(3)


Or you could put an IF in the function to make it still work the way it did to start with:
Code:
switch(checkbox1) ;checked = 1 not checked = 0
switch(checkbox2 * 2) ;checked = 2 not checked = 0
switch(checkbox3 * 3) ;checked = 3 not checked = 0

switch(n) {
  If (n != 0) ;only do something if n is not equal to 0
  {
     ;rest of the function here
  }
  Return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 5:16 pm 
Offline

Joined: August 16th, 2009, 2:02 pm
Posts: 20
Great thanks!
I've learned something and hope to write better and more complex scripts in the future!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], HotkeyStick, mrhobbeys, rbrtryn and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group