0manko

Trouble with Shift+enter with FB messenger

19 posts in this topic

Hello,

I'm currently working on a project which include a bot that will reply and do stuff for me through FB messenger. I got most of the stuff working fine buti'm giving up trying to do line break via CTRL+enter / Shift+enter via controlsend 

So here's the problem in facing : 

helpmeplz.thumb.jpg.aa9d8fbb5d15fc5d94fc

I've tried several methods with controlsend and i got no luck, the {shift} doesn't seem to work with {enter} key, instead of going nextline it just send the line as if the shift key was never pressed. Here are some of the different code i tried none of it make a different, all failed.  

func newline()
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line one",1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "^{Enter}")
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line two",1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "^{Enter}")
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line three",1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
EndFunc

func newline2()
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line one",1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{LSHIFT}{Enter}")
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line two",1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{LSHIFT}{Enter}")
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line three",1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
EndFunc

func newline3()
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line one",1)
    
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{SHIFTDOWN}")
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
    sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{SHIFTUP}")
    
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line two",1)
    
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{SHIFTDOWN}")
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
    sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{SHIFTUP}")
    
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "line three",1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
EndFunc

I've also tried making a notepad file of multiple line and copy to clipboard then controlsend paste it, but instead of having 3 sentence i'm getting one long sentence.
The only way i get to make anewline is through On Screen Keyboard with Shift + Enter or pressing manually typing it buti hope that there's some simpler way to achieve it with controlsend.  

CTRL+Enter will also make a new line but I can't get it to work either ... 

 

Share this post


Link to post
Share on other sites



Thanks Jfish, i've tried your method and  it still did not produce the result i was hoping for, instead of sending 3 continuous lines i got 3 separate lines, the best way i could achieve it is still using CTRL+enter style which i failed to do so

func newline4()
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    $multiLineString="Line One" & @crlf & _
    "Line 2" & @crlf & _
    "Line 3"
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", $multiLineString,1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{enter}")
EndFunc

dobubububudobu.thumb.jpg.bed05183b4918d2

Share this post


Link to post
Share on other sites

Thanks Jfish, i've tried your method and  it still did not produce the result i was hoping for, instead of sending 3 continuous lines i got 3 separate lines, the best way i could achieve it is still using CTRL+enter style which i failed to do so

func newline4()
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    $multiLineString="Line One" & @crlf & _
    "Line 2" & @crlf & _
    "Line 3"
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", $multiLineString,1)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{enter}")
EndFunc

dobubububudobu.thumb.jpg.bed05183b4918d2

Share this post


Link to post
Share on other sites

@CRLF is a carriage return with a line feed.  @CR is just a carriage return.  Try @CR instead.  I am not sure what triggers a new line in FB messenger but so some research to figure out how you need to format your string.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Once again same result, i've tried alot of method but none of it trigger line break. Any other suggestion to make linebreak/ctrl+enter to work ?

Share this post


Link to post
Share on other sites
32 minutes ago, JohnOne said:

Analyze a multiline string copied from the app, to determine which char is used for end of line.

Thanks for the suggestion,it seems that this may actually work. Is there any easy method i can used to analyze the string ?
 i saved the multiline text from the FB messenger to the notepad, after that i copy and paste back everything in the notepad and the linebreak remains in the messenger. But soon after i add another line using enter in the notepad everything clump into a sentence back instead of multiline.

I'm assuming that there's a linebreak element in there and is there anyway to determine and replicate it? 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

 

Update:

Things are getting weird again, so i copied and paste the same thing from the messenger, to the notepad, then back to the messenger again and it works perfectly. 

test1.jpg.9c5341ef543aa86a6b5058efa531a9test1r.thumb.jpg.8b19293e62e679142be9a4f

 

But once i added something in between the text it paste it again it went to one full straight line

test2.jpg.62dc2c6e6be8a678dfe0d84efa05c3test2r.thumb.jpg.ee7d50068575d2922285910

 

anyidea what's happening ? 

Edited by 0manko
accidental copy/paste

Share this post


Link to post
Share on other sites
3 minutes ago, JohnOne said:

Copy the text from the app to clipboard.

$aSplit = StringSplit(ClipGet(), "")

For $char In $aSplit
    ConsoleWrite(Asc($char) & @CRLF)
Next

What you get?

line one

line two

line three

51
108
105
110
101
32
111
110
101
13
10
108
105
110
101
32
116
119
111
13
10
108
105
110
101
32
116
104
114
101
101
13
10
13
10

 

Share this post


Link to post
Share on other sites

I've tried controlsend, clipput, both failed :/ 

Btw i'm using IE  with the URL https://www.messenger.com/ and inspect element did not help much, their HTML are really weird 

haywire.jpg

Share this post


Link to post
Share on other sites
1 minute ago, JohnOne said:

And the above string?

i'm using this

$multiLineString="Line One" & Chr(13) & "Line 2" & Chr(13) & "Line 3"

 and just edited abit into my code

func copytoclip()
    $multiLineString="Line One" & Chr(13) & "Line 2" & Chr(13) & "Line 3"
    ClipPut($multiLineString)
EndFunc

Func testsend()
    $multiLineString="Line One" & Chr(13) & "Line 2" & Chr(13) & "Line 3"
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", $multiLineString)
    sleep (100)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
EndFunc

 

Share this post


Link to post
Share on other sites

Update: 

 

this is getting even more confusing ......

This code copy  and paste it like normal CTRL+V and it works fine: 

Func Test1 ()
    $aSplit = ClipGet()
    Sleep (200)
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "^v")
    sleep (100)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
EndFunc

This send text using controlsend and it goes to separate line (both clipboard hold the same stuff i just copied a moment ago): 

Func Test2 ()
    $aSplit = ClipGet()
    Sleep (200)
    ControlFocus($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "", "", 0, 0)
    Sleep(250)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", $aSplit)
    sleep (100)
    ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
EndFunc

whyyyyy.thumb.jpg.1c0e7b2ab87224c101b7e0

 

Is there anyway to just make ctrl+Enter/Shift+enter to work :'( 

Share this post


Link to post
Share on other sites

Final update, i finally got this solved
 

I can finally triggered a new line with this simple code, not sure why controlsend() failed to do {ctrl/shift} but just using send() works 

Send("{CTRLDOWN}")
ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
Send("{CTRLUP}")

 

1 person likes this

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