Sign in to follow this  
Followers 0
john925

AutoIt GUI question

16 posts in this topic

There are four related capabilites common to most windows applications that I'd like to use with AutoIt-GUI.

Use tab and shift-tab to move the focus from control to control.

Once focus is on a button, press Enter in place of clicking on it.

Once focus is on a checkbox, press Space to check/uncheck it.

Once focus is on a radio button, press Space to select it.

Is it possible to do these things and, if so, how? Have I missed something obvious?

Thanks for any help!

john

Share this post


Link to post
Share on other sites



@josbe

I'll admit (blush) I didn't try them all. My first problem is that I can't tab from control to control so I didn't immeditately see how to test the other items. I've now tried using the space bar on a check box after clicking on it so it has focus and yes, the spacebar toggles the check on and off. I'll guess that the spacebar will also select a radio control if I can get the radio contol to have focus and Enter will do the same as clicking on a button if the focus is on the button. I still don't see how to use tab to shift focus from control to control and that's the necessary first step for the rest to be useful. I'm pretty new to AutoIt so it may be something simple. I've spent a lot of time looking through help but there's a lot of information there.

john

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

john925, do you use any of the following in your code:

GuiMsg()

GuiMsg(0)

GuiWaitClose()?

Last I checked, the tabbing only works with GuiMsg()....

GuiMsg(0)--which is used in AutoBuilder--might be required if you use HotKeySet.

If you need to use GuiMsg(0), then you can use HotKeySet("{Tab}", ...) to simulate tabbing among controls. An attempt at this workaround can be found in the source code of AutoBuilder (function TabJump in Main.au3)

Hope that helps

Edit: Hope that makes sense. :D I just re-read what I wrote. Use GuiMsg() or GuiWatiClose() in your code to see if tabbing works.

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

@cyberslug

Hi,

In fact I used AutoBuilder 0.41 to make my GUI interface and, now that you've pointed it out, see that it uses GuiMsg(0). I should have mentioned using AutoBuilder earlier. I'll see what I can do using HotKeySet(). By the way, AutoBuilder is great! Thanks for all the work you're putting into it. It helps me both by making it easy to create a GUI interface and, by looking at the generated code, I'm starting to understand how GUI programming works.

john

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here is something I just noticed. When I launch the script from a Windows environment (Read: Double clicking the exe or using the Run dialog), the control with focus is not initially shown. However, if I run from either a command window or use SciTE's Go command, the window shows up and the focus box is on the control as desired (Also, any accelerator keys show up in this case, but they do not when launched from Windows). I don't know what the relevance is, but it does show that something isn't quite right on the inside.

Edit: Tabbing works just fine no matter which GuiMsg() style is used. I have one of the most recent unstable builds as well, though that probably doesn't matter too much.

Edited by Valik

Share this post


Link to post
Share on other sites

I thought I'd try changing GuiMsg(0) to GuiMsg() in the code created by AutoBuilder before setting a hot key and tabbing/space/return all work perfectly now. I have four radio controls in a group I can tab into then have to use the cursor keys to move around them, but that's fine. I'm using the most recent AutoIt-GUI rather than the most recent unstable AutoIt so that might be making a difference to GuiMsg(0) working with tabs or not.

@cyberslug

Is there a special reason you use GuiMsg(0) rather than GuiMsg() in the AutoBuilder code? Everything I'm doing seems to work fine with GuiMsg().

john

Share this post


Link to post
Share on other sites

@Cyberslug

I spoke too soon. I hadn't closed my application when I replied and then found I couldn't close it by clicking on the "X" in the top right corner of the window. I'll try again once I get the most recent unstable AutoIt release.

@Valic

Thanks for the information. I both compile and run my executible from within Crimson Editor and have it set to run the executible through cmd.exe. I wouldn't have thought to test it by double clicking on the executible.

john

Share this post


Link to post
Share on other sites

Last Update (I hope!)-

I've got the most recent unstable AutoIt release now and tabs work properly in combination with GuiMsg(0). It also changed how my group of radio controls work. I have to shift focus to the first radio control (the one I want selected by default), send a space to select it, then shift focus to my first password input box (where I want the user to be when they start working). Then I start my main processing loop. The radio controls act oddly with tabs until after one of then has been actively selected.

john

Share this post


Link to post
Share on other sites

Last Update (I hope!)-

I've got the most recent unstable AutoIt release now and tabs work properly in combination with GuiMsg(0).  It also changed how my group of radio controls work.  I have to shift focus to the first radio control (the one I want selected by default), send a space to select it, then shift focus to my first password input box (where I want the user to be when they start working).  Then I start my main processing loop.  The radio controls act oddly with tabs until after one of then has been actively selected.

john

Can you show a small gui example that shows this problem and I'll try and fix it?

Share this post


Link to post
Share on other sites

Jon,

Here's code similar to my application but without any functionality. It sets the second radio button to be selected then sets focus on the first input box. When I tab through the controls and get to the radio buttons the first radio button, not the checked radio button, has focus first. Continuing to tab moves focus through all the radio buttons in the group then on to another control. This behaviour changes after I select a radio button by 1) tabbing to it then pressing the space bar, 2) tabbing to the radio button group and selecting a radio button with the cursor keys, or 3) selecting a radio button by clicking on it.

After actively selecting a radio button and tabbing out of the radio button group, tabbing back into the radio button group highlights the currently selected radio button rather than the first radio button, pressing tab again highlights the next non-radio button control. To use the keyboard to select a different radio button in the group you tab into the radio button group, which highlights the selected radio button, then use the cursor keys to move up and down through the radio buttons.

I'd like to see the latter behavior all the time. My current workaround is to set focus on the radio button I want initially selected, send the {SPACE} key to select it, then set focus on the input box I want users to start in.

Thanks for looking at this.

john

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
394 278
0   1   0   0   0   0   1   0   2   0   0   0   0   3   0   0   
group   $group_1    Group 1 30  90  120 160 0   0   
radio   $radio_1    Radio 1 50  120 70  20  0   0   
radio   $radio_2    Radio 2 50  150 60  20  0   0   
radio   $radio_3    Radio 3 50  180 60  10  0   0   
group  -99  -99 1   1   
button  $button_1   Button 1    30  20  120 40  0   0   
input   $input_1    Input 1 200 20  160 30  0   0   
input   $input_2    Input 2 200 70  160 30  0   0   
#ce - ### End of Dump ###

;Script generated by AutoBuilder 0.4

#include <GUIconstants.au3>
;#include <gui_include.au3>

Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
GuiCreate("MyGUI", 392,273,(@DesktopHeight-392)/2, (@DesktopHeight-273)/2 , 0x04CF0000)

$group_1 = GUISetControl("group", "Group 1", 30, 90, 120, 160)
    $radio_1 = GUISetControl("radio", "Radio 1", 50, 120, 70, 20)
    $radio_2 = GUISetControl("radio", "Radio 2", 50, 150, 60, 20)
    $radio_3 = GUISetControl("radio", "Radio 3", 50, 180, 60, 10)
GUISetControl("group","",-99,-99,1,1) ;close group

$button_1 = GUISetControl("button", "Button 1", 30, 20, 120, 40)
$input_1 = GUISetControl("input", "Input 1", 200, 20, 160, 30)
$input_2 = GUISetControl("input", "Input 2", 200, 70, 160, 30)

GuiShow()
GUISetControlEx($radio_2, $GUI_CHECKED)
GUIwrite($input_1, $GUI_FOCUS)

While 1
    sleep(100)
    $msg = GuiMsg(0)
    Select
    Case $msg = -3
        Exit
    Case $msg = 1
       ;;;
    Case $msg = $group_1
       ;;;
    Case $msg = $radio_1
       ;;;
    Case $msg = $radio_2
       ;;;
    Case $msg = $radio_3
       ;;;
    Case $msg = $button_1
       ;;;
    Case $msg = $input_1
       ;;;
    Case $msg = $input_2
       ;;;
    EndSelect
WEnd
Exit

Ps. I'm not certain what the "Case $msg = 1" is doing in the while loop and have tried commentinging it out with no apparent change in how the application runs.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Regarding the close button, check for $msg = 0 when using GuiMsg():

While 1
   sleep(100)
   $msg = GuiMsg()
   Select
   Case $msg= -3 or $msg = 0
       Exit
  ;Case ....
  ;   .....
    EndSelect
WEnd

Ps.  I'm not certain what the "Case $msg = 1" is doing in the while loop and have tried commentinging it out with no apparent change in how the application runs.

It's probably a bug in AutoBuilder. It sometimes generates erroneous code.... :D

The group_1 control should have a GuiRef# of 1; and since group controls do not respond to click events, $msg will never be equal to 1. This dead code should not affect your particular example.

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Looking at discussions on the net and playing around with the GUI builder function of VC it looks like we are using radios/groups incorrectly - you shouldn't be able to tab to each radio in a group, they should be treated as a single entity and once you tab to a radio group you use the arrow keys to move between them.

I created a test dialog in Visual C and this seemed to work consistantly. I'll see if I can work out how to do it in the AutoIt code.

Edited by Jon

Share this post


Link to post
Share on other sites

Cyberslug, in the code above (generated by your builder I assume :D ) you have a call to GuiSetControl to "close" the group. I can't find anything in the autoit source that refers to this. Is it just something that works by fluke or is it documented/designed like this?

Share this post


Link to post
Share on other sites

Cyberslug, in the code above (generated by your builder I assume :D ) you have a call to GuiSetControl to "close" the group.  I can't find anything in the autoit source that refers to this.  Is it just something that works by fluke or is it documented/designed like this?

AutoBulider has so many workarounds that it is a fluke it works at all!

The following example shows the why "closing a group" is sometimes needed.

It has three radio buttons inside a group frame followed by three radio buttons on the form proper. Uncomment the "close group" and run this example again.

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
394 278
0   0   0   0   0   0   1   0   0   0   0   0   0   6   0   0   
group   $group_1    Group 1 20  20  160 230 0   0   
radio   $radio_1    Radio 1 40  50  110 30  0   0   
radio   $radio_2    Radio 2 40  90  110 30  0   0   
radio   $radio_3    Radio 3 40  140 90  40  0   0   
group  -99  -99 1   1   
radio   $radio_4    Radio 4 210 40  120 40  0   0   
radio   $radio_5    Radio 5 210 90  120 50  0   0   
radio   $radio_6    Radio 6 220 160 110 50  0   0   
#ce - ### End of Dump ###


Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
GuiCreate("MyGUI", 392,273,(@DesktopHeight-392)/2, (@DesktopHeight-273)/2 , 0x04CF0000)

$group_1 = GUISetControl("group", "Group 1", 20, 20, 160, 230)
    $radio_1 = GUISetControl("radio", "Radio 1", 40, 50, 110, 30)
    $radio_2 = GUISetControl("radio", "Radio 2", 40, 90, 110, 30)
    $radio_3 = GUISetControl("radio", "Radio 3", 40, 140, 90, 40)
;;;;;;GUISetControl("group","",-99,-99,1,1) ;close group

$radio_4 = GUISetControl("radio", "Radio 4", 210, 40, 120, 40)
$radio_5 = GUISetControl("radio", "Radio 5", 210, 90, 120, 50)
$radio_6 = GUISetControl("radio", "Radio 6", 220, 160, 110, 50)

GuiWaitClose()
Exit

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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