Sign in to follow this  
Followers 0
strate

Tab When User Pushes Enter

3 posts in this topic

I've seen it posted but now I cannot find it. It was a script that when the user pushed enter it tabbed instead.

For some reason this isn't working for me:

If GUICtrlGetState($sCode) = $GUI_FOCUS Then
    HotKeySet('{ENTER}','_CatchEnterThenTab')
Else
    HotKeySet('{ENTER}')
EndIf

Func _CatchEnterThenTab()
    Send('{TAB}')
EndFunc

As you can see I want it to do it when a certain input is in focus.

Here's the full code:

#include <GuiConstants.au3>

Dim $Restart

#region -; GUI Creation
GuiCreate('', 130, 190,-1, -1 , $WS_POPUP,$WS_EX_DLGMODALFRAME)
$Label_1 = GuiCtrlCreateLabel("DCX Ship Code:", 20, 20, 80, 20)
$sCode = GuiCtrlCreateInput("", 20, 40, 80, 20)
$Label_3 = GuiCtrlCreateLabel("Number of Palllets:", 20, 70, 90, 20)
$sPallets = GuiCtrlCreateInput("", 20, 90, 40, 20)
$bPrint = GuiCtrlCreateButton("Print", 20, 120, 60, 20);,$BS_DEFPUSHBUTTON)
$bClose = GuiCtrlCreateButton("Close", 20, 150, 60, 20)
GuiSetState()
#endregion 

While 1
    If GUICtrlGetState($sCode) = $GUI_FOCUS Then
        HotKeySet('{ENTER}','_CatchEnterThenTab')
    Else
        HotKeySet('{ENTER}')
    EndIf
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $bClose
        ExitLoop
    Case $msg = $bPrint
        Global $Code = GUICtrlRead($sCode)
        Global $Pallets = GUICtrlRead($sPallets)
        _VerifyUserEntry()
        If $Restart = 1 Then
            $Restart = ''
            ContinueLoop
        EndIf
        _Print()
    EndSelect
WEnd
Exit
Func _CatchEnterThenTab()
    Send('{TAB}')
EndFunc
Func _VerifyUserEntry()
    If $Code = '' Or $Pallets == '' Then
        Global $Restart = 1
        MsgBox(4096,'Error:','A field was left blank.')
        If $Code = '' Then
            GUICtrlSetState($sCode,$GUI_FOCUS)
        Else
            GUICtrlSetState($sPallets,$GUI_FOCUS)
        EndIf
        Return
    EndIf
    If Not StringIsDigit($Code) Then 
        MsgBox(4096,'Error:','DCX Code must be numbers. (0-9)')
        Exit
    EndIf
    If Not StringIsDigit($Pallets) Then 
        MsgBox(4096,'Error:','Pallet quantity must be numbers. (0-9)')
        Exit
    EndIf
EndFunc
Func _Print()
    Local $Command_File_Name = IniRead('c:\lvwin70\Label.ini','Command FIle','Monitor Dir','Error')&'\DCX-SHIP_CODE.cmd'
    Local $LabelName = 'G:\Packaging\Labels\Sato8400\CUSTOMER LABEL SPECIFICATION TEMPLATES\DCX-SHIP-LABEL.lbl'
    Filewrite($Command_File_Name,'LabelName = "'&$LabelName&'"'& @CRLF & _
                                'Printer = "'&IniRead('c:\lvwin70\Label.ini','LabelView','printer_name','Error')&' on '&IniRead('c:\lvwin70\Label.ini','LabelView','port','Error')&'"'& @CRLF & _
                                'LABELQUANTITY = '&$Pallets)
    GUICtrlSetData($sCode,'')
    GUICtrlSetData($sPallets,'')
    GUICtrlSetState($sCode,$GUI_FOCUS)
EndFunc

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites



I had to change it to ControlGetFocus()

#include <GuiConstants.au3>

Dim $Restart

#region -; GUI Creation
$Main = GuiCreate('', 130, 190,-1, -1 , $WS_POPUP,$WS_EX_DLGMODALFRAME)
$Label_1 = GuiCtrlCreateLabel("DCX Ship Code:", 20, 20, 80, 20)
$sCode = GuiCtrlCreateInput("", 20, 40, 80, 20)
$Label_3 = GuiCtrlCreateLabel("Number of Palllets:", 20, 70, 90, 20)
$sPallets = GuiCtrlCreateInput("", 20, 90, 40, 20)
$bPrint = GuiCtrlCreateButton("Print", 20, 120, 60, 20);,$BS_DEFPUSHBUTTON)
$bClose = GuiCtrlCreateButton("Close", 20, 150, 60, 20)
GuiSetState()
#endregion
While 1
    If ControlGetFocus($Main) = 'Edit2' Then
        HotKeySet('{ENTER}','_CatchEnterThenTab')
    Else
        HotKeySet('{ENTER}')
    EndIf
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $bClose
        ExitLoop
    Case $msg = $bPrint
        Global $Code = GUICtrlRead($sCode)
        Global $Pallets = GUICtrlRead($sPallets)
        _VerifyUserEntry()
        If $Restart = 1 Then
            $Restart = ''
            ContinueLoop
        EndIf
        _Print()
    EndSelect
WEnd
Exit
Func _CatchEnterThenTab()
    Send('{TAB}')
EndFunc
Func _VerifyUserEntry()
    If $Code = '' Or $Pallets == '' Then
        Global $Restart = 1
        MsgBox(4096,'Error:','A field was left blank.')
        If $Code = '' Then
            GUICtrlSetState($sCode,$GUI_FOCUS)
        Else
            GUICtrlSetState($sPallets,$GUI_FOCUS)
        EndIf
        Return
    EndIf
    If Not StringIsDigit($Code) Then
        MsgBox(4096,'Error:','DCX Code must be numbers. (0-9)')
        Exit
    EndIf
    If Not StringIsDigit($Pallets) Then
        MsgBox(4096,'Error:','Pallet quantity must be numbers. (0-9)')
        Exit
    EndIf
EndFunc
Func _Print()
    Local $Command_File_Name = IniRead('c:\lvwin70\Label.ini','Command FIle','Monitor Dir','Error')&'\DCX-SHIP_CODE.cmd'
    Local $LabelName = 'G:\Packaging\Labels\Sato8400\CUSTOMER LABEL SPECIFICATION TEMPLATES\DCX-SHIP-LABEL.lbl'
    Filewrite($Command_File_Name,'LabelName = "'&$LabelName&'"'& @CRLF & _
                                'Printer = "'&IniRead('c:\lvwin70\Label.ini','LabelView','printer_name','Error')&' on '&IniRead('c:\lvwin70\Label.ini','LabelView','port','Error')&'"'& @CRLF & _
                                'LABELQUANTITY = '&$Pallets)
    GUICtrlSetData($sCode,'')
    GUICtrlSetData($sPallets,'')
    GUICtrlSetState($sCode,$GUI_FOCUS)
EndFunc


[center]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.[/center]

Share this post


Link to post
Share on other sites

It seems like its always so easy I hate it sometimes. Thanks alot, I would have been confused trying to make it work with my method.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

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