AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can't paste contents of clipboard as plaintext

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
tester8900



Joined: 23 Jan 2006
Posts: 12

PostPosted: Thu Feb 16, 2006 12:33 am    Post subject: Can't paste contents of clipboard as plaintext Reply with quote

I would like to be able to paste the contents of the clipboard as plain text.

I saw this line in the help file:
Code:
clipboard = %clipboard%   ; Convert any HTML or other formatted text to plain text.


Here is my code, but for some reason it is pasting as HTML nonetheless.

Code:
#IfWinActive Microsoft Development Environment
^v::
clipbak := ClipboardAll
Clipboard = %Clipboard%
Send !ep   ;paste by means of the menu   
Clipboard := clipbak
return
#IfWinActive


Also, notice how I use !ep to paste through an alternate way from ^v... is there some passthru function to just have ^v continue on to the program?
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4032
Location: Pittsburgh

PostPosted: Thu Feb 16, 2006 12:52 am    Post subject: Reply with quote

Check the spelling of your window title. The default SetTitleMatchMode is 1, that is, the title must start with "Microsoft Development Environment". If the current file name is in front of it, or there is a leading space, you may need SetTitleMatchMode 2.
Back to top
View user's profile Send private message
tester8900



Joined: 23 Jan 2006
Posts: 12

PostPosted: Thu Feb 16, 2006 1:00 am    Post subject: Reply with quote

I just confirmed it is detecting the window properly by changing the shortcut key to Ctrl+4 which previously did nothing but now will paste by means of the menu.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4032
Location: Pittsburgh

PostPosted: Thu Feb 16, 2006 1:06 am    Post subject: Reply with quote

I tested your script in Word, and everything was removed, but text. Can it be that your html file is text (with tags), and MDE renders it graphically? What do you see if pasted the same clipboard into other applications?
Back to top
View user's profile Send private message
tester8900



Joined: 23 Jan 2006
Posts: 12

PostPosted: Thu Feb 16, 2006 1:18 am    Post subject: Reply with quote

If I paste into word or notepad it works fine and I get plaintext of
int print ( string arg )

If I paste into MDE, I get
int <B class=methodname>print</B> ( string arg )<BR>
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4032
Location: Pittsburgh

PostPosted: Thu Feb 16, 2006 1:33 am    Post subject: Reply with quote

So, this might be the opposite: Word and Notepad renders the HTML file, which is text with tags, but MDE does not. If you pasted the line into Word and copy from there again, MDE should only show the text, because Word does not copy in HTML. It is the source, which looks like text. You could employ the intermediate step of pasting into Notepad with Ctrl-V, Ctrl-A for select all, Ctrl-X to cut, but it is ugly.

You could use a simple script to remove the HTML tags, anything between < and >. It might take 10 lines of code, but you don't have to open Notepad.
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Feb 16, 2006 4:09 pm    Post subject: Reply with quote

I did like Laszlo and tried with MS Word, and your code works as intended.
Maybe you are restoring the clipboard before your application processes the !ep command.
Do you really want to keep the formatted code in the clipboard?
If yes, try to add a little Sleep after the paste.
Here is how I tested:
Code:
SetTitleMatchMode 2
#IfWinActive Word
$^v::
clip = %ClipboardAll%
clipboard = %Clipboard%
Send ^v
Clipboard = %clip%
return
#IfWinActive

Notice the $^v hotkey: this allows to send the same hotkey to the application without re-triggering the hotkey at AHK level.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4032
Location: Pittsburgh

PostPosted: Thu Feb 16, 2006 4:46 pm    Post subject: Reply with quote

A very basic HTML tag removal only takes 3 lines of AHK code. Here it is in functional form.
Code:
AutoTrim Off
Text = int <B class=methodname>print</B> ( string arg )<BR>
MsgBox % TagDel(Text)

TagDel(Text)
{
   Loop Parse, Text, <>
      If (A_Index & 1)
         Out = %Out%%A_LoopField%
   Return Out
}
You can use the bare Loop in the hotkey subroutine, like this
Code:
AutoTrim Off
#IfWinActive Multi-Edit
!z::
   clipbak = %ClipboardAll%
   Text = %Clipboard%
   Loop Parse, Text, <>
      If (A_Index & 1)
         Out = %Out%%A_LoopField%
   Clipboard = %Out%
   ClipWait 2
   Send ^v
   Clipboard := clipbak
return
#IfWinActive

By the way, in your original script it is a good idea to add a Clipwait instruction after setting up the Clipboard, which waits until it contains some text. It could make a difference.
Code:
#IfWinActive Microsoft Development Environment
^v::
   clipbak := ClipboardAll
   Clipboard = %Clipboard%
   ClipWait 2 ; <--
   Send !ep   ;paste by means of the menu   
   Clipboard := clipbak
return
#IfWinActive
Back to top
View user's profile Send private message
tester8900



Joined: 23 Jan 2006
Posts: 12

PostPosted: Thu Feb 16, 2006 5:33 pm    Post subject: Reply with quote

It turned out to a timing issue like PhiLho thought. Changing the hotkey to $^v and then sending ^v got it to work (I wasn't successful using ClipWait 2). Thanks for both of your help!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group