AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to highlight a window?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
cybrown
Guest





PostPosted: Thu Mar 10, 2005 5:56 am    Post subject: How to highlight a window? Reply with quote

I just started using Autohotkey and I love it! It really makes programming in Windows easy. I would like to make a script that cycles through tiled windows on the screen with my mousewheel, and somehow indicates which window is active by some more visual method than the built-in Windows activation. I'd like to be able to draw a big red circle around the window, or somehow thicken the window border and change its color. Is this possible? I know I could do it by making a transparent splash window with the image of a circle, but that seems messy. Any other suggestions? Thanks!!

~Chris
Back to top
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Thu Mar 10, 2005 6:29 am    Post subject: Reply with quote

Transparencies are the only way to go right now, AutoHotkey doesn't have much for drawing on the screen. Confused

Be sure to post that script when you're done with it, btw. It sounds great. Did you get the idea from OSX's Expose?
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Thu Mar 10, 2005 7:20 am    Post subject: Reply with quote

What about to create a HTA (bordered) window with the scale of the window you currently hover with the mouse. Set that window to be fully transp. and put it on top of your target window.

Braindump.
Back to top
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Thu Mar 10, 2005 8:16 am    Post subject: Reply with quote

Ok, now that's a sweet idea. I'm gonna go work on this some right now, I can't let cybrown have all the fun! Cool
Back to top
View user's profile Send private message
Serenity



Joined: 08 Nov 2004
Posts: 1228

PostPosted: Thu Mar 10, 2005 8:23 am    Post subject: Reply with quote

Heres something I made earlier:

Code:
; draw a box round the active window

#SingleInstance force
SetWinDelay, -1
SetBatchLines, -1

Gui, +ToolWindow +AlwaysOnTop -SysMenu -Caption +Border
Gui, Color, cCCCCCC
SetTimer, Draw, 100

Draw:
MouseGetPos, MouseX, MouseY, MouseWin ; get mouse coords/window
WinActivate, %MouseWin%

WinGetActiveStats, Title, WinW, WinH, WinX, WinY ; get the stats of the active window

; variables
DrawW := (WinW)
DrawH := (WinH)
DrawX := (WinX - 1)
DrawY := (WinY - 1)

; show the gui
Gui, Show, NoActivate w%DrawW% h%DrawH% x%DrawX% y%DrawY%, Draw
WinSet, TransColor, CCCCCC, Draw
return

_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
cybrown
Guest





PostPosted: Fri Mar 11, 2005 6:59 am    Post subject: changing border coler Reply with quote

Is there a way to change the default border color? Or will I have to use a graphic for my purposes? Thanks!
Back to top
cybrown
Guest





PostPosted: Fri Mar 11, 2005 7:48 am    Post subject: Reply with quote

Ok, for now I'm trying to use a picture of a big red circle on a white background, but I can't seem to get the background to be transparent. What am I missing here?

Code:
gui, color, FFFFFF
gui, add, picture, backgroundtrans, c:\circle.bmp
gui, show
winset, transcolor,FFFFFF
gui, -caption



The window still has a white background. I'm sure this is simple, can someone help me out? I don't really understand transparency with images. Thanks!
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Fri Mar 11, 2005 1:18 pm    Post subject: Reply with quote

WinSet requires a WinTitle parameter unless you want it to use the last found window. In the case of Gui windows, you can make them "last found" this way:

gui, +lastfound
winset, transcolor,FFFFFF
Back to top
View user's profile Send private message Send e-mail
cybrown
Guest





PostPosted: Fri Mar 11, 2005 7:31 pm    Post subject: Reply with quote

Thanks for the help so far, the script is almost complete! I do have a small problem though. Once a window is circled, I use the following code snipped to click on a button in that window:

Code:
~LButton & q::
   CoordMode, Mouse, Screen
   MouseGetPos,mouseX,mouseY

   CoordMode, Mouse, Relative
   WinActivate, ahk_id %circledWindow%
   WinWaitActive, ahk_id %circledWindow%
   MouseClick, left, %button1x%, %button1y%
   
   CoordMode, Mouse, Screen
   MouseMove,mousex,mousey
return


The idea is that from anywhere on the screen, I push this hotkey, the mouse clicks the button on the circled window, and then moves back to its original position. In practice, when you click the LButton to start the hotkey, Windows activates whatever window is under the mouse. That's why I added the WinActivate into the code. However, even with the WinWaitActivate in there, for some reason the circled window doesn't really seem to be activated. For example, say circledWindow is titled "buttonWindow", on the right side of the screen. I place my mouse over "Untitled-Notepad" on the left side of the screen and press the Lbutton. At this point, the Notepad window becomes active. Now, while holding Lbutton, I press q. Now the weird stuff happens. The mouse attempts to click the button (and fails), and the ButtonWindow flashes. However, the border doesn't remain the "active" color. Instead, buttonWindow looks like it is deactive afterwards, so that neither Notepad or buttonWindow is active. If I continue holding Lbutton and press q again, it successfully clicks the button, and buttonWindow remains active. What's going on here? I'm confused...


PS I tried using #WinActivateForce and it didn't help.
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Mar 12, 2005 2:45 am    Post subject: Reply with quote

I'm not sure why it behaves that way in this case. You could try using a different hotkey temporarily, such as MButton or #z (Win+z), to try to isolate the problem.

If you can't get it working, it would be helpful to have a short test script or hotkey that anyone could run with Notepad or Calculator as the target. Once the problem is reproduced, it can be fixed (or at least explained with workarounds).
Back to top
View user's profile Send private message Send e-mail
cybrown
Guest





PostPosted: Sat Mar 12, 2005 6:56 am    Post subject: Reply with quote

Open a calculator window and run either of these scripts. The code is designed to press "5" on the standard size calc (normal mode, not scientific).

The simple version, with no "mouse retract":
Code:
~LButton & q::
   WinActivate, Calculator
   WinWaitActive, Calculator
   MouseClick, left, 113, 169
return


The version with "mouse retract" (brings mouse cursor back to its starting position afterwards):
Code:
~LButton & q::
   CoordMode, Mouse, Screen
   MouseGetPos,mouseX,mouseY

   CoordMode, Mouse, Relative
   WinActivate, Calculator
   WinWaitActive, Calculator
   MouseClick, left, 113, 169

   CoordMode, Mouse, Screen
   MouseMove,mousex,mousey
return


Now, place the cursor over the desktop and hold the Lbutton. Obviously calculator will lose the focus. Press 'q' while holding the mouse button and you'll see the cursor flash over to the calculator window and then come back. You'll also see the title bar of the calc window flash, but the 5 button will not be pressed. If you use another window (like a notepad window) instead of just the desktop, you'll also notice that that window somehow regains the focus after the mouse zooms to the calc window and back.

If you keep Lbutton pressed after you release 'q', then press 'q' again, you'll achieve the desired effect - '5' will be pressed, and calc will maintain the focus afterwards. However, if you release Lbutton, then press it again to try the hotkey, you should be unsuccessful each time.

If you click somewhere in the calc window during the hotkey - say, in one of the inactive areas - then press q, the script will work on the first try.

Notice also that if you make the following changes:

Code:
~LButton & q::
   CoordMode, Mouse, Screen
   MouseGetPos,mouseX,mouseY

   CoordMode, Mouse, Relative
   WinActivate, Calculator
   WinWaitActive, Calculator
   MouseClick, left, 113, 169

   CoordMode, Mouse, Screen
   MouseMove,mousex,mousey
   wingettitle,title,A ;This title SHOULD be "Calculator"
   msgbox, %title%
return


When you run the code now, clicking on the desktop to run the hotkey, the msgbox that opens will simply be empty, indicating that there is no active window (although, the window you clicked on would be active if you clicked a window instead of the desktop, even though the msgbox will still be blank). If you keep Lbutton pressed and press q a second time, this time the msgbox will show you that Calculator is active, which in fact it is. If you try to use a different hotkey, like #q, the script runs fine. Is there any way around this? I tried all of the following:

A version using absolute coords:
Code:
~LButton & q::
   WinGetPos,winX,winY,,,Calculator
   CoordMode, Mouse, Screen
   clickx := winx + 113 ;figure out absolute coords
   clicky := winy + 169
   mouseclick,left,clickx,clicky
return


A complicated, roundabout version using MouseGetPos:

Code:
~LButton & q::
   WinGetPos,winX,winY,,,Calculator
   CoordMode, Mouse, Screen
   clickx := winx + 113
   clicky := winy + 169
   MouseMove, clickx, clicky
   MouseGetPos,,,MouseWin
   WinActivate,ahk_id %MouseWin%
   WinWaitActive,ahk_id %MouseWin%
   Mouseclick, left ;the mouse is already over the button
return   


All of these attempts should give you the same results, where the button is clicked on the second try. As far as I know, using #WinActivateForce doesn't change things. Is there any way to get this kind of hotkey to work, or is the mouseclick throwing things off? Obviously I can't just use "LButton & q::" instead of "~LButton & q::" because I'll lose all mouse functionality. (Incidentally, using "LButton & q::" does work, since no other window "steals" the focus when you press LButton.) Slowing down the mousespeed doesn't seem to help either. I'm at a loss Sad

...Any ideas? Thanks for your input!

~Chris
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Mar 12, 2005 1:09 pm    Post subject: Reply with quote

Thanks for the in depth explanation.

I believe this behavior is caused by the fact that the OS resists activating other windows while you're holding down the left mouse button. This is probably done to prevent focus from being "stolen" at a critical moment, which might cause the app you're working with to think that the left mouse button is stuck down (when you later return to it).

Although I don't see a way to fix this in the program, here is one workaround: Insert "KeyWait, LButton" as the first line of the hotkey subroutine. It will wait for you to release the left mouse button before executing the subroutine, which seems to avoid this issue.

If the above workaround is unsatisfactory, there may be others.
Back to top
View user's profile Send private message Send e-mail
cybrown
Guest





PostPosted: Sun Mar 13, 2005 2:20 am    Post subject: Reply with quote

Thanks for the tip. It looks like you're right about the mousekey "sticking", because I also came up with the following. This will work on the first try:


Code:
~LButton & q::
   WinActivate, Calculator
   MouseClick, left, 113, 169
   MouseClick, left
return


After the first try, it will register 2 clicks each time if you don't release Lbutton between tries. Since that worked, I expected the following to work for all cases:


Code:
firstclick = true
~LButton & q::
   WinActivate, Calculator
   MouseClick, left, 113, 169
   if firstclick = true
      MouseClick, left
   firstclick = false
return
~Lbutton up::firstclick = true


This doesn't seem to work quite as expected though. Run the script, then click outside the calc window as before to try to fire the hotkey. You will get the desired result. If you now release Lbutton and try again immediately, the script will not work. However, if you first click once on the desktop and then click again to fire the hotkey, you will again get the desired result. It looks like the OS is somehow confused by the "artificial" firing of Lbutton occurring while the Lbutton is actually being held down. Does this give you any ideas? Thanks for all your help so far!

~Chris
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sun Mar 13, 2005 5:58 pm    Post subject: Reply with quote

If you have a satisfactory workaround, I'd just stick with that. This issue is getting far into the fringe now, and in most cases your guesses will be at least as good as mine.

However, if you ever discover behavior that you think could be a bug or that needs improvement in the program, please let me know.
Back to top
View user's profile Send private message Send e-mail
ProsperousOne



Joined: 19 Sep 2005
Posts: 100

PostPosted: Wed Aug 06, 2008 9:16 pm    Post subject: Draws Border Around Active PokerStars Poker Table Reply with quote

After 6 hours (!!!) Mad This code will draw a red border around the active window that is a PokerStars poker table window.

It actually briefly flashes once, as a red GUI is drawn OVER the top of the window the first time it is activated, then the poker table window is reactivated to bring it to the top.

This can be alievated by changing line 37 from

Gui, Show, x%ActiveWinIDX% y%ActiveWinIDY% w%ActiveWinIDW% h%ActiveWinIDH%

to

GGui, Show, Noactivate x%ActiveWinIDX% y%ActiveWinIDY% w%ActiveWinIDW% h%ActiveWinIDH%.

However, unless the desktop is clear, except for a poker table, the border will not appear, as it is drawn at bottom of the z-order... I couldn't figure out how to change the z-order, without activating it. Try it both ways


Code:
BorderColor := 0xFF0000   ; red
SysGet, border, 32
SetTimer, DrawActiveBorder, 100

DrawActiveBorder:
ActiveWinID := WinActive("A")
WinGet, idlist, list, ahk_class PokerStarsTableFrameClass ; get all PS Tables
PSTableActive := False
Loop, %idlist%
  {
    id := idlist%A_Index%
       If (ActiveWinID = id )      ; Active Window is PS Table Window
             {
             PSTableActive := True
             Break
          }
   }
If !PSTableActive   ; Active Window is Not PS Table, kill GUI
         {
              Gui, Destroy
              WinSet, Region,, ahk_id %LastActiveWinID%
              Return
          }
If !WinExist("ahk_id " . LastActiveWinID) ; Last window no longer exists, kill gui
    Gui, Destroy
Gui, +LastFoundExist   ; Determine if GUI already exists
IfWinExist
  If (ActiveWinID = LastActiveWinID)            ; GUI already exisits
       Return                                                   ; And is the same as current window
WinSet, Region,, ahk_id %LastActiveWinID%   ;
LastActiveWinID := ActiveWinID
WinGetPos, ActiveWinIDX, ActiveWinIDY, ActiveWinIDW, ActiveWinIDH, A
Gui, -Border -Caption
Gui, Color, %BorderColor%
w := ActiveWinIDW - (2 * border)
h := ActiveWinIDH - (2 * border)
Gui, Show, x%ActiveWinIDX% y%ActiveWinIDY% w%ActiveWinIDW% h%ActiveWinIDH%
WinSet, Region, %border%-%border% w%w% h%h%, ahk_id %ActiveWinID%  ; Make all parts of the window outside this rectangle invisible.
WinActivate, ahk_id %ActiveWinID%
Return
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group