Almost all computer users would use <Ctl> C and <Ctl> V keys extensively. How many times have you found yourself needing to copy a formatted text and paste it onto a different document without the formatting? I have felt the need for this very often and every time I do it, I miss a convenient shortcut for it. I find my Windows PC lacking support for this elementary feature. Of course, many softwares that host the target location have provision for this. For instance, you can copy the text from wherever you want and paste it without formatting in MS Word or MS Excel using Edit -> Paste Special -> Unformatted text. But I was looking for a universal and convenient approach to do this. Now, thanks to Autohotkey, I have managed to write a shortcut for it. I have set up 2 variants of hot keys for this -
- Copy the text unformatted (using hot key 1) and paste it wherever you like using standard <Ctl> V
- Copy the formatted text and paste it in unformatted fashion (using hot key 2).
I use either of it depending on my convenience. For hot key 1 (unformatted copy), I use <Ctl> <Shift> C, which is quite close to normal copy shortcut. For hot key 2 (unformatted paste), I use <Ctl> <Shift> V, which is quite close to normal paste shortcut. Quite logical, ain’t it?
Now on to the real scripting part. This is how I went about it -
^+c::
bak = %clipboard%
clipboard = %bak%
return
^+v::
bak = %clipboard%
clipboard = %bak%
Send ^v
return
As you can see the code above, the approach is very simple – Read the clipboard and assign it to an Autohotkey variable. This operation sheds all the formatting associated with the clipboard item. There is one drawback to this approach though – After you perform this, the formatting of the copied text in clipboard is gone for ever. If you want to print it somewhere else immediately with formatting, you will have to go back and copy the text again. But this is a very rare occurence, at least for me and I am quite happy with the solution I have come up with.
July 6, 2007 at 5:08 pm |
Thanks for figuring this out. I just hate the fact that windows copies formatting when you use the clipboard.
However, I had to modify the ^+c:: code to get it to work for me. Here is what I ended up with through trial and error:
^+c::
Send ^c
sleep 100
bak = %clipboard%
sleep 100
clipboard = %bak%
return
July 7, 2007 at 5:17 am |
Andy, It works for me without time delay! Maybe, it depends on the computer. Thanks a lot for sharing this code!
July 12, 2007 at 12:57 am |
Thanks for this. I made the following modification to the script to preserve the formatting on the clipboard after pasting without formatting:
; Ctrl+Shift+v pastes without formatting without
; Thanks to an annonymous programmer at
; http://programmerproductivity.wordpress.com
^+v::
ClipSaved := ClipboardAll
tempClipboard = %clipboard%
Clipboard = %tempClipboard%
SendPlay ^v
Clipboard := ClipSaved
return
July 17, 2007 at 4:32 pm |
Thanks for the improvement David!
April 2, 2009 at 10:09 pm |
Hi,
From some reason, in “send ^v” or “SendPlay ^v” or even sendinput command just types the letter “v” instead of pasting the text.
When I do a physical LCtrl and press V on my keyboard, it pastes it.
Does any1 had that issue before? How can I simulate the Control-v exactly?
April 3, 2009 at 10:57 am |
Hi – I found out how to do that… I use the virtual keys instead!
For example instead of doing:
Send ^c
I use :
sendplay {vkA2 Down}{vk43}{vkA2 Up} ;;copy vka2=LCtrl vk43=c
And instead of Send ^v I use:
sendplay {vkA2 Down}{vk56}{vkA2 Up} ;;paste vka2=LCtrl vk56=v
April 3, 2009 at 10:58 am |
List of virtual keys…
http://www.kbdedit.com/manual/low_level_vk_list.html
May 20, 2009 at 2:53 pm |
RE Eran:
Sorry I don’t understand how you get from those virtual key codes to what you’ve typed.
March 10, 2010 at 8:59 pm |
Thanks David for that one, beautiful in it’s simplicity.