Settings keys to only work when a specified menu is focus

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lord-McFly
Posts: 6
Joined: 30 May 2021, 01:55

Settings keys to only work when a specified menu is focus

Post by Lord-McFly » 05 Feb 2023, 01:27

Hello, fellow AHK enjoyers. I've got this great script from https://stackoverflow.com/questions/35971452/what-is-the-right-way-to-send-alt-tab-in-ahk that displays all open windows. I would like to setup keys that only work when this menu is focus if this is possible. Something like #If.
My idea is to turn W and S into up and down so I can navigate the menu with only my left hand. Thanks in advance!

Code: Select all

F2::AltTabMenu()

AltTabMenu(){
    list := ""
    Menu, windows, Add
    Menu, windows, deleteAll
    WinGet, id, list
    Loop, %id%
    {
        this_ID := id%A_Index%
        WinGetTitle, title, ahk_id %this_ID%
        If (title = "")
            continue            
        If (!IsWindow(WinExist("ahk_id" . this_ID))) 
            continue
        Menu, windows, Add, %title%, ActivateTitle      
        WinGet, Path, ProcessPath, ahk_id %this_ID%
        Try 
            Menu, windows, Icon, %title%, %Path%,, 0
        Catch 
            Menu, windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0 
    }
    CoordMode, Menu, Screen
    Xm := (0.35*A_ScreenWidth)
    Ym := (0.35*A_ScreenHeight)
    Menu, windows, Show, %Xm%, %Ym%
}

ActivateTitle:
    SetTitleMatchMode 3
    WinActivate, %A_ThisMenuItem%
return

;========== Check whether the target window is activation target
IsWindow(hWnd){
    WinGet, dwStyle, Style, ahk_id %hWnd%
    if ((dwStyle&0x08000000) || !(dwStyle&0x10000000)) {
        return false
    }
    WinGet, dwExStyle, ExStyle, ahk_id %hWnd%
    if (dwExStyle & 0x00000080) {
        return false
    }
    WinGetClass, szClass, ahk_id %hWnd%
    if (szClass = "TApplication") {
        return false
    }
    return true
}

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Settings keys to only work when a specified menu is focus

Post by mikeyww » 05 Feb 2023, 08:32

This might work as a separate script. It might need adjustments.

Code: Select all

#Requires AutoHotkey v1.1.33
#If menu()
w::Up
s::Down
#If

menu() {
 WinGet, pName, ProcessName, A
 WinGetClass, class, A
 Return pName = "" && class = ""
}

Lord-McFly
Posts: 6
Joined: 30 May 2021, 01:55

Re: Settings keys to only work when a specified menu is focus

Post by Lord-McFly » 07 Feb 2023, 11:02

Sorry for the late reply but thanks for this, will try it out!

Post Reply

Return to “Ask for Help (v1)”