Jump to content

TAB in Inputbox


Go to solution Solved by Andreik,

Recommended Posts

Hello,

we have a problem with inputbox.

If we enter TAB, there cursor changes from this button to another one, etc.

But we need the TAB in the inputbox message.

How can we enable this in the inputbox.

Thanks for an idea.

Cheers mike

Link to comment
Share on other sites

I never had a need to input a tab into an InputBox or any sort of input, but the GuiCtrlCreateInput has a forced "$WS_TABSTOP" control style, which doesn't seem to be able to be disabled and I think is for using tab to shift focus to the next Gui item in the script. I imagine the InputBox has a similar limitation. Both of these do accept the "@tab" macro if you send it to the control through a variable. But none of this helps if you want a way to manually type characters and tabs with your hands.

Maybe someone better acquainted with this language might have a solution...

Link to comment
Share on other sites

1 hour ago, abberration said:

GuiCtrlCreateInput has a forced "$WS_TABSTOP" control style, which doesn't seem to be able to be disabled [...]

@abberration here is a way to disable / enable  $WS_TABSTOP (or another style) using a function named Alter_Style . You can indicate several controls when calling the function, as shown in the script lines that are commented out. After the style is disabled, the TAB key won't select anymore the control(s) which don't have this style. A similar function should be easy to script to take care of Extended styles.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration

Local $hGUI = GUICreate("TabStop", 316, 207)
Local $Label1 = GUICtrlCreateLabel("Input1", 40, 40, 50, 17, $SS_CENTERIMAGE)
Local $Input1 = GUICtrlCreateInput("123", 100, 40, 170, 20)
Local $Label2 = GUICtrlCreateLabel("Input2", 40, 88, 50, 20, $SS_CENTERIMAGE)
Local $Input2 = GUICtrlCreateInput("456", 100, 90, 170, 20)
Local $idRemoveStyle = GUICtrlCreateButton("Remove TabStop ", 25, 155, 125, 25)
Local $idAddStyle = GUICtrlCreateButton("Add TabStop", 170, 155, 125, 25)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idRemoveStyle
            Alter_Style(0, $WS_TABSTOP, $Input1)
            ; Alter_Style(0, $WS_TABSTOP, $Input1, $Input2)
            ; Alter_Style(0, $WS_TABSTOP, $Input1, $Input2, $idRemoveStyle)

        Case $idAddStyle
            Alter_Style(1, $WS_TABSTOP, $Input1)
            ; Alter_Style(1, $WS_TABSTOP, $Input1, $Input2)
            ; Alter_Style(1, $WS_TABSTOP, $Input1, $Input2, $idRemoveStyle)
    EndSwitch
WEnd

;===========================================
Func Alter_Style($iRemoveOrAdd, $iStyleToAlter, $id1, $id2 = 0, $id3 = 0, $id4 = 0, $id5 = 0, _
    $id6 = 0, $id7 = 0, $id8 = 0, $id9 = 0, $id10 = 0)

    Local $hControl, $iStyle
    For $i = 1 To @NumParams - 2
        $hControl = GUICtrlGetHandle(Eval("id" & $i))
        $iStyle = _WinAPI_GetWindowLong($hControl, $GWL_STYLE)
        Switch $iRemoveOrAdd
            Case 0 ; remove style
                If BitAND($iStyle, $iStyleToAlter) = $iStyleToAlter Then
                    _WinAPI_SetWindowLong($hControl, $GWL_STYLE, BitXOR($iStyle, $iStyleToAlter))
                Endif
            Case 1 ; add style
                If BitAND($iStyle, $iStyleToAlter) <> $iStyleToAlter Then
                    _WinAPI_SetWindowLong($hControl, $GWL_STYLE, BitOR($iStyle, $iStyleToAlter))
                Endif
            Case Else
                MsgBox(0, "", "Scripter, wake up :)")                
        EndSwitch
    Next
EndFunc   ;==>Alter_Style

 

Edited by pixelsearch
added the "scripter, wake up" part
Link to comment
Share on other sites

  • Solution

Here is a hacky way:

#include <WinAPISysWin.au3>
#include <GuiEdit.au3>

HotKeySet('{TAB}', 'Tab')

$hGUI = GUICreate('Test')
$cInput1 = GUICtrlCreateInput('test', 100, 100, 150, 25)
$hInput1 = GUICtrlGetHandle($cInput1)
$cInput2 = GUICtrlCreateInput('', 100, 200, 150, 25)
$cInput3 = GUICtrlCreateInput('', 100, 300, 150, 25)
GUISetState()

Do
Until GUIGetMsg() = -3

Func Tab()
    HotKeySet('{TAB}')
    If _WinAPI_GetFocus() = $hInput1 Then
        _GUICtrlEdit_ReplaceSel($hInput1, @TAB)
    Else
        Send('{TAB}')
    EndIf
    HotKeySet('{TAB}', 'Tab')
EndFunc

 

Link to comment
Share on other sites

11 hours ago, pixelsearch said:

@abberration here is a way to disable / enable  $WS_TABSTOP (or another style) using a function named Alter_Style . You can indicate several controls when calling the function, as shown in the script lines that are commented out. After the style is disabled, the TAB key won't select anymore the control(s) which don't have this style. A similar function should be easy to script to take care of Extended styles.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration

Local $hGUI = GUICreate("TabStop", 316, 207)
Local $Label1 = GUICtrlCreateLabel("Input1", 40, 40, 50, 17, $SS_CENTERIMAGE)
Local $Input1 = GUICtrlCreateInput("123", 100, 40, 170, 20)
Local $Label2 = GUICtrlCreateLabel("Input2", 40, 88, 50, 20, $SS_CENTERIMAGE)
Local $Input2 = GUICtrlCreateInput("456", 100, 90, 170, 20)
Local $idRemoveStyle = GUICtrlCreateButton("Remove TabStop ", 25, 155, 125, 25)
Local $idAddStyle = GUICtrlCreateButton("Add TabStop", 170, 155, 125, 25)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idRemoveStyle
            Alter_Style(0, $WS_TABSTOP, $Input1)
            ; Alter_Style(0, $WS_TABSTOP, $Input1, $Input2)
            ; Alter_Style(0, $WS_TABSTOP, $Input1, $Input2, $idRemoveStyle)

        Case $idAddStyle
            Alter_Style(1, $WS_TABSTOP, $Input1)
            ; Alter_Style(1, $WS_TABSTOP, $Input1, $Input2)
            ; Alter_Style(1, $WS_TABSTOP, $Input1, $Input2, $idRemoveStyle)
    EndSwitch
WEnd

;===========================================
Func Alter_Style($iRemoveOrAdd, $iStyleToAlter, $id1, $id2 = 0, $id3 = 0, $id4 = 0, $id5 = 0, _
    $id6 = 0, $id7 = 0, $id8 = 0, $id9 = 0, $id10 = 0)

    Local $hControl, $iStyle
    For $i = 1 To @NumParams - 2
        $hControl = GUICtrlGetHandle(Eval("id" & $i))
        $iStyle = _WinAPI_GetWindowLong($hControl, $GWL_STYLE)
        Switch $iRemoveOrAdd
            Case 0 ; remove style
                If BitAND($iStyle, $iStyleToAlter) = $iStyleToAlter Then
                    _WinAPI_SetWindowLong($hControl, $GWL_STYLE, BitXOR($iStyle, $iStyleToAlter))
                Endif
            Case 1 ; add style
                If BitAND($iStyle, $iStyleToAlter) <> $iStyleToAlter Then
                    _WinAPI_SetWindowLong($hControl, $GWL_STYLE, BitOR($iStyle, $iStyleToAlter))
                Endif
            Case Else
                MsgBox(0, "", "Scripter, wake up :)")                
        EndSwitch
    Next
EndFunc   ;==>Alter_Style

 

Hi,

thanks for the tip.

Your function stops well the cursor jumping from button to button or input.

But the TAB does not enter the input field.

If I hit TAB nothing is displayed in the input.

Cheers mike

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...