Jump to content

Fire control using keyboard - TAB key and Case statement


Skysnake
 Share

Recommended Posts

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.14.2
    Author:         Skysnake

    Script Function:
    Problem traversing GUI controls (input), populated from another and firing without changing first

    The GUI does not have buttons
    instead the INPUT controls trigger the various CASE statements
    However, the INPUT requires a touch before it fires.
    Is there a way to work around the "touch requirment"?

#ce ----------------------------------------------------------------------------
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>


Local $hGUI = GUICreate("No Button GUI", 600, 400)
Local $input1 = GUICtrlCreateInput("1", 8, 8, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input2 = GUICtrlCreateInput("1", 8, 32, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input3 = GUICtrlCreateInput("0", 8, 56, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)



; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            ExitLoop

        Case $input2
            GUICtrlSetData($input3, GUICtrlRead($input1) + GUICtrlRead($input2))

    EndSwitch
WEnd

The script illustrates the problem very well.

Only when the value of $input2 is changed (type a new value) does the Case statement fire.

Why is this so?

I do not want to retype. I just want it to go.  

This is a very simplified version, but imaging the value is populated from a different function and the user only needs to tab through if happy, reducing the need to touch the values.

I am sure there is a solution, but I cannot find it.

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

You could check that the input has lost focus then run a function.

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.14.2
    Author:         Skysnake

    Script Function:
    Problem traversing GUI controls (input), populated from another and firing without changing first

    The GUI does not have buttons
    instead the INPUT controls trigger the various CASE statements
    However, the INPUT requires a touch before it fires.
    Is there a way to work around the "touch requirment"?

#ce ----------------------------------------------------------------------------
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <guiconstants.au3>

Local $hGUI = GUICreate("No Button GUI", 600, 400)
Local $input1 = GUICtrlCreateInput("1", 8, 8, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input2 = GUICtrlCreateInput("1", 8, 32, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input3 = GUICtrlCreateInput("0", 8, 56, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)


; Display the child GUI.
GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            ExitLoop

        Case $input2
            RunInput2()

    EndSwitch
WEnd

Func RunInput2()
    GUICtrlSetData($input3, GUICtrlRead($input1) + GUICtrlRead($input2))
EndFunc

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam

    Switch $nID
        Case $input2
            Switch $nNotifyCode
                Case $EN_KILLFOCUS
                    RunInput2()
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

 

Edited by benners
Link to comment
Share on other sites

1 hour ago, benners said:

You could check that the input has lost focus then run a function.

That definitely an option.

But in a very big script, that would have to be well managed, and may make execution slow.

 

I like WM_COMMAND option, as it does not interfere with the tab-stop sequence.

 

I do like the lost focus idea - Any idea how to toggle focus on/off in a way that the GUI understands? I have tried to use $GUI_NOFOCUS followed by $GUI_FOCUS but does not change behaviour

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

Maybe you would prefer this approach, where only the precise controls trigger the WindowProc :

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>

Local $hGUI = GUICreate("No Button GUI", 600, 400)
Local $input1 = GUICtrlCreateInput("1", 8, 8, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input2 = GUICtrlCreateInput("1", 8, 32, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input3 = GUICtrlCreateInput("0", 8, 56, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($input1), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
_WinAPI_SetWindowLong(GUICtrlGetHandle($input2), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

GUISetState()

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

GUIDelete($hGUI)
DllCallbackFree($wProcHandle)

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
  ; hwnd = GUICtrlGetHandle($idControl)

  If $Msg = $WM_KILLFOCUS Then GUICtrlSetData($input3, GUICtrlRead($input1) + GUICtrlRead($input2))
  Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam)
EndFunc   ;==>_WindowProc

 

Link to comment
Share on other sites

  • 3 weeks later...

What about a hotkey?
 

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

HotKeySet("{Tab}", "TriggerInput2")

Local $hGUI = GUICreate("No Button GUI", 600, 400)
Local $input1 = GUICtrlCreateInput("1", 8, 8, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input2 = GUICtrlCreateInput("1", 8, 32, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input3 = GUICtrlCreateInput("0", 8, 56, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)

; Loop until the user exits.
While 1
    $sMsg = GUIGetMsg()
    Switch $sMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            ExitLoop

        Case $input2
            GUICtrlSetData($input3, GUICtrlRead($input1) + GUICtrlRead($input2))
            
    EndSwitch
WEnd

Func TriggerInput2()
    $sMsg = $input2
EndFunc

 

Edited by CYCho
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>



Local $hGUI = GUICreate("No Button GUI", 600, 400)
Local $input1 = GUICtrlCreateInput("1", 8, 8, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input2 = GUICtrlCreateInput("1", 8, 32, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))
Local $input3 = GUICtrlCreateInput("0", 8, 56, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER))

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)



; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            ExitLoop

        Case ($input2 Or $input1)
            GUICtrlSetData($input3, GUICtrlRead($input1) + GUICtrlRead($input2))

    EndSwitch
WEnd

 

Edited by jugador
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...