AHK WinMenuSelectItem does not work

General discussion related to "Everything".
Post Reply
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

AHK WinMenuSelectItem does not work

Post by vsub »

Just curious,is this some limitation\bug on the everything side or autohotkey or windows...or my code(which is very simple)

Code: Select all

#IfWinActive,AHK_class EVERYTHING
~MButton::
Keywait,MButton
MouseGetPos,,,,ID
If ID = EVERYTHING_CLOSE_BUTTON1
{
WinMenuSelectItem,A,,History,Home
;Send,!{Home}
Return
}
I middle click on the X button in the addressbar(everything 1.5)to execute History->Home but the problem is,if there is two or more windows of everything,the script work only on the first window

If I enable the option hide_on_close and close the first window first and then the second,when I click on the tray icon only once,it will bring the second window and the script will not work but if I click on the tray icon to bring the first window back,the script will work but only on the first window

I can just use Send,!{Home} and that works but WinMenuSelectItem does not
raccoon
Posts: 1017
Joined: Thu Oct 18, 2018 1:24 am

Re: AHK WinMenuSelectItem does not work

Post by raccoon »

WinMenuSelectItem,A,, will only act upon the Active Window, so whatever program has focus.
Everything does not instantaneously come into focus when you click on the window. It takes Microsoft Windows time to process this. Therefor any action you take on the Active Window will be the wrong window.

You can fix this by either adding a short Sleep in your hotkey function, or by using the MouseGetPos to capture the application window under the cursor and pass that to the WinMenuSelectItem command instead. You can do this at the same time you're detecting the mouse is over the EVERYTHING_CLOSE_BUTTON1 control.

Code: Select all

#IfWinActive ahk_class EVERYTHING
~MButton::
  Sleep, 100
  WinMenuSelectItem,A,,Help,About
  Return
#IfWinActive ; EVERYTHING

Code: Select all

#IfWinActive ahk_class EVERYTHING
~MButton::
  MouseGetPos,,, hwnd, ctrl
  if (ctrl == "EVERYTHING_CLOSE_BUTTON1")
    WinMenuSelectItem,ahk_id %hwnd%,,Help,About
  Return
#IfWinActive ; EVERYTHING
Going forward, please wrap all your hotkeys inside of functions to protect their variable scope from global mish-mashing.
If you're using Everything v1.5a, then the ahk_class is EVERYTHING_(1.5a) for #IfWinActive.

Code: Select all

#IfWinActive ahk_class EVERYTHING_(1.5a)
~MButton::
hotkey_everything_mclick_search()
{
  Keywait,MButton
  MouseGetPos,,, hwnd, ctrl
  if (ctrl == "EVERYTHING_CLOSE_BUTTON1")
  {
    WinMenuSelectItem,ahk_id %hwnd%,,History,Home
    ; more stuff...
  }
}
#IfWinActive ; EVERYTHING
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: AHK WinMenuSelectItem does not work

Post by vsub »

I know that the "A" means that it will work only on the active window but
1.I did activate the second window
2.I close the other window and activate the second
3.I tried with getting the window id and then use ahk_id in WinMenuSelectItem
But none of that worked

There is no need for sleep because I am using KeyWait and even without KeyWait,the code works just fine on the first window but not on the second

And btw,all of your examples work the exact same way as my script,they don't work on the second window,only on the first
raccoon
Posts: 1017
Joined: Thu Oct 18, 2018 1:24 am

Re: AHK WinMenuSelectItem does not work

Post by raccoon »

I tested all of my code examples on Everything 1.4 and 1.5, with the window being inactive at the time that I clicked the button, and it definitely requires a Sleep period otherwise an assertive hWnd window handle in WinMenuSelectItem if the target Everything is not already the Active Window.

KeyWait only means that the rest of the script will proceed only after you have lifted your middle-click button. This does not mean that the Everything window under the mouse is the Active window yet. It's still inactive if not already in focus.

Your original code example had a broken #IfWinActive declaration. I fixed it.

Don't forget that 1.5a requires a different #IfWinActive declaration, ahk_class EVERYTHING_(1.5a). Your example would only work for Everything 1.4 which does not have an X in the Search bar.

Make sure that you have the latest AutoHotkey interpreter installed. 1.1.33.10

Since you're already using MouseGetPos, you have no articulate reason to argue this point. Just use the hwnd value as I demonstrated.
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: AHK WinMenuSelectItem does not work

Post by vsub »

The closing #IfWinActive is only needed if there is no other code and it doesn't need to be #IfWinActive,just a simple #If is enough

I have an ini option enabled that removes the 1.5a from the title bar and when I check the ahk_class of the window,it says ahk_class EVERYTHING not ahk_class EVERYTHING_(1.5a)

I can also just remove the while #If condition and make the MButton to work globally and it still does not work

Code: Select all

~MButton::
Keywait,MButton
  Sleep, 100
  MouseGetPoS,,,win
  WinMenuSelectItem,ahk_id %win%,,Help,About
  Return
This works the same,only on the first window
Attachments
Video_2021-11-14_212947.zip
(322.37 KiB) Downloaded 266 times
raccoon
Posts: 1017
Joined: Thu Oct 18, 2018 1:24 am

Re: AHK WinMenuSelectItem does not work

Post by raccoon »

Try running your .ahk script As Administrator.

If Everything is running As Administrator, a User level AutoHotkey script cannot even see Everything.

Also, many Windows API refuse to function if the AutoHotkey script is not running As Administrator, regardless of what the target process (Everything) is running as. I think WinMenuSelectItem always requires AHK running As Admin.
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: AHK WinMenuSelectItem does not work

Post by vsub »

Everything and AHK are not running as admin
If Everything was working as admin,the script was not going to work on the first window too
raccoon
Posts: 1017
Joined: Thu Oct 18, 2018 1:24 am

Re: AHK WinMenuSelectItem does not work

Post by raccoon »

Does it work now, running AutoHotkey As Admin?
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: AHK WinMenuSelectItem does not work

Post by vsub »

raccoon wrote: Mon Nov 15, 2021 1:30 am Does it work now, running AutoHotkey As Admin?
No,everything is using the service and ahk is running as admin...no differece,it does not work on the second window
void
Developer
Posts: 16698
Joined: Fri Oct 16, 2009 11:31 pm

Re: AHK WinMenuSelectItem does not work

Post by void »

The menus in Everything are dynamic.

In other words, the menu does not exist until it is visible.


Please try sending EVERYTHING_IPC_ID_VIEW_GOTO_HOME (40049) with WM_COMMAND.

Code: Select all

SendMessage, 0x111, 40049,,, A
0x111 = WM_COMMAND
40049 = EVERYTHING_IPC_ID_VIEW_GOTO_HOME (or EVERYTHING_IPC_ID_HISTORY_HOME in Everything 1.5)

everything_ipc.h
vsub
Posts: 474
Joined: Sat Nov 12, 2011 11:51 am

Re: AHK WinMenuSelectItem does not work

Post by vsub »

void wrote: Mon Nov 15, 2021 9:58 am The menus in Everything are dynamic.

In other words, the menu does not exist until it is visible.


Please try sending EVERYTHING_IPC_ID_VIEW_GOTO_HOME (40049) with WM_COMMAND.

Code: Select all

SendMessage, 0x111, 40049,,, A
0x111 = WM_COMMAND
40049 = EVERYTHING_IPC_ID_VIEW_GOTO_HOME (or UI_ID_HISTORY_HOME in Everything 1.5)

everything_ipc.h
Yes that works and since you said
the menu does not exist until it is visible.
I tried clicking on the menus and then execute WinMenuSelectItem and that made the code to work on the second window too
Post Reply