Keketoco00 Posted Monday at 02:48 AM Posted Monday at 02:48 AM Hello everyone! I'm a beginner and I'm not very familiar with the commands yet. I'm having trouble limiting the text in Edit. I set the limit to 15 characters with the command GUICtrlSetLimit(-1, 15), but since I want the name to end with "-PC", the command GUICtrlSetLimit doesn't identify the "-PC" as typed and the limit is 18. I can do this, but I don't think it's the right method. I also believe that this method of typing in two boxes simultaneously is not the right one. I would like it to only send the contents of $Edit2 to $Edit4 when I type, and not when I click with the cursor. Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) If $Edit2 = 24 Then If StringLen(GUICtrlRead($Edit2)) <= 12 Then ;Here I put $Edit2 because when I put $Edit4 <= 15 it types 16 characters GUICtrlSetData($Edit4, LimitCaracte($Edit2) & "-PC") EndIf EndIf EndFunc
funkey Posted Monday at 08:29 AM Posted Monday at 08:29 AM (edited) I always use this function : RestrictControlRegExp But the code is corrupt so here the files. BR funkey RESTRICTCONTROLREGEXP_TEST.AU3 RestrictControlRegExp.au3 Edited Monday at 08:30 AM by funkey Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
ioa747 Posted Monday at 11:24 AM Posted Monday at 11:24 AM (edited) different approach expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WinAPIDlg.au3> _Main() Func _Main() Local $hGUI = GUICreate("Example", 250, 100) GUICtrlCreateLabel("Type name here (max 12 chars)", 20, 20) Local $idEditName = GUICtrlCreateEdit("", 20, 40, 160, 20, $ES_AUTOHSCROLL) GUICtrlSetLimit($idEditName, 12) Local $idEditResult = GUICtrlCreateEdit("", 20, 65, 160, 20, $ES_READONLY, 0) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ; Check if the active control is $idEditName If _WinAPI_GetDlgCtrlID(ControlGetHandle($hGUI, "", ControlGetFocus($hGUI))) = $idEditName Then Local $sValue = _InputLimiter($idEditName) If $sValue <> "" Then GUICtrlSetData($idEditResult, $sValue) EndIf WEnd EndFunc Func _InputLimiter($iCtrlInput, $iMaxBaseLength = 12, $sSuffix = "-PC") Local Static $sLastValue Local $sCurrentValue = GUICtrlRead($iCtrlInput) If $sCurrentValue <> $sLastValue Then $sLastValue = $sCurrentValue Return StringLeft($sCurrentValue, $iMaxBaseLength) & $sSuffix EndIf Return "" EndFunc Edit: variant with more advanced limiter Func _InputLimiter($iCtrlInput, $iMaxBaseLength = 12, $sSuffix = "-PC") Local Static $sLastValue Local $sCurrentValue = GUICtrlRead($iCtrlInput) Local $sFilteredValue = StringRegExpReplace($sCurrentValue, "[^a-zA-Z0-9]", "") If $sFilteredValue <> $sCurrentValue Then GUICtrlSetData($iCtrlInput, $sFilteredValue) Return "" EndIf If $sFilteredValue <> $sLastValue Then $sLastValue = $sFilteredValue ; Update static ConsoleWrite("$sCurrentValue=" & $sCurrentValue & @CRLF) ; For debugging Return StringLeft($sFilteredValue, $iMaxBaseLength) & $sSuffix EndIf Return "" EndFunc Edited Monday at 04:17 PM by ioa747 variant with more advanced limiter argumentum and Keketoco00 2 I know that I know nothing
Keketoco00 Posted Monday at 05:49 PM Author Posted Monday at 05:49 PM (edited) 9 hours ago, funkey said: I always use this function : RestrictControlRegExp But the code is corrupt so here the files. BR funkey RESTRICTCONTROLREGEXP_TEST.AU3 788 B · 4 downloads RestrictControlRegExp.au3 5 kB · 5 downloads funkey I couldn't adapt this command to my script. However, ioa747 helped me with this. Anyway, I appreciate your help. 6 hours ago, ioa747 said: #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WinAPIDlg.au3> _Main() Func _Main() Local $hGUI = GUICreate("Example", 250, 100) GUICtrlCreateLabel("Type name here (max 12 chars)", 20, 20) Local $idEditName = GUICtrlCreateEdit("", 20, 40, 160, 20, $ES_AUTOHSCROLL) GUICtrlSetLimit($idEditName, 12) Local $idEditResult = GUICtrlCreateEdit("", 20, 65, 160, 20, $ES_READONLY, 0) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ; Check if the active control is $idEditName If _WinAPI_GetDlgCtrlID(ControlGetHandle($hGUI, "", ControlGetFocus($hGUI))) = $idEditName Then Local $sValue = _InputLimiter($idEditName) If $sValue <> "" Then GUICtrlSetData($idEditResult, $sValue) EndIf WEnd EndFunc Func _InputLimiter($iCtrlInput, $iMaxBaseLength = 12, $sSuffix = "-PC") Local Static $sLastValue Local $sCurrentValue = GUICtrlRead($iCtrlInput) If $sCurrentValue <> $sLastValue Then $sLastValue = $sCurrentValue Return StringLeft($sCurrentValue, $iMaxBaseLength) & $sSuffix EndIf Return "" EndFunc iao747 Thank you very much for your answer. It worked very well for me. I adapted it to use WM_COMMAND. I don't know if it's a problem, but I prefer it this way. 6 hours ago, ioa747 said: Func _InputLimiter($iCtrlInput, $iMaxBaseLength = 12, $sSuffix = "-PC") Local Static $sLastValue Local $sCurrentValue = GUICtrlRead($iCtrlInput) Local $sFilteredValue = StringRegExpReplace($sCurrentValue, "[^a-zA-Z0-9]", "") If $sFilteredValue <> $sCurrentValue Then GUICtrlSetData($iCtrlInput, $sFilteredValue) Return "" EndIf If $sFilteredValue <> $sLastValue Then $sLastValue = $sFilteredValue ; Update static ConsoleWrite("$sCurrentValue=" & $sCurrentValue & @CRLF) ; For debugging Return StringLeft($sFilteredValue, $iMaxBaseLength) & $sSuffix EndIf Return "" EndFunc Since I want to block special characters only when I type in the second edit, I chose to call StringRegExpReplace only for the second edit. This way, I can type "ä" in $Edit2 and "a" will appear in $Edit4. Example: Func _LimitCaracte($Caracte) $string = GUICtrlRead($Caracte) $string1 = StringRegExpReplace($string, "[ä]", "a") Return $string1 EndFunc Edited Monday at 06:02 PM by Keketoco00 ioa747 1
Keketoco00 Posted Tuesday at 06:47 PM Author Posted Tuesday at 06:47 PM (edited) Can anyone tell me how I can make the focus stay when I type and not when I click Edit? Edited Tuesday at 07:08 PM by Keketoco00
argumentum Posted Tuesday at 07:25 PM Posted Tuesday at 07:25 PM 37 minutes ago, Keketoco00 said: Can anyone tell me how I can make the focus stay when I type and not when I click Edit? Explain your self. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Keketoco00 Posted Tuesday at 08:54 PM Author Posted Tuesday at 08:54 PM (edited) 1 hour ago, argumentum said: Explique-se. I would like to know if there is a command that detects when I type an edit. Example: If "I typed in the Edit control", then Edited Tuesday at 08:57 PM by Keketoco00
Nine Posted Tuesday at 10:22 PM Posted Tuesday at 10:22 PM 1 hour ago, Keketoco00 said: "I typed in the Edit control Of course, but it is not clear what you want to do. You must make you request clear enough otherwise we will just do away. “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Solution Keketoco00 Posted Tuesday at 11:16 PM Author Solution Posted Tuesday at 11:16 PM (edited) 1 hour ago, Nine said: Claro, mas não está claro o que você quer fazer. Você precisa deixar sua solicitação clara o suficiente, caso contrário, simplesmente a rejeitaremos. I don't know which words to use because the translator changes them. I'm using the wm_command command to type two edits at the same time, but when I click on $Edit1, it automatically sends the text to $Edit2. And I would like it to send the text only after I edit something. I think the EN_CHANGE command does this, but I didn't know how to use it in AutoIT. The way iao747 sent it worked partially. If there is already some text in $Edit1, it automatically sends it to $Edit2. I hope I understood. Edit: with a little research I ended up getting it. If _WinAPI_HiWord($wParam) = $EN_CHANGE Then GUICtrlSetData($Edit2, GUICtrlRead($Edit1)) EndIf Edited Tuesday at 11:33 PM by Keketoco00 argumentum 1
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