Jump to content

Select Button On {enter}


litlmike
 Share

Recommended Posts

When I {TAB} through the 3 buttons on the GUI, and press {ENTER}, I would like the GUI to select/click the button highlighted. It doesn't do that now, how come?

*************EDIT**************

Or another way to ask this! How do I change the Push Button from {SPACEBAR} to {ENTER}? I notice in the GUI that {SPACEBAR} will select the button the user is highlighted on, but how can I make that the {ENTER} key instead?

Func GUI_Time_Slots ()
GuiCreate("MyGUI", 392, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Button_1 = GuiCtrlCreateButton("8:30 Time Slot", 20, 90, 100, 50)
$Button_2 = GuiCtrlCreateButton("11:00 Time Slot", 150, 90, 110, 50)
$Button_3 = GuiCtrlCreateButton("1:15 Time Slot", 280, 90, 100, 50)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_830 ()
    
    Case $msg = $Button_2
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_1100 ()
        
    Case $msg = $Button_3
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_1315 ()
    
    EndSelect
WEnd
Return
EndFunc

Func Time_Slot_830 ()
    BlockInput (1)
    Sleep (100)
    Send ("0830a")
    BlockInput (0)
    Return
EndFunc

Func Time_Slot_1100 ()
    BlockInput (1)
    Sleep (100)
    Send ("1100a")
    BlockInput (0)
    Return
EndFunc

Func Time_Slot_1315 ()
    BlockInput (1)
    Sleep (100)
    Send ("0115p")
    BlockInput (0)
    Return
EndFunc
Edited by litlmike
Link to comment
Share on other sites

  • Moderators

Take a look at $BS_DEFPUSHBUTTON in the help file under GUI Control Styles.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Take a look at $BS_DEFPUSHBUTTON in the help file under GUI Control Styles.

I changed it to this, does this seem right? It looks kinda ugly, but it does seem to work from my prelim testing.

$Button_1 = GuiCtrlCreateButton("8:30 Time Slot", 20, 90, 110, 50, -1, $BS_DEFPUSHBUTTON)
$Button_2 = GuiCtrlCreateButton("11:00 Time Slot", 150, 90, 110, 50, -1, $BS_DEFPUSHBUTTON)
$Button_3 = GuiCtrlCreateButton("1:15 Time Slot", 280, 90, 110, 50, -1, $BS_DEFPUSHBUTTON)
Link to comment
Share on other sites

  • Moderators

I changed it to this, does this seem right? It looks kinda ugly, but it does seem to work from my prelim testing.

$Button_1 = GuiCtrlCreateButton("8:30 Time Slot", 20, 90, 110, 50, -1, $BS_DEFPUSHBUTTON)
$Button_2 = GuiCtrlCreateButton("11:00 Time Slot", 150, 90, 110, 50, -1, $BS_DEFPUSHBUTTON)
$Button_3 = GuiCtrlCreateButton("1:15 Time Slot", 280, 90, 110, 50, -1, $BS_DEFPUSHBUTTON)
It's not an extended style, it's a style:
$Button_1 = GuiCtrlCreateButton("8:30 Time Slot", 20, 90, 110, 50, $BS_DEFPUSHBUTTON)
$Button_2 = GuiCtrlCreateButton("11:00 Time Slot", 150, 90, 110, 50)
$Button_3 = GuiCtrlCreateButton("1:15 Time Slot", 280, 90, 110, 50)
Is all you should need :think:.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

It's not an extended style, it's a style:

$Button_1 = GuiCtrlCreateButton("8:30 Time Slot", 20, 90, 110, 50, $BS_DEFPUSHBUTTON)
$Button_2 = GuiCtrlCreateButton("11:00 Time Slot", 150, 90, 110, 50)
$Button_3 = GuiCtrlCreateButton("1:15 Time Slot", 280, 90, 110, 50)
Is all you should need :think:.
Hmmm... it seems that $BS_DEFPUSHBUTTON is a Default Button command. In that, whenever I press enter, it will select/click the button that is assigned as $BS_DEFPUSHBUTTON. But in this case, I am not looking for a default push button, I am just looking to push the button that the user has tabbed onto. The GUI in the original post, did not do that. Is there another way to assign the buttons?
Link to comment
Share on other sites

#include <GUIConstants.au3>
Func GUI_Time_Slots ()
GuiCreate("MyGUI", 392, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Button_1 = GuiCtrlCreateButton("8:30 Time Slot", 20, 90, 100, 50)
GUICtrlSetState( -1,$GUI_DEFBUTTON)
$Button_2 = GuiCtrlCreateButton("11:00 Time Slot", 150, 90, 110, 50)
$Button_3 = GuiCtrlCreateButton("1:15 Time Slot", 280, 90, 100, 50)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_830 ()
    
    Case $msg = $Button_2
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_1100 ()
        
    Case $msg = $Button_3
        GuiSetState ( @SW_HIDE )
        Sleep (200)
        Time_Slot_1315 ()
    
    EndSelect
WEnd
Return
EndFunc

Func Time_Slot_830 ()
    BlockInput (1)
    Sleep (100)
    Send ("0830a")
    BlockInput (0)
    Return
EndFunc

Func Time_Slot_1100 ()
    BlockInput (1)
    Sleep (100)
    Send ("1100a")
    BlockInput (0)
    Return
EndFunc

Func Time_Slot_1315 ()
    BlockInput (1)
    Sleep (100)
    Send ("0115p")
    BlockInput (0)
    Return
EndFunc

8)

NEWHeader1.png

Link to comment
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
 Share

  • Recently Browsing   0 members

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