Sign in to follow this  
Followers 0
EarlDPearl

GUICtrlInput use Tab or Enter to exit

9 posts in this topic

How does one modify a GUICTRLINPUT box so that either the Tab or Enter key completes the operation and moves along to the next box. Maybe it is not modifiable and one has to create a completely new function. I went looking for the GUICTRLINPUT source to modify but cannot seem to find it.

All input boxes in my application are numeric and most people inputting will have numberic keyboards and will want use the numeric keyboard Enter key.

Will appreciate help ... Thanks ... Earl

Share this post


Link to post
Share on other sites



EarlDPearl,

Welcome to the AutoIt forum. :)

A quick way to do what you want is to use an Accelerator key so that the {ENTER} key acts as a {TAB} key and moves the focus onto the next input:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hInput_1 = GUICtrlCreateInput("", 10, 10, 200, 20)
$hInput_2 = GUICtrlCreateInput("", 10, 50, 200, 20)
$hInput_3 = GUICtrlCreateInput("", 10, 90, 200, 20)

$hDummy = GUICtrlCreateDummy()

GUISetState()

Local $aAccelKeys[1][2] = [["{ENTER}", $hDummy]]
GUISetAccelerators($aAccelKeys)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hDummy
            Send("{TAB}")
    EndSwitch

WEnd

You could easily improve this by adding some errorchecking to see if all the inputs were completed and then using {ENTER} to move to the next action, but that can come later. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks for the quick reply ... off to work now.

Share this post


Link to post
Share on other sites

I tranlated your example into an event driven scheme and it works very well. Thanks loads... Earl

Solved

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The code is messed up. This is a result of several upgrades to the forum software, which has been affecting the code boxes. It is best to first click the AutoIt code button and add the AutoIt tags to your post without any code. Then paste your code directly between the tags. This generally works all the time.

Edited by czardas

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I know this is and old thread, but I'm working on this same thing now and if I do it this way I loose the ability to use the enter button on GUICtrlcreateButton's. here is mine below.

#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Save = "1"

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 592, 320, 488, 249)
$Input1_sku = GUICtrlCreateInput("", 72, 56, 233, 32)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input2_qty = GUICtrlCreateInput("", 72, 144, 233, 32, $ES_NUMBER)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("SKU:", 8, 56, 46, 28)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("QTY:", 8, 144, 48, 28)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Enter = GUICtrlCreateButton("Enter", 120, 224, 123, 33, $WS_GROUP)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$hDummy = GUICtrlCreateDummy() ;Comment out for testing Enter with gui buttons.
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $aAccelKeys[1][2] = [["{ENTER}", $hDummy]] ;==>Comment out for testing Enter with gui buttons.
GUISetAccelerators($aAccelKeys) ;==>Comment out for testing Enter with gui buttons.


While 1
$nMsg = GUIGetMsg()
If $nMsg = $Enter Then _Enter()
If $nMsg = $Save Then _Save()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hDummy ;==>;Comment out for testing Enter with gui buttons.
Send("{TAB}") ;==>;Comment out for testing Enter with gui buttons.
EndSwitch
WEnd

Func _Enter()


$Label3 = GUICtrlCreateLabel("SKU: " & GUICtrlRead($Input1_sku), 344, 56, 220, 25)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("QTY: " & GUICtrlRead($Input2_qty), 344, 144, 220, 25)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Save = GUICtrlCreateButton("Save", 368, 224, 137, 33, $WS_GROUP)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
EndFunc ;==>_Enter

Func _Save()
Local $file = FileOpen("Audit_" & @YEAR & ".csv", 1) ;==>Comment out to disable file creation.
FileWriteLine($file, GUICtrlRead($Input1_sku) & ", " & GUICtrlRead($Input2_qty)) ;==>Comment out to disable file creation.
_SelfRestart()
EndFunc ;==>_Save

Func _SelfRestart()
If @Compiled Then
Run(FileGetShortName(@ScriptFullPath))
Else
Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
EndIf
Exit
EndFunc ;==>_SelfRestart
Edited by ravaged1

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sorry have not been around here in a while.

Basicly with code in my post above, Im looking to just make a fast little app that will play nice with the keyboard, mouse, and a barcode scanner. keyboard enter key for buttons will not work becuase I set it up for inputs(barcode scanner).

I'm not sure how to get them all working right together.

Edited by ravaged1

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I don't really understand this thread. Enter is normally used to activate the button which has focus. Altering this makes no sense to me. There are a whole load of other keys available that could be used as accelerators. You can set a particular button to be the default push button when you create it, by using $BS_DEFPUSHBUTTON.

Edited by czardas

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I don't really understand this thread. Enter is normally used to activate the button which has focus. Altering this makes no sense to me. There are a whole load of other keys available that could be used as accelerators. You can set a particular button to be the default push button when you create it, by using $BS_DEFPUSHBUTTON.

When you use a barcode scanner or type in a field it's normal to use the enter key to move to the next feild or button even.

After setting the ENTER key to TAB with $aAccelKeys, enter will no longer work for buttons. So I'm asking if anyone knows a better way to do what I'm looking for.

Edited by ravaged1

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