Autohotkey : 가상 데스크톱에서 이름으로 창 찾기 및 초점 맞추기

Nov 19 2020

Windows 10의 가상 데스크톱에서 실행중인 창을 찾고 집중하는 ahk 스크립트를 원합니다.

나는 더 일찍 하나를 찾았지만 아쉽게도 그것이 어디에서 왔는지 잊어 버렸습니다. VNC 세션에서 작동하지 않는 특수 키 단축키 (예 : Win 키, alt-tab)를 지원하기위한 것이라고 생각합니다. 안타깝게도 꽤 좋지만 키보드 검색 기능이 없기 때문에 키보드 또는 마우스 선택과 함께 작동하고 가장 최근에 사용 된 순서로 정렬됩니다. 따라서이 검색 기능이있는 업데이트 된 버전 또는 소스 (개발자에게 문의)를 찾을 수 있다면 완벽합니다! 내가 가진 코드는 다음과 같습니다.

#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
}

라는 스크립트의 vnc special keys.ahk경우이 이름은 내가 지정한 이름 일 수 있습니다. 이것에 대한 자세한 내용은 아니지만 (Google, Github) 둘러 보았지만 찾지 못했습니다. 그리고 여러분, 최소한 작성자와 소스 웹 사이트에 주석을 달아야합니다.

오래된 2010 스크립트 도 찾았습니다.

답변

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