OzoneB Posted December 13, 2018 Share Posted December 13, 2018 I have an AutoIT GUI with an input box. I want to run a check on the input every time the value changes. For example: $myvalue = "hello" $value = GUICtrlCreateInput("",150,75,190,20) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case ???????? If GuiCtrlRead($value) == $myvalue Then ; Enable next field. Else ; Disable next field. EndIf EndSwitch WEnd So any time a key is pressed in that input box the if statement gets executed. I don't know what I should put where I've put the ???? at. Thank you! Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted December 13, 2018 Share Posted December 13, 2018 (edited) Hi @OzoneB, and welcome to the AutoIt forums You have to "capture" the event "change" sent from the Input box To do this, you use a WM_COMMAND Windows Message, capturing the EN_CHANGE Event/Notification code. A little sample for the welcome expandcollapse popup#include <Date.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $frmMainForm = GUICreate("A Form", 235, 62, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") Global $txtInput = GUICtrlCreateInput("", 19, 22, 201, 21) GUICtrlSetFont(-1, 10, 400) GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $hdlWindowFrom, _ $intMessageCode, _ $intControlID_From $intControlID_From = BitAND($wParam, 0xFFFF) $intMessageCode = BitShift($wParam, 16) Switch $intControlID_From Case $txtInput Switch $intMessageCode Case $EN_CHANGE ConsoleWrite("[" & _Now() & "] - The text in the $txtInput control has changed! Text = " & GUICtrlRead($txtInput) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Edited December 13, 2018 by FrancescoDiMuro pixelsearch, OzoneB, Subz and 1 other 4 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
OzoneB Posted December 13, 2018 Author Share Posted December 13, 2018 Thank you @FrancescoDiMuro, that's exactly what I was after Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted December 13, 2018 Share Posted December 13, 2018 @OzoneB Happy to have helped Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
edumanilha Posted February 29, 2020 Share Posted February 29, 2020 On 12/13/2018 at 11:01 AM, FrancescoDiMuro said: Hi @OzoneB, and welcome to the AutoIt forums You have to "capture" the event "change" sent from the Input box To do this, you use a WM_COMMAND Windows Message, capturing the EN_CHANGE Event/Notification code. A little sample for the welcome expandcollapse popup#include <Date.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $frmMainForm = GUICreate("A Form", 235, 62, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") Global $txtInput = GUICtrlCreateInput("", 19, 22, 201, 21) GUICtrlSetFont(-1, 10, 400) GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $hdlWindowFrom, _ $intMessageCode, _ $intControlID_From $intControlID_From = BitAND($wParam, 0xFFFF) $intMessageCode = BitShift($wParam, 16) Switch $intControlID_From Case $txtInput Switch $intMessageCode Case $EN_CHANGE ConsoleWrite("[" & _Now() & "] - The text in the $txtInput control has changed! Text = " & GUICtrlRead($txtInput) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Hello, I need something like this to check changes on a input box...But I tried your example and some others from the forum and nothing worked...Your post is the more recent, I hope it don't count as a necropost...I looked into the rules and couldn't find any expiration date... Now Im trying checks inside a loop but the creatinput keep flashing and I'm having trouble trying to define a pause... Thanks! Link to comment Share on other sites More sharing options...
Nine Posted February 29, 2020 Share Posted February 29, 2020 Post your own code, so we can see what is wrong... “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...
edumanilha Posted February 29, 2020 Share Posted February 29, 2020 (edited) 19 minutes ago, Nine said: Post your own code, so we can see what is wrong... I tried a lot of If's And's switch and everything...I'm thinking to change the approach to this WM_COMMAND...Maybe will be a cleaner solution...The way I'm checking the input keeps flashing and turns even difficult to type! the code right now... expandcollapse popup;text from input Global $destino = ControlGetText("GUI2", "", $Final) ;check if have at least 3 octets Global $StartSpliting = StringRegExp($destino,"((?:\d{1,3}\.){2}\d{1,3})") ;check if all octets have been filled Global $IPFull = StringRegExp($destino,"((?:\d{1,3}\.){3}\d{1,3})") ;MsgBox(48, "", $StartSpliting,20) ;empty branch number If $destino = "" And $Filial <> $destino then $Filial = $destino GUICtrlSetData($labelfilialdest,"Filial: ") EndIf If $StartSpliting = 1 Then Global $IPdestino = StringSplit($destino,".") If $IPdestino[1] = 10 And $IPdestino[2] < 254 Then If $IPdestino[2] <> $Filial Then $Filial = $IPdestino[2] GUICtrlSetData($labelfilialdest,"Filial: " & $Filial) ;MsgBox(48, "", $destino & "segundo octeto") GUICtrlSetColor($Final, 0xFF0000) EndIf ElseIf $IPdestino[1] = 10 And $IPdestino[2] = 254 And $IPdestino[3] = 0 Then If $IPdestino[2] <> $Filial Then $Filial = $IPdestino[2] GUICtrlSetData($labelfilialdest,"Filial: " & $Filial) ;MsgBox(48, "", $destino & "segundo octeto") GUICtrlSetColor($Final, 0xFF0000) EndIf ElseIf $IPdestino[1] = 10 And $IPdestino[2] == 254 And $IPdestino[3] >= 1 Then If $IPdestino[2] + $IPdestino[3] <> $Filial Then $Filial = $IPdestino[2]+$IPdestino[3] GUICtrlSetData($labelfilialdest,"Filial: " & $Filial) ;MsgBox(48, "", $destino & "segundo e terceiro octeto") GUICtrlSetColor($Final, 0xFF0000) EndIf EndIf ElseIf $IPFull = 1 Then Global $IPdestino = StringSplit($destino,".") Global $Return = _ValidIP($destino) If $Return < 0 Then Switch @error Case 1 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 1 - IP address starts with an invalid number = 0, 127 , 169 or is > 239") Case 2 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 2 - one of the octets of the IP address is out of the range 0-255 or contains invalid characters") Case 3 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 3 - IP Address is not a valid dotted IP address (ex. valid address 190.40.100.20)") Case 4 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 4 - Last octet is either 0 or 255") EndSwitch Else GUICtrlSetColor($Final, 0x00CC00) ;MsgBox(48, "", $destino & " is a valid Class " & $Return[5] & " IP address") EndIf Edited February 29, 2020 by edumanilha worng code Link to comment Share on other sites More sharing options...
Nine Posted February 29, 2020 Share Posted February 29, 2020 Sorry but this code is not runable. Please make it short and runable. Remove all unnecessary code and leave what is causing the problem... “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...
edumanilha Posted February 29, 2020 Share Posted February 29, 2020 (edited) 48 minutes ago, Nine said: Sorry but this code is not runable. Please make it short and runable. Remove all unnecessary code and leave what is causing the problem... expandcollapse popup#NoTrayIcon #include <GUIConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <GDIPlus.au3> #include <GuiButton.au3> #include <GuiImageList.au3> #include <WinAPIGdi.au3> #include <SendMessage.au3> $IP1 = StringSplit("192.168.6.10",".") ;CHECAR REDE $Octeto = $IP1 $Filial = $Octeto[2] + $Octeto [3] $Form2 = GUICreate ("GUI2", 600, 190) GUICtrlCreatePic(@ScriptDir & "\Dados\Imagens\background.bmp",0,0,0,0,$SS_WHITERECT) GUISetState(@SW_SHOW, $Form2) ;botão 4 insert IP $Final = GUICtrlCreateInput($Octeto[1] & "." & $Octeto[2] & "." & $Octeto[3] & ".", 435, 40, 140, 20,$SS_CENTER) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetFont(-1,11,600,0,"Arial",5) GUICtrlSetTip(-1, "Preenche ao abrir, com seus 3 primeiros octetos da sua rede atual." & @CRLF & "Caso deseje conectar em outro local, basta apagar e preencher o IP que deseja.") WinSetOnTop(-1, "", $WINDOWS_ONTOP) GUICtrlSetBkColor(-1, 0x000000) ;GuiCtrlSetState($Form2, $GUI_ONTOP) ;Global $destino = ControlGetText("GUI2", "", $Final) ;comentário botão user/comandos Global $labelfilialdest = GUICtrlCreateLabel("Filial: " & $Filial, 430, 65, 150, 20,$SS_CENTER) GUICtrlSetColor(-1, 0x00000) GUICtrlSetFont(-1, 11, 600, 0, "Arial", 5) while 1 ;text from input Global $destino = ControlGetText("GUI2", "", $Final) ;check if have at least 3 octets Global $StartSpliting = StringRegExp($destino,"((?:\d{1,3}\.){2}\d{1,3})") ;check if all octets have been filled Global $IPFull = StringRegExp($destino,"((?:\d{1,3}\.){3}\d{1,3})") ;MsgBox(48, "", $StartSpliting,20) ;empty branch number If $destino = "" And $Filial <> $destino then $Filial = $destino GUICtrlSetData($labelfilialdest,"Filial: ") EndIf If $StartSpliting = 1 Then Global $IPdestino = StringSplit($destino,".") If $IPdestino[1] = 10 And $IPdestino[2] < 254 Then If $IPdestino[2] <> $Filial Then $Filial = $IPdestino[2] GUICtrlSetData($labelfilialdest,"Filial: " & $Filial) ;MsgBox(48, "", $destino & "segundo octeto") GUICtrlSetColor($Final, 0xFF0000) EndIf ElseIf $IPdestino[1] = 10 And $IPdestino[2] = 254 And $IPdestino[3] = 0 Then If $IPdestino[2] <> $Filial Then $Filial = $IPdestino[2] GUICtrlSetData($labelfilialdest,"Filial: " & $Filial) ;MsgBox(48, "", $destino & "segundo octeto") GUICtrlSetColor($Final, 0xFF0000) EndIf ElseIf $IPdestino[1] = 10 And $IPdestino[2] == 254 And $IPdestino[3] >= 1 Then If $IPdestino[2] + $IPdestino[3] <> $Filial Then $Filial = $IPdestino[2]+$IPdestino[3] GUICtrlSetData($labelfilialdest,"Filial: " & $Filial) ;MsgBox(48, "", $destino & "segundo e terceiro octeto") GUICtrlSetColor($Final, 0xFF0000) EndIf EndIf EndIf If $IPFull = 1 Then Global $IPdestino = StringSplit($destino,".") Global $Return = _ValidIP($destino) If $Return < 0 Then Switch @error Case 1 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 1 - IP address starts with an invalid number = 0, 127 , 169 or is > 239") Case 2 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 2 - one of the octets of the IP address is out of the range 0-255 or contains invalid characters") Case 3 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 3 - IP Address is not a valid dotted IP address (ex. valid address 190.40.100.20)") Case 4 MsgBox(64, "", "Error in IP address: " & $destino & @LF & "Error code is: 4 - Last octet is either 0 or 255") EndSwitch Else GUICtrlSetColor($Final, 0x00CC00) ;MsgBox(48, "", $destino & " is a valid Class " & $Return[5] & " IP address") EndIf Else GUICtrlSetColor($Final, 0xFF0000) EndIf WEnd Func _ValidIP($sIP) Local $adIPAddressInfo[6] Local $aArray = StringSplit($sIP, ".", 2) If Not IsArray($aArray) Or UBound($aArray) <> 4 Then Return SetError(3, 0, -1) Local $dString = "0x" If $aArray[0] <= 0 Or $aArray[0] > 239 Or $aArray[0] = 127 Or $aArray[0] = 169 Then Return SetError(1, 0, -1) EndIf For $I = 0 To 3 If $I < 3 Then If $aArray[$I] < 0 Or $aArray[$I] > 255 Or Not StringIsDigit($aArray[$I]) Then Return SetError(2, 0, -1) EndIf Else If Not StringIsDigit($aArray[$I]) Then Return SetError(2, 0, -1) EndIf If $aArray[$I] < 1 Or $aArray[$I] > 254 Then Return SetError(4, 0, -1) EndIf EndIf $dString &= StringRight(Hex($aArray[$I]), 2) $adIPAddressInfo[$I] = $aArray[$I] Next $adIPAddressInfo[4] = $dString Switch $aArray[0] Case 1 To 126 $adIPAddressInfo[5] = "A" Return $adIPAddressInfo Case 128 To 191 $adIPAddressInfo[5] = "B" Return $adIPAddressInfo Case 192 To 223 $adIPAddressInfo[5] = "C" Return $adIPAddressInfo Case 224 To 239 $adIPAddressInfo[5] = "D" Return $adIPAddressInfo EndSwitch EndFunc ;==>_ValidIP I kept only the basic now...Thanks! But About WM_COMMAND, do you have any working example? It may be usefull tomorrow... EDIT: I found one WM working example! Edited February 29, 2020 by edumanilha Link to comment Share on other sites More sharing options...
edumanilha Posted February 29, 2020 Share Posted February 29, 2020 When I put GUIRegisterMsg($WM_COMMAND,'WM_COMMAND'), on my input...my buttons stop working... Link to comment Share on other sites More sharing options...
Subz Posted February 29, 2020 Share Posted February 29, 2020 (edited) @edumanilha Just use _GuiCtrlIPAddress_... functions example: #include <GUIConstantsEx.au3> #include <GuiIPAddress.au3> Example() Func Example() Local $sIPAddress = "192.168.6.10" Local $hGui = GUICreate("IP Address Control", 260, 30) Local $hIPAddress = _GUICtrlIpAddress_Create($hGui, 5, 5, 125, 20) Local $idIPAddress = GUICtrlCreateButton("IP Address", 130, 4, 125, 22) GUISetState(@SW_SHOW) _GUICtrlIpAddress_Set($hIPAddress, $sIPAddress) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idIPAddress MsgBox(4096, "IP Address", "IP Address = " & _GUICtrlIpAddress_Get($hIPAddress)) EndSwitch WEnd EndFunc Edited March 1, 2020 by Subz edumanilha 1 Link to comment Share on other sites More sharing options...
edumanilha Posted February 29, 2020 Share Posted February 29, 2020 9 minutes ago, Subz said: @edumanilha Just use _GuiCtrlIPAddress_... functions example: #include <GUIConstantsEx.au3> #include <GuiIPAddress.au3> Example() Func Example() Local $sIPAddress = "192.168.6.10" Local $hGui = GUICreate("IP Address Control IsBlank Example", 260, 30) Local $hIPAddress = _GUICtrlIpAddress_Create($hGui, 5, 5, 125, 20) Local $idIPAddress = GUICtrlCreateButton("IP Address", 130, 4, 125, 22) GUISetState(@SW_SHOW) _GUICtrlIpAddress_Set($hIPAddress, $sIPAddress) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idIPAddress MsgBox(4096, "IP Address", "IP Address = " & _GUICtrlIpAddress_Get($hIPAddress)) EndSwitch WEnd EndFunc OMG! Thank you...I didn't saw this... 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