RSS

How-To Geek

One of the more irritating problems with the Windows command prompt is that you can’t paste anything into the window using the keyboard easily—it requires using the mouse. Here’s how to fix that problem.

The solution, as with many Windows shortcomings, is to use a quick AutoHotkey script to enable pasting from the keyboard. What it actually does is take the clipboard contents and use the SendInput function to send the keystrokes really quickly to the console window.

But first… here’s another way to do it.

The Alternate Built-In Way to Paste from the Keyboard

There is actually a way to paste something using the keyboard, but it’s not terribly convenient to use. What you’ll have to do is use the Alt+Space keyboard combination to bring up the window menu, then hit the E key, and then the P key. This will trigger the menus and paste into the console.

Once you get used to doing it, it really isn’t so bad… but who wants to use a different combination for one application than the rest of Windows?

The AutoHotkey Script Ctrl+V Awesomeness

You’ll need to first make sure that you’ve got AutoHotkey installed, and then create a new AutoHotkey script or add the following to your existing script. We’ve also provided a download in case there are any formatting problems.

What this script does is simply use the SendInput function to send the data into the window, which is a lot faster than any other method.

Note: the script doesn’t paste line breaks very well. If you’ve got a better solution for that, feel free to let us know in the comments and we’ll update the post.

Downloadable AutoHotkey Script

Simply grab the script, save it anywhere, and then double-click on it to start it. You can kill it through the tray icon if you want—if you’d like to hide the tray icon, add #NoTrayIcon to the top of the script.

For those of you who are too lazy to download AutoHotKey and create the script yourself :P, you can download a ready-made installer that does everything (including setting it up to run on startup) here: http://cmdpaste.lakotahosting.com/

“Note: the script doesn’t paste line breaks very well.”…line breaks on the clipboard (in most cases) are \r\n (or in AutoHotkey-speak `r`n…or in other words “CRLF”). When you Send text with AutoHotkey it sends exactly what you tell it to & the clipboard has the `r & `n. So it sends the `r, which causes the Command Prompt to go to the next line/execute the command, but since there is still a `n to send, you get the “double spacing”.

“Note: the script doesn’t paste line breaks very well.”…line breaks on the clipboard (in most cases) are \r\n (or in AutoHotkey-speak `r`n…or in other words “CRLF”). When you Send text with AutoHotkey it sends exactly what you tell it to. The clipboard has `r & `n for line breaks. So AutoHotkey sends the `r, which causes the Command Prompt to go to the next line/execute the command, but since there is still a `n to send, you end up with “double spacing”.

“Note: the script doesn’t paste line breaks very well.”…line breaks on the clipboard (in most cases) are \r\n (or in AutoHotkey-speak `r`n…or in other words “CRLF”). When you Send text with AutoHotkey it sends exactly what you tell it to. The clipboard has `r & `n for line breaks. So AutoHotkey sends the `r, which causes the Command Prompt to go to the next line/execute the command, but since there is still a `n to send, you end up with “double spacing”.

With both the original script and JSLover’s variant, I get odd results using bash. If I copy, say a directory like “C:\Program Files\AutoHotkey” into bash, I get “C:\Program F[Gile[Gs\[GAutoHotkey.” Any ideas on what’s going on here?