Ankit
Ankit

Reputation: 1510

AHK for selecting Context Menu Option - Not working

I am trying to create a Hotkey (Ctrl+l) to do following:

  1. Right Click at Current Mouse Location. (to bring up context menu)
  2. In the context menu go to Second option. (or any other option)
  3. Click Enter on that option.

    ^l::MouseClick, right
    Sleep, 1000
    Send, {DOWN  2}{ENTER}
    

Problem:
The problem is that ONLY the Right Click command works and brings up the Context Menu successfully but Down doesn't work at all, so NO OPTION is Selected from the menu.

Additional Info:
I found that if context menu is already there and then if I run following script:

Send, {DOWN 2}{ENTER}

It selects the option Successfully. But I need both Right Click and Selection of Option to be done by single Hotkey.

What am I doing wrong ?

Upvotes: 0

Views: 1488

Answers (2)

user1944441
user1944441

Reputation:

If you declare your hotkeys with command in the same line only that line will be executed

^l::MouseClick, right  ; only this line is executed
Sleep, 1000
Send, {DOWN  2}{ENTER}

Compared to this:

^l::
MouseClick, right
Sleep, 1000
Send, {DOWN  2}{ENTER}
return

All lines get executed.

Upvotes: 2

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

You wrote MouseClick, Right in the same line as ^l::, this way ONLY the first line is executed.

^l::
MouseClick, right
Sleep, 100
Send, {DOWN 2}{ENTER}
Return

Upvotes: 2

Related Questions