user594297
user594297

Reputation: 93

AHK - # (windows) hotkey stay in pressed state at first use

I wrote a simple script wich open the active joomla site administrator page in Firefox:

#a::
    Send, !d
    GetText(url)
    StringGetPos, localHost, url, localhost
    startPos := 7
    if(localhost)
        startPos := 17
    StringGetPos, pos, url, /,,startPos
    adminURL := SubStr(url,1,pos)
    Send ^t%adminURL%/administrator{enter}
return

GetText(ByRef txt)  ;copy the selected text to clipboard
{
    BlockInput, on
    prevClipboard = %clipboard%
    clipboard =
    Send, ^c
    BlockInput, off
    ClipWait, 2
    txt = %clipboard%
    txt:=RegExReplace(txt,"\x20{2,}"," ")
    clipboard = %prevClipboard%
}

At first use (after reboot) the script do weird things:

It looks like the windows key is still in pressed state when I send the input. After first use the script work properly. I think something is wrong with the getText function.

I try a lot of modification, but doesn't work.

Can somebody help me?

Upvotes: 0

Views: 212

Answers (1)

MCL
MCL

Reputation: 4065

Let the hotkey label wait until you have released each key:

#a::
    KeyWait, LWin ; or RWin, as desired
    KeyWait, a ; just to make sure nothing interferes
    /*
        do stuff!
    */
return

In contrast to #a UP::, this won't let a WIN key press trickle through when releasing A first.

Upvotes: 1

Related Questions