1

I'm trying to use AutoHotKey to fix the backspace key in Chrome. My first attempt utilized the following solution from this question:

#IfWinActive, ahk_class Chrome_WidgetWin_1
BackSpace::Send, {Left}{Delete}

It works, but it unfortunately also prevents me from selecting text in an input/textarea and removing it all with the backspace key. So I started looking for a way to exclude cases where the cursor is in one of those. I then found this answer, with a script for changing the window title when inside an input/textarea and the following AHK script to make use of that title update:

SetTitleMatchMode, RegEx

#x:: ; normal hotkey
     ; do something
    return

#IfWinActive, \[AHK\] - Google Chrome$
    #x:: ; input/textarea focus hotkey
         ; do something
        return

#IfWinActive

I've been trying to mix the two together, so that I can rewrite the behaviour of Backspace when in a Chrome window that does not end in [AHK] - Google Chrome, but I have been unsuccessful so far. I feel like I'm really close and just missing something, but I am an absolute novice at AHK and I have no idea where to go from here. After meddling with the above code, and searching online, here's what I have right now:

SetTitleMatchMode 2 ; partial title matches

IfWinActive, ahk_class Chrome_WidgetWin_1 ; identify Chrome
{
    #BackSpace::
    If WinActive("[AHK] - Google Chrome") ; identify when within text element
    {
        return
    }
    else {
        Send, {Left}{Delete}
    }
}

I feel like I should be able to accomplish this with a single IfWinActive statement to include Chrome and exclude the [AHK] stuff, but the docs don't give any examples for adding the other parameters past the first one, and my own attempts have been futile. Any help with this would be greatly appreciated. Also, if there's a way to similarly exclude the address bar, that would be stellar.

DiMono
  • 133

1 Answers1

1
#ifWinActive, ahk_class Chrome_WidgetWin_1

bs::
    clipboard =  ; Clear clipboard
    send ^c  ; Copy any selected text
    if clipboard =  ; If nothing is selected
        send {left}
    send {del}
return

#ifWinActive
Adam Lui
  • 386