Jump to content
maniootek

Remove line break from the text pasted to input

Recommended Posts

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

 

Share this post


Link to post
Share on other sites

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 :) 


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.
  :)

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
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 by maniootek

Share this post


Link to post
Share on other sites

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 by Nine

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...