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
  • Hi 

    Couldn't set it out Is there any video tutorial available for that?

    emoji
  • Hi ,

    The above code works works, but I've confirmed that it doesn't work if I run it in a second AutoHotkey script and I try to set a window on top with both scripts. If I reload the 2nd script, then the 1st one doesn't work. Weird…

    Have you got 2 AutoHotkey scripts running?

    BTW: This is the code I use nowadays:

    AppsKey & v::
        WinGet, ExStyle, ExStyle, A
        if (ExStyle & 0x8)  ; 0x8 is WS_EX_TOPMOST
            ; ToolTip to show alwaysON enabled
        else
            ; ToolTip to show alwaysON disabled
        Winset, Alwaysontop, Toggle, A

    return

    emoji
  •  

    You know what? Now a window opens up that tells me that the script I am trying to run requires AutoHotkep v.1    ahahahahah! I am totally defeated!

    There is no doubt in my mind that you have copied the wrong one.  I believe you used the link that Jesús provided which took you to the top of the thread and then you looked down and took the first one you came to from me which is for V1.  If you scrolled to the very next message you would have seen the one from me that was for V2.

    I gave you a direct link to that post:  RE: Studio 2022 Find/Replace dialog box is always displayed on top 

    Please do this again and make sure that you use the correct script.  Only this time I am putting the script here as well!!

    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
  • No, Paul, sorry to contradict you but I assure you I clicked on YOUR link and there were two buttons, for version 1 and for version 2 (with v.2 even indicated as "deprecated"), and I clicked on v. 2.0.

    In fact, the message I see now is saying that the script is for v. 1 and I should download v.1, and that's because they see that I have v.2.

    I created a script .ahk file with the same name you gave to yours, with mi initials "VMT.correct" and I opened it with Notepad. Actually I did not quite understand WHAT IS THE SCRIPT exactly: do I have to copy and paste the entire content of your screenshot here above?
    ;------------------------------------------------------------------------------
    ; 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

    #HotIf WinActive("ahk_exe SDLTradosStudio.exe")

    $^f:: triggerFindAndReplace()
    $^h:: triggerFindAndReplace()

    triggerFindAndReplace() {
        find := "Find and Replace" ; Window title of the Find and Replace window
        Send '^f'
        If WinWaitActive(find, "", 2) {
            WinSetAlwaysOnTop(1, find) ; Use 1 for On
    ;        SoundBeep(1500)
        }
    }

    ; Check the active window every 100 milliseconds
    SetTimer CheckActiveWindow, 100

    CheckActiveWindow() {
        find := "Find and Replace"
        activeWin := WinExist("A")

        if activeWin and WinActive("ahk_exe SDLTradosStudio.exe") {
            if WinExist(find) {
                WinSetAlwaysOnTop(1, find) ; Turn on always on top if Trados Studio is active
            }
        } else {
            if WinExist(find) {
                WinSetAlwaysOnTop(0, find) ; Turn off always on top if Trados Studio is not active
            }
        }
    }

  •  

    In fact, the message I see now is saying that the script is for v. 1 and I should download v.1, and that's because they see that I have v.2.

    Confusing…

    Do you get this error message? This script requires AutoHotkey v2.0.

    If so, you installed AutoHotkey v.1.1 instead of AutoHotkey 2.0 (although you said above that you installed 2.0):

    Yes, I followed Paul's instructions (his video above). I downloaded the AutoHotkey software (v. 2.0),

    In Windows > Apps & features section, please check if you have this AutoHotkey version installed:

    Screenshot showing AutoHotkey version 1.1.37.02 with a date of 16032024.

    If so, please uninstall this application from the same place, go to the AutoHotkey website https://www.autohotkey.com/ and install AutoHotkey v2.0.

    Hopefully it will work!

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 9:42 AM (GMT 1) on 27 Jun 2024]
  •  

    Just to add to this... here's what I have installed:

    Screenshot showing the AutoHotkey application icon with version number 2.0.11 and a date of 01032024.

    Version 2.0.11

    That's what you should have as well.

    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


    Generated Image Alt-Text
    [edited by: RWS Community AI at 10:47 AM (GMT 1) on 27 Jun 2024]
  •  

    Actually I did not quite understand WHAT IS THE SCRIPT exactly: do I have to copy and paste the entire content of your screenshot here above?

    That wasn't a screenshot, it was the actual script added as a code snippet in the forum to separate it from the text.

    And yes, you should copy/paste all of it.

    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
  • None of these. From Paul's link https://www.autohotkey.com/
    AutoHotkey website with a header 'AutoHotkey - Powerful. Easy to learn.' and buttons to download version 2.0 and version 1.1 (deprecated).e

    I downloaded v2.0, of course, and I got this .exe:
    AutoHotkey v2.0.17 installation window with options to install to 'C:Program FilesAutoHotkey', and install modes for 'All users', 'Current user', or 'Portable'.
    which then appears in the Start menu as AutoHotkey Dash...

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 12:29 PM (GMT 1) on 27 Jun 2024]
  •    

    Just a quick update.  Valeria and I just had a quick call and we resolved the problem.  The correct version of AHK was installed, but the old version of the script (v1) was still in the ahk file in the start folder.  We replaced the script and all is well... tested the functionality and that tricky little find/replace window is now happily sitting behind other windows waiting patiently for Valeria to get back to Studio ;-)

    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
  • Yes, that one is resolved and thank you again (did I thank you?), Paul :-)))
    However, Trados 2021 won't be installed, I keep receiving the same message. Probably because 2021 should have been installed BEFORE 2022, and now that I am trying to reinstall it AFTER I got 2022, this is not accepted anymore?

    Error message from Trados Studio 2021 SR2 installation stating 'Setup did not complete. The error is: Setup has detected a higher version of this product already installed. If you still wish to install this version, you must remove the other version first.' with an OK button.

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 4:03 PM (GMT 1) on 27 Jun 2024]
  • But probably I can do without the 2021 version now that I resolved the Find&Replace problem... so don't worry! :-*

    emoji
  •   

    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:

    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
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:

    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
  • HI Paul, sorry for not replying earlier but I was busy and then on a short holiday this week. Thank you for taking the time to change the script for this issue. The problem now is that I don't remember the procedure for the script :-DDD Can you remind me where I have to put it? Just open Autokey and replace all the content I see with this new script above?

    emoji
  •  

    Hi Valeria,

    I'm just adding a link to   here, in case he doesn't see your response.

    All the best,

    Ali Smiley

    emoji
  •  

    Can you remind me where I have to put it?

    You can put it wherever you like!  But in your case I recall we put it into the Windows startup folder so that it runs automatically every time you start your computer up.

    Just open Autokey and replace all the content I see with this new script above?

    The easiest way to do this, as you already have a script in place is this:

    AutoHotkey system tray menu open with cursor hovering over 'Edit Script'. Other options include 'Reload Script', 'Suspend Hotkeys', and 'Exit'. Notification area shows date as 07082024.

    Right-Click on the AHK icon in your system tray, and then:

    1. Select "Edit Script" and this will open in notepad or some editor.  Replace the script there with the new one.  Just copy paste.  Save it!
    2. After saving it, close the file and then select "Reload Script" and you're done.

    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


    Generated Image Alt-Text
    [edited by: RWS Community AI at 8:09 AM (GMT 1) on 7 Aug 2024]
  • Ok great, I replaced it!
    But half an hour ago another problem started: suddenly the usual Trados keys I use to go from a segment to the next do not work any more! And not even the Confirm button! ahahahah I am going nuts this summer.........

    emoji
  •   

    ok - I tightened up the script a little.  The updated version is here:

    Replace the one you had with this in the same way as before.  The new script refines and simplifies the handling of "Find and Replace" window behaviour in relation to Trados Studio.  It removes the reliance on the #HotIf directive, directly integrates checks for whether the relevant window is active, and uses a more consistent approach to setting the "Always on Top" status.  This makes the script more robust and less dependent on the exact timing or state changes within the application.

    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
  • Thanks, Paul. I am trying to change it. I will let you know if and when I succeed...

    emoji
  • Seems to work fine! T H A N K    Y O U  !!!!!

    emoji
  • Sometimes it works sometimes it doesn't... but anyway ;-)

    emoji