I am looking for a way to add an option(s) to the right click context menu when editing text on a WinXP machine. I already do a lot of copy/pasting on it, so the clipboard is always changing, but there is one string I type repeatedly in almost every file I edit.
I've already added some custom option to the context menu for .zip files to batch unzip them, but I'm not having any luck finding a way to add this.
The machine is used for a single purpose and I try to keep it as stable as possible so I'm trying to stay away from any new third-party software that could bloat the system.
The question asks how to edit the context menu for an Edit control, it it slightly unclear whether this is wanted for renaming or editing files, the AutoHotkey script below replicates the Edit control menu when editing files in Explorer and using Notepad. It adds a button that sends a string to the Edit control.
The script shows a custom context menu, when an Edit control is right-clicked, or when an Edit control is focused and the
AppsKey
is pressed.Note: The script below is tested on Windows 7, but the methods should work on Windows XP.
Note: The Explorer address bar also uses an Edit control, however, this is taken into account by the script.
Note: You requested a method that is lightweight, AutoHotkey can be run with one exe file (under 2MB in size), and one script file. Scripts can also be compiled to small exes.
I don't think there's an extension point for that sort of thing. You'd have to inject code into every process that has a window with a text box control, which would be complicated and frowned upon by most anti-virus applications.
I know you said you wanted to avoid third-party software, but there really isn't any way around it. A program like AutoIt will allow you to create a custom keyboard shortcut to paste whatever text you like into almost any application. It would probably be much more stable than any custom program written in the short term.
You can even compile the automation script to a standalone executable if you don't want to install the entire AutoIt distribution on the machine.
Assuming you are referring to the Edit control context menu. You can achieve this by cloning and amending the Edit control context menu, via AutoHotkey. If the context menu is a for a different type of control, the same principle applies but it may be harder to recreate the existing menu item functions.
To 'add' a menu item, the simplest method would be to replace the entire menu with your own custom context menu. With your custom menu item at the top of it, and you would probably want to recreate the Undo/Cut/Copy/Paste/Delete/Select All items that appear on the Edit control. Using
ControlGet, vText, Selected
to recreate the Copy function for example. You use#IfWinActive
to make the menus only appear if a certain window is the active window, e.g. only if Notepad is the active window. You would also need to capture right-clicks via the RButton hotkey and/or capture AppsKey presses, and useControlGetFocus
to check if an Edit control was in focus, andMouseGetPos
to check if an Edit control was under the cursor. So there would be a bit of work involved. Regarding capturing right-clicks, see the link below, where you would replace LButton with RButton. Good luck!Is it possible to catch the close button and minimize the window instead? AutoHotKey
Similar question: Can I edit the context menu of a text field (not Explorer context menu)?
Note:
- For typing long/repetitive strings, the use of hotstrings in AutoHotkey can really facilitate this. Achievable in literally one line of code.
- For batch jobs involving zip files perhaps try 7-Zip and using command lines parameters in AutoHotkey. This could probably be achieved in around 10 or 20 lines of code.
AutoHotkey is very lightweight, about 1MB, you could try it for a day or two, possibly watch a short 'hello world' tutorial video, it can be quite easy to get started.