AutoHotkey Community

It is currently May 25th, 2012, 4:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: July 29th, 2006, 3:20 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The functionality of this simple script is there in a few clipboard management scripts already posted (and in a few freeware utilities, like PureText), but if you don't need other fancy features, this one is short and fast. (The simple method Chris described here often fails.)
Code:
^#v::                            ; Text–only paste from ClipBoard
   Clip0 = %ClipBoardAll%
   ClipBoard = %ClipBoard%       ; Convert to text
   Send ^v                       ; For best compatibility: SendPlay
   Sleep 50                      ; Don't change clipboard while it is pasted! (Sleep > 0)
   ClipBoard = %Clip0%           ; Restore original ClipBoard
   VarSetCapacity(Clip0, 0)      ; Free memory
Return
Ctrl-Win-V pastes the text content of the clipboard, leaving it unchanged, so Ctrl-V would still paste formatted text with pictures, if it was in the Clipboard. It is very useful if you paste text from websites into MS Word or Lotus Notes, where they look weird with unusual indentation, font, color, etc. Sleep 50 was necessary in my PC, because setting up the clipboard happens in the background, parallel to the script. If it was not finished when Ctrl-V is sent, the old content was used. Experiment with other values. Sleep 250 should be enough even for the slowest PC's.

If you know, you only need the text content of the selection, but many times, you could save time and memory if the clipboard is converted to text:
Code:
^#x::
^#c::                            ; Text-only cut/copy to ClipBoard
   Clip0 = %ClipBoardAll%
   ClipBoard =
   StringRight x,A_ThisHotKey,1  ; C or X
   Send ^%x%                     ; For best compatibility: SendPlay
   ClipWait 2                    ; Wait for text, up to 2s
   If ErrorLevel
      ClipBoard = %Clip0%        ; Restore original ClipBoard
   Else
      ClipBoard = %ClipBoard%    ; Convert to text
   VarSetCapacity(Clip0, 0)      ; Free memory
Return
Ctrl-Win-C/X copies/cuts the selection to the clipboard and converts it to text.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks Lazlo!
PostPosted: July 31st, 2006, 2:42 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
This is going to be great. Similar to Skrommels PlainPaste, but the code is easier for me to understand and will fit nicely in my ini file. I'm going to be using this starting tonight.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2007, 7:41 am 
Offline

Joined: February 28th, 2006, 8:42 am
Posts: 159
very nice, useful, and elegant. simple too. I'm using it already. perfect.
By the way what I was looking for was the converter to plain text on the 'copy/cut' keys (rather than on the paste keys). Most such converters do it on the paste key. So your second solution was especially perfect for me.
I needed it that way because of a particular program I use where I have to use a menu command to paste, so it had to be converted on the front end...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2007, 9:48 am 
Offline

Joined: March 24th, 2007, 8:10 pm
Posts: 39
Excellent!

Already in my AutoHotkey.ahk :D

_________________
Regards,
Antonio


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2007, 10:20 pm 
Offline

Joined: February 17th, 2006, 2:29 pm
Posts: 37
Very good!!! :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2007, 10:47 pm 
Offline

Joined: February 28th, 2006, 8:42 am
Posts: 159
hi - i've been using lazlo's plain-text-copy script for a while, and its been great. Recently I tried to map the hotkey to the mouse, and I ran into trouble. Wondering whats going on.

The script i'm using is this:

Code:
lwin & c::                            ; Text-only cut/copy to ClipBoard
   Clip0 = %ClipBoardAll%
   ClipBoard =
   StringRight x,A_ThisHotKey,1  ; C or X
   Send ^%x%                     ; For best compatibility: SendPlay
   ClipWait 2                    ; Wait for text, up to 2s
   If ErrorLevel
      ClipBoard = %Clip0%        ; Restore original ClipBoard
   Else
      ClipBoard = %ClipBoard%    ; Convert to text
   VarSetCapacity(Clip0, 0)      ; Free memory
Return


all i did was change the hotkey to:

lwin & lbutton::

When I open notepad and try to copy some text using lwin & lbutton, windows tries to close notepad (I get the "would you like to save your work?" prompt).

any ideas why i'm not able to map this to a mouse button? I've also tried variations like "lctrl & rbutton". It only seems happy if the hotkey is limited to the keyboard, not the mouse.

thanks!

(I should add that a line like "lwin & rbutton::send ^v" works fine for pasting, even when mapped to the mouse like that).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 1:33 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Change
Code:
   StringRight x,A_ThisHotKey,1  ; C or X
   Send ^%x%                     ; For best compatibility: SendPlay
to
Code:
   Send ^c
otherwise it sends Ctrl+N. :lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 1:46 am 
Offline

Joined: February 28th, 2006, 8:42 am
Posts: 159
THanks! works perfectly.

why did it send control-N? because "lbutton" ends with an "N"?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 4:12 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Yes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2007, 11:52 pm 
Offline

Joined: October 9th, 2006, 9:27 am
Posts: 21
Is it possible to modify this script so that he'd work with Unicode characters? Now, for example, if cyrillic characters are copied, trash letters like "ââèäó ñïåöèôèê" are pasted.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2007, 1:16 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
If you want to remove formatting from Unicode text use this:
Code:
^#v::                            ; Text–only paste from ClipBoard
   Clip0 = %ClipBoardAll%
   Transform UC, Unicode         ; Save Unicode text
   Transform Clipboard, Unicode, %UC%
   Send ^v                       ; For best compatibility: SendPlay
   Sleep 50                      ; Don't change clipboard while it is pasted! (Sleep > 0)
   ClipBoard = %Clip0%           ; Restore original ClipBoard
   VarSetCapacity(Clip0, 0)      ; Free memory
Return
It does not work if the Clipboard contains pictures (too).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2008, 6:10 am 
Offline

Joined: January 13th, 2008, 6:00 pm
Posts: 115
I have a modified version to remove white space and new line marks and that avoids "pasting" because that can trigger unnecessary paste options in Microsoft Office:

Code:
$>!v:: ; paste without formatting
  gosub getplain
  Send {Raw}%clipboardt%
  clipboardt =
  return
 
  getplain:
  StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
  clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
  StringLeft, 1st, clipboardt, 1
  IfInString, 1st, %A_Space%
  StringTrimLeft, clipboardt, clipboardt, 1
  StringRIght, last, clipboardt, 1
  IfInString, last, %A_Space%
  StringTrimRight, clipboardt, clipboardt, 1
  return
 


Updates May 16, 2008


Last edited by instantrunoff on May 16th, 2008, 6:54 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2008, 9:33 am 
Offline

Joined: October 9th, 2006, 9:27 am
Posts: 21
instantrunoff wrote:
I have a modified version to remove white space and new line marks and that avoids "pasting" because that can trigger unnecessary paste options in Microsoft Office:

Code:
   >!v:: ; paste without formatting
     plainpaste:
     StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
     clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
     StringLeft, 1st, clipboardt, 1
     IfInString, 1st, %A_Space%
     StringTrimLeft, clipboardt, clipboardt, 1
     Send %clipboardt%
     clipboardt =
     return


Thanks! It finally works with MS Office, but rather than paste instantly, it "types" the clipboard, and therefore is not for large text fragments.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2008, 2:33 pm 
Offline

Joined: January 13th, 2008, 6:00 pm
Posts: 115
sashabe wrote:
instantrunoff wrote:
I have a modified version to remove white space and new line marks and that avoids "pasting" because that can trigger unnecessary paste options in Microsoft Office:

Code:
   >!v:: ; paste without formatting
     plainpaste:
     StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
     clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
     StringLeft, 1st, clipboardt, 1
     IfInString, 1st, %A_Space%
     StringTrimLeft, clipboardt, clipboardt, 1
     Send %clipboardt%
     clipboardt =
     return


Thanks! It finally works with MS Office, but rather than paste instantly, it "types" the clipboard, and therefore is not for large text fragments.


Yeah, I had it "type" the clipboard rather than paste, because it annoyed me to have paste options or automatic formatting applied when pasting. However, you can use SendPlay for something paste-like.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2008, 6:22 pm 
Offline

Joined: January 13th, 2008, 6:00 pm
Posts: 115
PS I updated the script to prevent issues sending text with characters that get escaped.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: tidbit and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group