Skysnake Posted November 19, 2020 Share Posted November 19, 2020 (edited) expandcollapse popup#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 November 19, 2020 by Skysnake Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
benners Posted November 19, 2020 Share Posted November 19, 2020 (edited) You could check that the input has lost focus then run a function. expandcollapse popup#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 November 19, 2020 by benners Skysnake 1 Link to comment Share on other sites More sharing options...
Skysnake Posted November 19, 2020 Author Share Posted November 19, 2020 (edited) 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 November 19, 2020 by Skysnake Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Nine Posted November 19, 2020 Share Posted November 19, 2020 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 Skysnake 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Skysnake Posted December 6, 2020 Author Share Posted December 6, 2020 @Nine interesting 🙂 Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
CYCho Posted December 6, 2020 Share Posted December 6, 2020 (edited) 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 December 6, 2020 by CYCho zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
jugador Posted December 6, 2020 Share Posted December 6, 2020 (edited) #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 December 6, 2020 by jugador Skysnake 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now