Jump to content

RTF data in the clipboard


Kiai
 Share

Recommended Posts

I have been trying to figure out how to send a string to the clipboard with RTF coding, simple stuff like bolding a word. I have read the helpfile on _ClipBoard_SetDataEx but can't quite figure out how to make this work. I want the script below to put the string in in a way that, when I hit ctrl-v in Word, the bolding happens. Suggestions? Thanks. (I had to put some spaces in to make my post come out with the rtf codes)

CODE
$string="simple stuff like [b ]bolding[/b ] a word."

ClipPut($string)

Edited by Kiai
Link to comment
Share on other sites

Hi.

Welcome to the forum!

... interesting question.

The style of a string stored in clipboard is *NOT* RTF code, it's "formatted text".

Start wordpad.exe.

Write the line " This is bold, this is italic, this is underlined", copy this to your clipboard.

Then run this code to see, that there are no "font definitions" at the "format boundaries" in your clipboard's content:

$MyString=ClipGet()
ConsoleWrite($MyString & @CRLF)

$Foo=$MyString
for $i=StringLen($Foo) to 1 step -1
    $Next=StringLeft($Foo,1)
    ConsoleWrite($Next & ", ASCII: " & Asc($Next) & ", Rest: " & $Foo & @CRLF)
    $Foo=StringTrimLeft($Foo,1)
Next

ConsoleWrite("done." & @CRLF)

Your clipboard is holding "formatted text", and when you paste it to programs like word, exel, wordpad, the "formatted text" will be inserted.

When you start a program, that's not capable to handle formating, from the same clipboard content you will get just the plain text. Check this using notepad.exe e.g.

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hi.

Thanks for your help. Any idea of how to send text to the clipboard as formatted text instead of just as text using autoit? I assumed there would be a way using the RTF codes but that doesn't seem to work. This is for an application where I don't want to open and close word or wordpad just to get bolding, and the application doesn't include keyboard controls for this.

Welcome to the forum!

... interesting question.

The style of a string stored in clipboard is *NOT* RTF code, it's "formatted text".

Start wordpad.exe.

Write the line " This is bold, this is italic, this is underlined", copy this to your clipboard.

Then run this code to see, that there are no "font definitions" at the "format boundaries" in your clipboard's content:

$MyString=ClipGet()
ConsoleWrite($MyString & @CRLF)

$Foo=$MyString
for $i=StringLen($Foo) to 1 step -1
    $Next=StringLeft($Foo,1)
    ConsoleWrite($Next & ", ASCII: " & Asc($Next) & ", Rest: " & $Foo & @CRLF)
    $Foo=StringTrimLeft($Foo,1)
Next

ConsoleWrite("done." & @CRLF)

Your clipboard is holding "formatted text", and when you paste it to programs like word, exel, wordpad, the "formatted text" will be inserted.

When you start a program, that's not capable to handle formating, from the same clipboard content you will get just the plain text. Check this using notepad.exe e.g.

Regards, Rudi.

Link to comment
Share on other sites

I appreciate the help. I understand that I can copy formatted text from word. I want to create formatted text from within an autoit script without having to open word. I want to send a string to the clipboard with formatting in it. Any ideas?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...