Monday, October 24, 2011

How to Enable Ctrl+V for Pasting in the Windows Command Prompt

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.
image
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.

#IfWinActive ahk_class ConsoleWindowClass
^V::
SendInput {Raw}%clipboard%
return
#IfWinActive
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.
image
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.
Download the PasteCommandPrompt AutoHotkey Script from howtogeek.com

No comments:

Post a Comment