Sign in to follow this  
Followers 0
Raizeno

ClipPut () doesn't work properly

16 posts in this topic

So i have 2 strings $txt1 and $txt2 

What I'm trying to do is :

Hotkeyset ("{F9}","text1")

Hotkeyset ("{F10}","text2")

Func text1 ()

Clipput($txt1)

Send("^v")

Endfunc

Func text2 ()

Clipput($txt2)

Send("^v")

Endfunc

 

So i want to paste each of those strings at the press of a button 

Here is where it gets weird : when i try to do this in the android emulator Bluestacks if i press F9 then F10 instead of geting both strings pasted i get txt1 pasted twice and this goes on like that . Seems like clipput doesn't work properly with this emulator any ideeas why ?

I also tried this in notepad and works as intended so i dont think it's something wrong with my script...

 

 

Share this post


Link to post
Share on other sites



I opened it up too and get the same problem. Doesn't look like it's an issue with autoit but rather an issue with the way the android emulator stores the clipboard buffer. That or it's something to do with the Ctrl key. It seemed like there was an issue doing Ctrl+A when I was trying to highlight my editor.

You could try doing ControlSend instead. This script seemed to send the string pretty fast

AutoItSetOption("SendKeyDelay", 0)
AutoItSetOption("SendKeyDownDelay", 0)

Hotkeyset ("{F9}","text1")
Hotkeyset ("{F10}","text2")

Global $txt1 = "Test string 1"
Global $txt2 = "Test string 2"

While 1
    Sleep(100)
WEnd

Func text1()
    ControlSend("BlueStacks App Player", "", "", $txt1)
Endfunc

Func text2()
    ControlSend("BlueStacks App Player", "", "", $txt2)
Endfunc

 

Share this post


Link to post
Share on other sites

You have to give the OS time to store and organise the data in the clipboard. Try adding a short sleep after Clipput()


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

I added sleep (2000) after ClipPut and it still doesn't work i get the same text pasted twice although im not pressing the same hotkey twice .

 

Share this post


Link to post
Share on other sites
Func text1()
    Do
        ClipPut($txt1)
        Sleep(10)
    Until ClipGet() = $txt1
    Send("^v")
EndFunc   ;==>text1

Func text2()
    Do
        ClipPut($txt2)
        Sleep(10)
    Until ClipGet() = $txt2
    Send("^v")
EndFunc

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

That doesn't solve it either i still get the same results . It's like the paste comes from somewhere else ....

Share this post


Link to post
Share on other sites

Are you using any kind of clipboard manager?

Share this post


Link to post
Share on other sites

No .

i even tried this on 2 computers and the results are the same .

Share this post


Link to post
Share on other sites
Func text1()
    Do
        ClipPut($txt1)
        Sleep(10)
    Until ClipGet() = $txt1
    Send("^v")
EndFunc   ;==>text1

Func text2()
    Do
        ClipPut($txt2)
        Sleep(10)
    Until ClipGet() = $txt2
    Send("^v")
EndFunc

 

That's exactly what I did to! He's right though, it still didn't work.

Did a little googling and it turns out I was pretty close, it's something to do with the Control key. If you do {CtrlDown}, sleep, then {v} it will work properly. I guess it's same way the bluestacks player is getting the ctrl key from windows

Hotkeyset ("{F9}","text1")
Hotkeyset ("{F10}","text2")

Global $txt1 = "Test string 1"
Global $txt2 = "Test string 2"

While 1
    Sleep(100)
WEnd

Func text1()
    ClipPut($txt1)
    Send("{CtrlDown}")
    Sleep(500)
    Send("{v}")
    Send("{CtrlUp}")
Endfunc

Func text2()
    ClipPut($txt2)
    Send("{CtrlDown}")
    Sleep(500)
    Send("{v}")
    Send("{CtrlUp}")
Endfunc

This works for me

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Still doesn't work . 

I think android has it's own clipboard and there is a built in timer till it imports the windows clipboard. I mean the frequency of the recheck .

That's the only thing that makes sense. 

Edited by Raizeno

Share this post


Link to post
Share on other sites

me, me, me. I've got it !

AutoItSetOption("SendKeyDelay", 10)
AutoItSetOption("SendKeyDownDelay", 10)

Hotkeyset ("{ESC}","bye")
Hotkeyset ("{F9}","text1")
Hotkeyset ("{F10}","text2")

Global $txt1 = "Test string 1"
Global $txt2 = "Test string 2"

While 1
    Sleep(100)
WEnd

Func bye()
    Exit
EndFunc

Func text1()
    Send($txt1)
Endfunc

Func text2()
    Send($txt2)
Endfunc

try that :)

Share this post


Link to post
Share on other sites

@JohnOne , out of topic but still a somewhat relevant question. Back in the days of DOS, one would load the keyboard buffer. Can that be done with windows OS ?

Share this post


Link to post
Share on other sites

I honestly don't even know what that means, my first encounter with a PC was windows xp about 7 years ago.

If I were to guess though, I'd the likes of send and it's windows api (probably sendinput) do not go near the actual keyboard, which is what I suspect it might have done in the dos.

When I've searched in the past for how to avoid automation detection, the same answer always pooped up... "if you want to do that, you need to write your own driver".

But when dos was out, probably a driver to me, was the man I paid my bus fare to.

1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Still doesn't work . 

I think android has it's own clipboard and there is a built in timer till it imports the windows clipboard. I mean the frequency of the recheck .

That's the only thing that makes sense. 

I don't think it works that way. I googled BlueStacks Ctrl v and people said to long press Ctrl and then v (also a and c for all/copy). Makes me more or less think that the window is waiting for the ctrl key to be registered to the GUI. When it recognizes that it's been pressed/is pressed it starts copying the clipboard from windows and starts converting it into a format that is valid for android. It's like there's a Hotkey (more than likely a thread) for the Control key and a second hotkey (or thread) for Ctrl + v that go to two separate functions.

So the application needs a few milis to finish getting clipboard from windows and converting/setting in android. My example worked for me each time I used it, tested it 4-5 times alternating between F9 and F10, if it doesn't work for you maybe increase the sleep delay (I've got windows 7 x64, i5-3570k CPU @ 3.4ghz, 8gigs ram @ 2133hz)

Share this post


Link to post
Share on other sites

I don't think it works that way. I googled BlueStacks Ctrl v and people said to long press Ctrl and then v (also a and c for all/copy). Makes me more or less think that the window is waiting for the ctrl key to be registered to the GUI. When it recognizes that it's been pressed/is pressed it starts copying the clipboard from windows and starts converting it into a format that is valid for android. It's like there's a Hotkey (more than likely a thread) for the Control key and a second hotkey (or thread) for Ctrl + v that go to two separate functions.

So the application needs a few milis to finish getting clipboard from windows and converting/setting in android. My example worked for me each time I used it, tested it 4-5 times alternating between F9 and F10, if it doesn't work for you maybe increase the sleep delay (I've got windows 7 x64, i5-3570k CPU @ 3.4ghz, 8gigs ram @ 2133hz)

I ran this on 2 computers one being a bit old and the other is an i7 laptop 4 gb ram same results .

Just going to say, OP computer might just be plop.

Last time I installed bluestacks it hammered the resources and ran like a bag of shite.

I later tried Andy and it was well better.

As far as Andy goes it is good for small period of times with a bonus for ease of use. But if your trying to automate something in Andy over a long period of time it has severe memory leaks it goes up to the point it crashes my computer.

The best emulator i found so far was Genymotion but it has a more difficult setup than the usual emulators. Might have to get back on that .

 

me, me, me. I've got it !

AutoItSetOption("SendKeyDelay", 10)
AutoItSetOption("SendKeyDownDelay", 10)

Hotkeyset ("{ESC}","bye")
Hotkeyset ("{F9}","text1")
Hotkeyset ("{F10}","text2")

Global $txt1 = "Test string 1"
Global $txt2 = "Test string 2"

While 1
    Sleep(100)
WEnd

Func bye()
    Exit
EndFunc

Func text1()
    Send($txt1)
Endfunc

Func text2()
    Send($txt2)
Endfunc

try that :)

I tried that too but the ammount of text is about 100 char long and since i want this script to run on my low performance computer it take a lot of time to send that even with SendKeyDelay 0 so i realy need the use of clipboard.

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
Sign in to follow this  
Followers 0