Docfxit

Putting text from the clipboard into a variable

8 posts in this topic

#1 ·  Posted

I am trying to put something in the clipboard and then get it out.

Global $UserCode1
ClipPut("") ;Clear the clipboard

ControlFocus($hWnd, "", "Edit3")
Send("^{HOME}+^{END}")
Send("{CTRLDOWN}c{CTRUP}")
$UserCode1 = ClipGet()
MsgBox(0, "", "$UserCode1 = " & $UserCode1)

When MsgBox is displayed it doesn't show anything in $UserCode1.

If I bring up Notepad and do a <Ctrl>V it pastes in what is in the clipboard.

What am I doing wrong?

Thanks,

Docfxit

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hello. Probably there is some no printable characters. try to write to a file and check the file contents.

Filewrite("Somefile.txt",$UserCode1)

Saludos

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks for the suggestion.

The file was written with 0 bytes.

Global $UserCode1
ClipPut("") ;Clear the clipboard

ControlFocus($hWnd, "", "Edit3")
Send("^{HOME}+^{END}")
Send("{CTRLDOWN}c{CTRUP}")
$UserCode1 = ClipGet()
Filewrite("Somefile.txt",$UserCode1)
MsgBox(0, "", "$UserCode1 = " & $UserCode1)

Docfxit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

EDIT: Guessing you key strokes are properly reading the value of the edit control into the clipboard ... my mistake. 

 

Edited by Jfish

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

#5 ·  Posted (edited)

So probably the clipboard content isn't raw text. So it's proceesed different. Probably you can paste to a dummy edit control them read the text back. I'm by phone right now so I can't build a sample script.

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

19 minutes ago, Jfish said:

where are you storing anything to the clipboard?  Looks like you are resetting it to blank and then reading it.  The send command is not putting those values to the clipboard.  See what I mean with the below:

ClipPut("")
send ("test")test
$val=ClipGet()
MsgBox(0,'',$val)
ClipPut("test put")
$val=ClipGet()
MsgBox(0,'',$val)

 

Thank you for catching that:

So I tried this:

Global $UserCode1
ClipPut("") ;Clear the clipboard

ControlFocus($hWnd, "", "Edit3")
Send("^{HOME}+^{END}")
Send("{CTRLDOWN}c{CTRUP}")
ClipPut($UserCode1)
Filewrite("Somefile.txt",$UserCode1)
MsgBox(0, "", "$UserCode1 = " & $UserCode1)

I thought the Send("{CTRLDOWN}c{CTRUP}") would put the text into the clipboard.

I thought all I needed to do was take it from the clipboard and put it into $UserCode1

If I bring up Notepad and do a <Ctrl>V it pastes in what is in the clipboard.

The file gets written with 0 bytes.

The MsgBox is displayed with nothing for $UserCode1

Docfxit

Edited by Docfxit

Share this post


Link to post
Share on other sites

#7 ·  Posted

Have you tried using CongrolGetText in lieu of the Send commands?

Share this post


Link to post
Share on other sites

#8 ·  Posted

35 minutes ago, Danp2 said:

Have you tried using CongrolGetText in lieu of the Send commands?

That solved the problem.

Thank you very much,

Docfxit

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