Why does my hotstring not work when I copy paste Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Julie Kholer

Why does my hotstring not work when I copy paste

08 Nov 2017, 03:02

I use ::ATB::All The Best

and IT works great if I type out ATB. But if I paste ATB and hit enter it does not trigger the hotstring :-(
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Why does my hotstring not work when I copy paste

08 Nov 2017, 03:26

Because the way the hotstring triggers is by basically keylogging you. Pasting does not trip the keylogger; it only sees the Ctrl and V keys, or that you right clicked and made a menu selection.

However... if you simulate the typing, and if you make sure that your simulated typing can trigger keys, it should work. See this recent thread on hotstrings which is related to your question: https://autohotkey.com/boards/viewtopic ... 09#p181009

This code worked for me; I copied the ATB to my clipboard with a manual Ctrl+C, pasted it, and then hit the Space key (Enter should work fine too) to trigger the replacement. If an ending character (see #Hotstring EndChars) is included after the ATB on the clipboard, it'll automatically trigger the hotstring for you.

Code: Select all

::ATB::All The Best

^v::
SendLevel, 2
SendRaw %clipboard%
return
This does replace your native pasting functionality and I expect would prevent pasting images. So you may like to change your hotkey to something like ^+v (Ctrl+Shift+v) or do !v (Alt+v).
Hildagard K

Re: Why does my hotstring not work when I copy paste  Topic is solved

22 Nov 2017, 20:24

Exaskryz wrote:Because the way the hotstring triggers is by basically keylogging you. Pasting does not trip the keylogger; it only sees the Ctrl and V keys, or that you right clicked and made a menu selection.

However... if you simulate the typing, and if you make sure that your simulated typing can trigger keys, it should work. See this recent thread on hotstrings which is related to your question: https://autohotkey.com/boards/viewtopic ... 09#p181009

This code worked for me; I copied the ATB to my clipboard with a manual Ctrl+C, pasted it, and then hit the Space key (Enter should work fine too) to trigger the replacement. If an ending character (see #Hotstring EndChars) is included after the ATB on the clipboard, it'll automatically trigger the hotstring for you.

Code: Select all

::ATB::All The Best

^v::
SendLevel, 2
SendRaw %clipboard%
return
This does replace your native pasting functionality and I expect would prevent pasting images. So you may like to change your hotkey to something like ^+v (Ctrl+Shift+v) or do !v (Alt+v).
this code does not work when you copy and paste using the mouse :-(
User avatar
davebrny
Posts: 85
Joined: 05 Dec 2016, 06:26

Re: Why does my hotstring not work when I copy paste

23 Nov 2017, 06:33

this takes the text that is currently highlighted and if its an abbreviation thats in your hotstring file then it will convert it to the replacement.
everything after "clipWait" sounds like it would work for your siutation

Code: Select all

clipboard_all := clipboardAll
clipboard := ""
send ^{c}
clipWait, 0.3
selected := clipboard

loop, parse, hotstring_list, `n, `r
    {
    if !inStr(a_loopField, "::")
        continue
    split := strSplit(a_loopField, ":")
    if (split[3] = selected)  ; split3 = abbreviation 
        {
        clipboard := split[5] ; split5 = replacement text
        send ^{v}
        sleep 200 
        break
        }
    }

clipboard := clipboard_all
you will have to modify it depending on how you have your hotstrings set up. its best of they are in a file on their own so it doesnt have to loop through too much text

then put the fileread part in your auto-execute section so you dont have to read it every time you run the above code

Code: Select all

fileRead, hotstring_list, C:\file_that_contains_your_hostrings.ahk
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Why does my hotstring not work when I copy paste

24 Nov 2017, 22:21

Hildagard K wrote:
Exaskryz wrote:Because the way the hotstring triggers is by basically keylogging you. Pasting does not trip the keylogger; it only sees the Ctrl and V keys, or that you right clicked and made a menu selection.

However... if you simulate the typing, and if you make sure that your simulated typing can trigger keys, it should work. See this recent thread on hotstrings which is related to your question: https://autohotkey.com/boards/viewtopic ... 09#p181009

This code worked for me; I copied the ATB to my clipboard with a manual Ctrl+C, pasted it, and then hit the Space key (Enter should work fine too) to trigger the replacement. If an ending character (see #Hotstring EndChars) is included after the ATB on the clipboard, it'll automatically trigger the hotstring for you.

Code: Select all

::ATB::All The Best

^v::
SendLevel, 2
SendRaw %clipboard%
return
This does replace your native pasting functionality and I expect would prevent pasting images. So you may like to change your hotkey to something like ^+v (Ctrl+Shift+v) or do !v (Alt+v).
this code does not work when you copy and paste using the mouse :-(
If AHK knows a way to detect when you are trying to paste and intercept it, or if AHK has a way to know what item in the context menu you've selected, you could code that. The only thing I can imagine is doing this:

Code: Select all

~RButton::
MouseGetPos, StartX, StartY
KeyWait, LButton, D
MouseGetPos, EndX, EndY
If (EndX-StartX < 100) ; set the 100 to the width in pixels of your right click menu
     && (EndY-StartY > 150) && (EndY-StartY < 200) ; set a "top of item" and "bottom of item" boundary, like if it's 175 pixels from the top of the menu to select "paste", you'd want the range to include 175
     ; However, if you click toward the top or bottom of the screen these coordinates change, so you need to ranges. Same to clicking on the right or left of your screen
     {
     Send {Esc} ; to cancel the menu
     SendLevel, 2
     SendRaw %clipboard%
     }
else
    Click
return
Wait, that won't work, because the LButton isn't suppressed. So instead of using KeyWait, LButton, D, you need to turn on an LButton hotkey with the hotkey command. Then turn it off at the end of the hotkey execution.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], Spawnova and 325 guests