maniootek Posted February 10, 2020 Share Posted February 10, 2020 I have some text in other app and I wan to copy it and paste to my input in my gui but when I copy it I always get line break before that text. Quote some text before "some text" there is line break and I can't paste it to my input in gui I could change my input to edit control but I don't want to accept line break in my "input/edit" as this is designed to accept only 1-line text. Is there a trick to remove this line break (@CRLF) from the clipboard? Can I make some action (remove line breaks) while text is pasting to the input? Sample code: #include <GUIConstantsEx.au3> ClipPut(@CRLF & "12356") Example() Func Example() GUICreate("My script", 200, 200) Local $idInput = GUICtrlCreateInput("CTRL+V HERE", 5, 5, 190) Local $idButton = GUICtrlCreateButton("load info", 50, 25, 100) GUICtrlSetState(-1, 512) ;512 = $GUI_DEFBUTTON GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox(0, Default, "Entered ID=" & GUICtrlRead($idInput)) EndSwitch WEnd EndFunc Link to comment Share on other sites More sharing options...
Developers Jos Posted February 10, 2020 Developers Share Posted February 10, 2020 Something like this? #include <GUIConstantsEx.au3> ClipPut(@CRLF & "12356") Example() Func Example() GUICreate("My script", 200, 200) Local $idInput = GUICtrlCreateEdit("CTRL+V HERE", 5, 5, 190,20) Local $idButton = GUICtrlCreateButton("load info", 50, 25, 100) GUICtrlSetState(-1, 512) ;512 = $GUI_DEFBUTTON GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox(0, Default, "Entered ID=" & GUICtrlRead($idInput)) EndSwitch If StringInStr(GUICtrlRead($idInput),@CRLF) then GUICtrlSetData($idInput,StringReplace(GUICtrlRead($idInput),@CRLF,"")) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : StringReplace(GUICtrlRead($idInput),@CRLF,"") = ' & StringReplace(GUICtrlRead($idInput),@CRLF,"") & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndIf WEnd EndFunc Jos maniootek 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted February 10, 2020 Share Posted February 10, 2020 A different approach, that will replace any vertical characters (only when pasting) : #include <Constants.au3> #include <GUIConstants.au3> #include <WinAPI.au3> $sString = @CRLF & "This " & @LF & "is a" & @CR & " test" & @CRLF ClipPut($sString) Example() Func Example() GUICreate("My script", 200, 200) Local $idInput = GUICtrlCreateInput("CTRL+V HERE", 5, 5, 190) Local $idButton = GUICtrlCreateButton("load info", 50, 25, 100) GUICtrlSetState(-1, $GUI_DEFBUTTON) GUISetState() Local $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") Global $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($idInput), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox(0, Default, "Entered ID=" & GUICtrlRead($idInput)) EndSwitch WEnd DllCallbackFree($wProcHandle) EndFunc ;==>Example Func _WindowProc($hWnd, $iMsg, $wParam, $lParam) If $iMsg = $WM_PASTE Then _WinAPI_SetWindowText($hWnd, StringRegExpReplace(ClipGet(), "(\v)", "")) Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WindowProc maniootek 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...
Subz Posted February 10, 2020 Share Posted February 10, 2020 Or use StringStripWS (ClipGet(), 3) to remove any leading/trailing white space. Link to comment Share on other sites More sharing options...
maniootek Posted February 11, 2020 Author Share Posted February 11, 2020 (edited) 16 hours ago, Nine said: A different approach, that will replace any vertical characters (only when pasting) : #include <Constants.au3> #include <GUIConstants.au3> #include <WinAPI.au3> $sString = @CRLF & "This " & @LF & "is a" & @CR & " test" & @CRLF ClipPut($sString) Example() Func Example() GUICreate("My script", 200, 200) Local $idInput = GUICtrlCreateInput("CTRL+V HERE", 5, 5, 190) Local $idButton = GUICtrlCreateButton("load info", 50, 25, 100) GUICtrlSetState(-1, $GUI_DEFBUTTON) GUISetState() Local $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") Global $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($idInput), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox(0, Default, "Entered ID=" & GUICtrlRead($idInput)) EndSwitch WEnd DllCallbackFree($wProcHandle) EndFunc ;==>Example Func _WindowProc($hWnd, $iMsg, $wParam, $lParam) If $iMsg = $WM_PASTE Then _WinAPI_SetWindowText($hWnd, StringRegExpReplace(ClipGet(), "(\v)", "")) Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WindowProc It paste doubled value when copied value has no vertical characters, any idea? There is also problem with DllCallBackFree function - it slow down exit and return red error in console !>12:31:43 AutoIt3.exe ended.rc:-1073740771 Edited February 11, 2020 by maniootek Link to comment Share on other sites More sharing options...
Nine Posted February 11, 2020 Share Posted February 11, 2020 (edited) Put a GUIDelete () before the DllCallBackFree function. It will solve the slow exit. That is not a problem on Win7, only on Win10. As for the double values, I cannot replicate this either with Win7 and Win10. What version of autoIt are you using ? Edited February 11, 2020 by Nine “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...
maniootek Posted February 11, 2020 Author Share Posted February 11, 2020 1 hour ago, Nine said: Put a GUIDelete () before the DllCallBackFree function. It will solve the slow exit. slow exit is fixed no 1 hour ago, Nine said: As for the double values, I cannot replicate this either with Win7 and Win10. Just change this line Quote $sString = @CRLF & "This " & @LF & "is a" & @CR & " test" & @CRLF to: Quote $sString = "test" Run the script and type CTRL+V. In my PC I got "testtest" value in the input box. You can also check my movie here 1 hour ago, Nine said: What version of autoIt are you using ? AutoIt 3.3.14.5 Windows 10 PRO 64-bit Link to comment Share on other sites More sharing options...
Nine Posted February 11, 2020 Share Posted February 11, 2020 Change the function to this one : Func _WindowProc($hWnd, $iMsg, $wParam, $lParam) If $iMsg = $WM_PASTE Then _WinAPI_SetWindowText($hWnd, StringRegExpReplace(ClipGet(), "(\v)", "")) Return EndIf Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WindowProc Tested on Win10, now working... maniootek 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...
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