User
User

Reputation: 53

Trying to fix autohotkey code which do a function when I press a key twice

I want to write a code in aoutohotkey to do this: If the my dictionary application is active, then when I press the key " j " it clicks on a specific coordinate (in this coordinate there is an open Kmplayer window ) then send Enter and then send Space. here is my code:

#IfWinActive Oxford Advanced Learner's Dictionary
j::
    If (A_ThisHotkey = A_PriorHotkey) && (A_TimeSincePriorHotkey < 500)
        Click, 1149,305
        sleep,100
        send,{Enter}
        sleep,100
        send,{space}
return

But it doesn't work perfectly. sometimes it works but most of the times when I press the key " j " twice, it just send space and enter.

Some details:

  1. I'm not much experienced at working with aoutohotkey I just found a double tap pressing code on reddit and used it.

  2. For swiping window to the open Kmplayer I didn't find a better solution than just Click, 1149,305 because unlike many applications, the key combination Alt+Esc doesn't swap windows for Oxford dictionary app. (maybe this clicking cause the problem)

Upvotes: 0

Views: 144

Answers (1)

0x464e
0x464e

Reputation: 6489

If your if-statement's body has more than one line, you need { }s.

#IfWinActive Oxford Advanced Learner's Dictionary
j::
    if (A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 500)
    {
        Click, 1149,305
        sleep,100
        send,{Enter}
        sleep,100
        send,{space}
    }
return

Not sure if this is your only problem though.
I wasn't able to make sense of what your second detail was trying to say.

Upvotes: 2

Related Questions