Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I write an AHK script like this:


It works like charm. The only thing is, when I want a copied part of text, (something that includes things I want to have auto replaced) it doesn't want to replace it.

For example:

!INS::{Ctrl Down}c{Ctrl Up}{Tab 2}{Enter}{Ctrl Down}v{Ctrl Up}

Lets me copy abc but when it is pasted, I don't get alphabet (as defined earlier).

Is there a way to make it replace the copied and pasted words? Like when I use the send command to send a line or some words that include a word I would like to auto replace?

share|improve this question

Hotstrings only affect what you physically type. To perform search and replace on the Clipboard you can use the RegExReplace command.

Below is a script which copies the selected text and then pastes the modified contents (after search and replace). I believe this is what you meant:

#x:: ;[Win]+[X]

;Empty the Clipboard.
    Clipboard =
;Copy the select text to the Clipboard.
    SendInput, ^c
;Wait for the Clipboard to fill.

;Perform the RegEx find and replace operation,
;where "ABC" is the whole-word we want to replace.
    haystack := Clipboard
    needle := "\b" . "ABC" . "\b"
    replacement := "XYZ"
    result := RegExReplace(haystack, needle, replacement)

;Empty the Clipboard
    Clipboard =
;Copy the result to the Clipboard.
    Clipboard := result
;Wait for the Clipboard to fill.

;-- Optional: --
;Send (paste) the contents of the new Clipboard.
    SendInput, %Clipboard%

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .