Jump to content

Step numeric value in inputbox using keys


 Share

Go to solution Solved by Melba23,

Recommended Posts

I am developing a small application to change various parameters in a program.

The parameters are numeric only and can be integer.

I would like the fine-tuning of these parameters to be as simple as possible. Of course I can just let the operator type in replacement value, but this gets tedious with 4-5 digit parameter values.

I have two different ideas / paths:

  • when the field has focus, use some keys to change to next/previous value, like a spinner. Preferably up/down keys. Adobe designsoftware works like this, if you have tried them. Probably different controls though.
  • have some general up/down buttons (or the Windows up/down control ?) that change value that just had / has focus.
Only I am not really sure how to deal with the focus / focus-lost issue.

My program is not using onevent mode.

Thanks for any help

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

  • Moderators

Myicq,

Perhaps something like this: :huh:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

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

$cInput = GUICtrlCreateInput("999", 10, 10, 200, 20)
$hInput = GUICtrlGetHandle($cInput)

$cButton = GUICtrlCreateButton("Focus Taker", 10, 100, 100, 30)

$cUp = GUICtrlCreateDummy()
$cDown = GUICtrlCreateDummy()

GUISetState()

; Set GUIAccelerators for the dummy controlIDs
Global $aAccelKeys[2][2] = [["{UP}", $cUp],["{DOWN}", $cDown]]
GUISetAccelerators($aAccelKeys)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cUp
            If _WinAPI_GetFocus() = $hInput Then
                $iValue = GUICtrlRead($cInput) + 1
                If $iValue = 1001 Then $iValue = 0
                GUICtrlSetData($cInput, $iValue)
            EndIf
        Case $cDown
            If _WinAPI_GetFocus() = $hInput Then
                $iValue = GUICtrlRead($cInput) - 1
                If $iValue = -1 Then $iValue = 1000
                GUICtrlSetData($cInput, $iValue)
            EndIf
    EndSwitch
WEnd

I hope it is of use. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

M23,

it did help me a long way, thanks.

How can I make this code more generalized for use with 4-8 input boxes ? I have seen before that DummyControls have been used to "border off" other controls, like this

$before = guictrlcreatedummy()
$i1 = guictrlcreateinput(...)
$i2 = guictrlcreateinput(...)
...
$after = guictrlcreatedummy()

then check the id of the control if it's between $before and $after.

Just forgot how :(

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

  • Moderators
  • Solution

Myicq,

I would use an array like this:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

; Number of inputs
Global $iCount = 3
; Array to hold input ControlID and handle
Global $aInput[$iCount + 1][2] = [[$iCount]]

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

For $i = 1 To $iCount
    ; Store the ControlID and handle
    $aInput[$i][0] = GUICtrlCreateInput("999", 10, 20 * $i, 200, 20)
    $aInput[$i][1] = GUICtrlGetHandle($aInput[$i][0])
Next

$cButton = GUICtrlCreateButton("Focus Taker", 380, 10, 100, 30)

$cUp = GUICtrlCreateDummy()
$cDown = GUICtrlCreateDummy()

GUISetState()

; Set GUIAccelerators for the dummy controlIDs
Global $aAccelKeys[2][2] = [["{UP}", $cUp],["{DOWN}", $cDown]]
GUISetAccelerators($aAccelKeys)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cUp
            ; Get handle of focused control
            $hFocus = _WinAPI_GetFocus()
            ; See if it is an input
            For $i = 1 To $iCount
                If $aInput[$i][1] = $hFocus Then
                    ; Chnage the input
                    $iValue = GUICtrlRead($aInput[$i][0]) + 1
                    If $iValue = 1001 Then $iValue = 0
                    GUICtrlSetData($aInput[$i][0], $iValue)
                    ; No point in looping any more
                    ExitLoop
                EndIf
            Next
        Case $cDown
            $hFocus = _WinAPI_GetFocus()
            For $i = 1 To $iCount
                If $aInput[$i][1] = $hFocus Then
                    $iValue = GUICtrlRead($aInput[$i][0]) - 1
                    If $iValue = -1 Then $iValue = 1000
                    GUICtrlSetData($aInput[$i][0], $iValue)
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

All clear? :)

M23

Edited by Melba23
Copy paste error fixed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

M23,

your thankful input inspired me to what I think will be the solution. Sort of along the way you suggest, but not quite.

My solution was:

Case $cUp
        for $i = $cInput1 to $cInput4
            if _WinAPI_GetFocus() = GuiCtrlGetHandle($i) Then
                 $iValue = GuiCtrlRead($i) +1
                 GuiCtrlSetData($i, $iValue)
            EndIf
         next

That way I do not have to create variables for handle. Just need to make sure inputs are following each other in design.

Similar for $cDown

Thanks for your suggestions again, especially about the Accelerators ! That will come in handy many places.

- myicq.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

  • Moderators

Myicq,

I would suggest adding an ExitLoop before the EndIf as I did - why continue the loop if you have already identifed the focused input? ;)

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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