Page 1 of 1

Help with script that no longer works since windows 11 upgrade

Posted: 09 Aug 2022, 09:39
by ahk_Jon
This is a script I found in the forum many years ago - you can view the original thread here: https://autohotkey.com/board/topic/32634-altf1f12-selection-for-open-windows/

It's been working perfectly until I transferred the code over to my new pc running windows 11 pro with a new version of ahk, it no longer seems to bind the window to a key.

Does anyone know what's caused it to fail? All my other scripts seem to be unaffected by the upgrade.

Thanks in advance.

Code: Select all

; Bindable ALT+Fn Window selector - josephusm
; Use Ctrl+Fn to bind the active window, and Alt+Fn to raise it later

Loop, 12
{
    id%A_Index% := 0
}
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

BindKey(key)
{
    ; Store the active window's ID

    WinGet, active_id, ID, A
    id%key% := active_id

    ToolTip, %key%
    SetTimer, RemoveToolTip, 1000
    
    return
}

UseBind(key)
{
    ; Use the stored window's ID to focus it
    ; if it still exists

    win_id := id%key%

    if WinExist("ahk_id" . win_id)
    {
        WinActivate, ahk_id %win_id%

        ToolTip, %key%
        SetTimer, RemoveToolTip, 500
    }
    else
    {
        ToolTip, %key%: No existing window bound
        SetTimer, RemoveToolTip, 1000
    }

    return
}


^F1::
BindKey(1)
return

!F1::
UseBind(1)
return

^F2::
BindKey(2)
return

!F2::
UseBind(2)
return

^F3::
BindKey(3)
return

!F3::
UseBind(3)
return

^F4::
BindKey(4)
return

!F4::
UseBind(4)
return

^F5::
BindKey(5)
return

!F5::
UseBind(5)
return

^F6::
BindKey(6)
return

!F6::
UseBind(6)
return

^F7::
BindKey(7)
return

!F7::
UseBind(7)
return

^F8::
BindKey(8)
return

!F8::
UseBind(8)
return


Re: Help with script that no longer works since windows 11 upgrade

Posted: 09 Aug 2022, 13:08
by mikeyww
Interesting issue. I was playing around with the following script. I'm hoping that someone can explain why the MsgBox is not null!

Code: Select all

id1 := 0, BindKey(1), UseBind(1)

BindKey(key) {
 WinGet, active_id, ID, A
 id%key% := active_id
}

UseBind(key) {
 MsgBox, % id%key%
}
image220809-1410-001.png
Output
image220809-1410-001.png (3.55 KiB) Viewed 2949 times

Re: Help with script that no longer works since windows 11 upgrade

Posted: 09 Aug 2022, 13:29
by gregster
mikeyww wrote:explain why the MsgBox is not null
Because id1 exists as a global variable.
https://www.autohotkey.com/docs/Functions.htm#More_about_locals_and_globals wrote:Within a function (unless force-local mode is in effect), any dynamic variable reference such as Array%i% always resolves to a local variable unless no variable of that name exists, in which case a global is used if it exists. [...]

Re: Help with script that no longer works since windows 11 upgrade

Posted: 09 Aug 2022, 14:02
by mikeyww
Perfect! I figured it was some quirk like that. :)

When I tried the script with the F1 keys indicated, it did work (Win 10 Pro x64).

To debug, you could display the values of the variables at each point. That would probably enable you to trace the problem to a specific line. For example, when you use UseBind, you can display the value of WinExist and win_id.

Re: Help with script that no longer works since windows 11 upgrade

Posted: 11 Aug 2022, 10:43
by ahk_Jon
mikeyww wrote:
09 Aug 2022, 14:02
To debug, you could display the values of the variables at each point. That would probably enable you to trace the problem to a specific line. For example, when you use UseBind, you can display the value of WinExist and win_id.
Thank you for taking the time to look into this, I've been trying to figure it out using your debugging suggestion. To me it appears my PC simply is not storing the ID but i cannot explain why as my ahk knowledge is lacking.

If anyone knows of any windows 11 compatibility issues perhaps that could point me in the right direction.

Re: Help with script that no longer works since windows 11 upgrade

Posted: 10 Mar 2023, 09:21
by ahk_Jon
mikeyww wrote:
09 Aug 2022, 14:02
Perfect! I figured it was some quirk like that. :)

When I tried the script with the F1 keys indicated, it did work (Win 10 Pro x64).

To debug, you could display the values of the variables at each point. That would probably enable you to trace the problem to a specific line. For example, when you use UseBind, you can display the value of WinExist and win_id.
Thank you for your help prviously, just to bring this thread to a conclusion, I figured out the problem - all I had to do was run AKH as Administrator.

doh!