Autohotkey: znajdź i zaznacz okna według nazwy na wirtualnych pulpitach

Nov 19 2020

Chciałbym, aby skrypt ahk znajdował i koncentrował się na uruchamianiu okien na wirtualnych pulpitach w systemie Windows 10.

Znalazłem jeden wcześniej, ale niestety zapomniałem skąd pochodzi, może ktoś tutaj wie. Myślę, że miało to pomóc ze specjalnymi skrótami klawiszowymi, które nie działają w sesjach VNC (na przykład klawisz Win, alt-tab). Niestety, ponieważ jest całkiem niezły, ale nie ma funkcji wyszukiwania z klawiatury, działa raczej z wyborem klawiatury lub myszy i sortuje według ostatnio używanych. Więc gdybym mógł znaleźć zaktualizowaną wersję lub jej źródło (aby skontaktować się z jej twórcą), które ma tę funkcję wyszukiwania, idealnie! Oto kod, który mam:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


$F1:: AltTab() $F2:: AltTabMenu()
$F4:: LWin
!`::WinClose, A  ; Alt-` = close window

; AltTab-replacement for Windows 8:
AltTab(){
    list := ""
    WinGet, id, list
    Loop, %id%
    {
        this_ID := id%A_Index%
        IfWinActive, ahk_id %this_ID%
            continue    
        WinGetTitle, title, ahk_id %this_ID%
        If (title = "")
            continue
        If (!IsWindow(WinExist("ahk_id" . this_ID))) 
            continue
        WinActivate, ahk_id %this_ID%, ,2
            break
    }
}

; AltTabMenu-replacement for Windows 8:
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, Mouse, Screen
    MouseMove, (0.4*A_ScreenWidth), (0.35*A_ScreenHeight)
    CoordMode, Menu, Screen
    Xm := (0.25*A_ScreenWidth)
    Ym := (0.25*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
}

dla skryptu o nazwie vnc special keys.ahk, ale może to być nazwa, którą mu nadałem. Przepraszam, niewiele więcej szczegółów na ten temat, rozejrzałem się (Google, Github), ale nie znalazłem. I dzieci, pamiętajcie, aby umieścić komentarz w swoim kodzie przynajmniej z autorem i stroną źródłową :-P

Znalazłem też to https://superuser.com/questions/350238/autohotkey-script-that-quickly-finds-an-open-window-by-title

Odpowiedzi

1 user3419297 Nov 22 2020 at 00:04
F1::    
InputBox, UserInput, Find and focus running windows, Type part of a window title to display a menu with all possible matches.., , 300, 140
if ErrorLevel
{
    MsgBox, CANCEL was pressed.
    return
}   
else
{
    DetectHiddenWindows, On
    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
        If !InStr(title, UserInput)
            continue
        Menu, windows, Add, %title%, ActivateWindow 
        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, Mouse, Screen
    MouseMove, (0.4*A_ScreenWidth), (0.35*A_ScreenHeight)
    CoordMode, Menu, Screen
    Xm := (0.25*A_ScreenWidth)
    Ym := (0.25*A_ScreenHeight)
    Menu, windows, Show, %Xm%, %Ym%
}
return


ActivateWindow:
DetectHiddenWindows, On
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
}

https://stackoverflow.com/a/36008086/3419297