Sign in to follow this  
Followers 0
guitara

Always on top, always focused

1 post in this topic

I figured I've asked enough questions, and gotten enough help, that I should post something. Here's a little example of a basic app I dev'd for work. It lets you select a window to be always on top, and always focused. It does allow for mouse clicks outside of the window. I use this at work when I want to type into say Word, while examining an image. I click or zoom on the image, then continue typing, without having to reset focus. Also includes a pause hotkey, and allows you to temporarily suspend the always focused property by minimizing. Questions, comments, feedback welcome.

Global $Paused
Global $title
HotKeySet("{PAUSE}", "TogglePause")

$var = WinList()
$done=0
$handle=0
$MsgActive=0
$pos=0

;Choose Window to be always on top, and always focused
For $i = 1 to $var[0][0]
 ; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) and $done=0 Then
    $MsgActive=MsgBox(4, "Set window to Always on top, Always focused?", "Title=" & $var[$i][0] )
    Select
        Case $MsgActive = 6
            $done=1
            $handle=$var[$i][1]
            $title=$var[$i][0]
    EndSelect
  EndIf
Next

WinSetOnTop($title,"",1)
while 1
    WinWaitNotActive($title)
    
;Allow Click outisde of app, then refocus
    while IsPressed('01') or IsPressed('02')
    Wend
    
; Check if window is minimized, if so let it until user reopens it
    $state = WinGetState($title)
    If BitAnd($state, 16) Then
        WinWaitActive($title)
    EndIf
    
    WinActivate($title)
WEnd

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Func IsPressed($hexKey) 
  Local $aR, $bO
  
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
  If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
     $bO = 1
  Else
     $bO = 0
  EndIf
  
  Return $bO
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    ToolTip('Script is "Paused"',0,0)
    While $Paused
    WEnd
    ToolTip("")
EndFunc

test5.au3

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0