Set a window Always On Top

This AutoHotkey script is related to this post:

https://community.sdl.com/product-groups/translationproductivity/f/studio/35337/why-is-the-find-and-replace-window-is-not-always-on-top

where the poster asked to set the Find and Replace window on top of the Editor.

The following script will set any window Always On Top. It works with any window, not only the Find and Replace dialog box.

I use the Application key plus the V keys as a hotkey, but you can change it to your convenience.

☛ The Application Key is also called the Menu Key and when pressed it opens a contextual menu: Screenshot of an AutoHotkey script to set the Find and Replace window in Trados Studio always on top using the Application key and V.

AppsKey & v::
        while GetKeyState("AppsKey", "P")
                Sleep, 20
        Winset, Alwaysontop, Toggle, A
return

Add these lines to your script file and when the Find and Replace window (or any window) is open and active, press the hotkey. From now on the window will be on top on any window, not that just the Editor. And it'll be on top until you close the Find and Replace dialog box or until you press again the same hotkey.

  • If you close the Find and Replace dialog box, and re-open it later, you will need to press your hotkey again to set it always on top.
  • If you use another hotkey, you might need to edit the GetKeyState parameter accordingly.

I hope it helps!



Generated Image Alt-Text
[edited by: Trados AI at 4:31 AM (GMT 0) on 5 Mar 2024]
emoji
Parents Reply
  •   

    I was testing the "Replace" problem with support in that the Find tab is always active and never the Replace even when clicking Ctrl+H.  They could not reproduce this issue.  So I revisited the script and made a change so that now it all works correctly:

    ;------------------------------------------------------------------------------
    ; Ensure "Find and Replace" window is always on top when Trados Studio is active
    ; and not always on top when Trados Studio is not active
    ;------------------------------------------------------------------------------
    
    #Requires AutoHotkey v2.0
    
    ; Initialize the global variable
    global isOnTop := false
    
    #HotIf WinActive("ahk_exe SDLTradosStudio.exe")
    
    $^f:: triggerFindOrReplace("Find")
    $^h:: triggerFindOrReplace("Replace")
    
    triggerFindOrReplace(action) {
        global isOnTop
        find := "Find and Replace" ; Window title of the Find and Replace window
    
        if (action = "Find") {
            Send '^f'
        } else if (action = "Replace") {
            Send '^h'
        }
    
        If WinWaitActive(find, "", 2) {
            if !isOnTop {
                WinSetAlwaysOnTop(1, find) ; Set Always-on-Top only once
                isOnTop := true
            }
        }
    }
    
    ; Check the active window every 100 milliseconds
    SetTimer(CheckActiveWindow, 100)
    
    CheckActiveWindow() {
        global isOnTop
        find := "Find and Replace"
        activeWin := WinExist("A")
    
        ; Add a small delay to ensure the active window is fully registered
        Sleep(100)
        if WinActive("A") != activeWin {
            return  ; The active window has changed, do nothing
        }
    
        if activeWin and WinActive("ahk_exe SDLTradosStudio.exe") {
            if WinExist(find) and !isOnTop {
                WinSetAlwaysOnTop(1, find)
                isOnTop := true
            }
        } else {
            if WinExist(find) and isOnTop {
                WinSetAlwaysOnTop(0, find)
                isOnTop := false
            }
        }
    }
    
    #HotIf

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
Children