Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Auto-raise / mouse hover


  • Please log in to reply
96 replies to this topic
KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Does anyone have a windows 7 version that works? Cause its not working for me in windows 7.

grannyGrump
  • Members
  • 51 posts
  • Last active: Mar 13 2015 09:05 AM
  • Joined: 13 Sep 2010
digging up this old thread, because I've been using GetMouseTaskButton() very happily in XP.
I'm using it in an Auto-raise routine, and in a routine for Middle-click Taskbar Button to Close Window.
http://www.autohotke...ght=scroll klik

It doesn't work in my Vista-64, I think because I'm running it using AHK Basic or AHK_L_ansi.

I don't know how to port my big script to AHK_L_64. :oops:

How would I go about adapting the GetMouseTaskButton function for 64-bit?
Please, can someone point me toward a solution?
Antique Newbie

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
I'm not aware of a working solution. MS changed the taskbar and made it more difficult to use. I'm sure there is a way somehow, but I have not seen it yet. If you're not using a 64bit build of AHK you won't have to adapt your scripts in most cases.

grannyGrump
  • Members
  • 51 posts
  • Last active: Mar 13 2015 09:05 AM
  • Joined: 13 Sep 2010
fragman, thanks for the heads-up about converting scripts. I'm too much of a novice to face that daunting task just yet.
I'm using Basic and AHK_L_ansi with great satisfaction.

I cobbled together a clunky workaround using Sean's Taskbutton.ahk that got me a working solution to auto-raise by hovering taskbuttons in Vista-64-bit. Doesn't work for grouped taskbar buttons, but that's ok.

EDIT -- got the group buttons to work too, so its all good!
Antique Newbie

AndyAlbany
  • Members
  • 9 posts
  • Last active: Sep 19 2011 06:42 PM
  • Joined: 24 Feb 2011
Hi All,

I communicated with Lexikos and helped me fiddle with this script enough to get the autoraise to work on my Win 7 64 bit taskbar and windows orb. The hover any window still works too, but he said that the hover min max works intermittently and couldn't be updated (I would remove it from the script, but I don't know how without breaking the whole thing). I don't know if it works on grouped buttons, because I don't group my buttons.

#Persistent

hover_task_buttons  = 1 ; hover over taskbar button to activate window
  hover_task_group  = 0 ; hover to select (or exit) from a window-group menu
                        ; (for Windows' "Group similar taskbar buttons" feature)
hover_task_min_info = 0 ; only show info for minimized windows, don't activate
hover_start_button  = 1 ; hover over start button to open start menu
hover_min_max       = 0 ; minimize or maximize by hovering over the min/max buttons
hover_any_window    = 1 ; activate any window by hovering (except the taskbar)

hover_no_buttons    = 1 ; ignore hover if a mouse button is in the down state

hover_delay       = 200 ; hover delay, from when the mouse stops moving

; WORKS, BUT NOT PERFECTLY: (brings the window forward, then puts it back in place)
hover_keep_zorder   = 0 ; don't bring windows forward, only activate them

;
; DisableHover - since menus aren't usually truly "activated", if any
;   window in the DisableHover group *EXISTS*, hover will be ignored.
;
GroupAdd, DisableHover, ahk_class #32768

; I'm not certain whether this class is used only for menus;
; if not, you may need to comment out this line.
GroupAdd, DisableHover, ahk_class MozillaDropShadowWindowClass


CoordMode, Mouse, Screen
SetTimer, hovercheck, 10
return


; Don't consider it hovering if the mouse was clicked.
; However, clicking and then moving a small amount will still trigger hover.
~LButton::
~RButton::
~MButton::
    MouseGetPos, lastx, lasty
return


hovercheck:
    MouseGetPos, x, y
    if (x != lastx or y != lasty)
    {
        SetTimer, hovering, % -hover_delay
        lastx := x
        lasty := y

        if (remove_ttip_on_move)
        {
            ToolTip
            remove_ttip_on_move := false
        }
    }
return


hovering:
    if (hover_no_buttons && (GetKeyState("LButton") or GetKeyState("RButton")))
        return
   
    if (WinExist("ahk_group DisableHover"))
        return

; hover over taskbar button to activate window:
    if (hover_task_buttons)
    {
        MouseGetPos,,, win, ctl
        if (ctl="MSTaskListWClass1") {
            Click
            return
        }
    }
; hover over start button to open start menu:
    if (hover_start_button && !WinActive("ahk_class DV2ControlHost")) ; Start Menu
    {
        MouseGetPos,,, win, ctl
        WinGetTitle, ti, ahk_id %win%
        WinGetClass, cl, ahk_id %win%
        if (A_OSVersion = "WIN_7" && (cl = "Button" && ti = "Start"))
            or (cl = "Shell_TrayWnd" && ctl = "Button1")
        {
            Click
            return
        }
    }
; hover over minimize, maximize or help buttons on titlebar:
    if (hover_min_max)
    {
        MouseGetPos, x, y, win, ctl, 2
        SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, % "ahk_id " (ctl ? ctl : win)
        if ErrorLevel in 8,9  ; min,max (titlebar)
        {
            Click
            return
        }
    }
; hover over any window to focus:
    if (hover_any_window)
    {
        ifWinExist, ahk_id %win% ahk_class Shell_TrayWnd
            return  ; don't activate the taskbar
        MouseGetPos,,, win
        if (!WinActive("ahk_id " win)) {
            if (hover_keep_zorder)
                JustActivate(win)
            else
                WinActivate, ahk_id %win%
        }
    }
return


JustActivate(hwnd)
{
    if (WinActive("ahk_id " hwnd))
        return
   
    ; Get the window which hwnd is positioned after, so hwnd's position
    ; in the z-order can be restored after activation.   
    hwnd_prev := GetPrevWindow(hwnd)
    ; DllCall("GetWindow","uint",hwnd,"uint",3) would be simpler,
    ; but doesn't work right since it usually gets an invisible window
    ; which moves when we activate hwnd.
   
    ; Repositioning a window in the z-order sometimes sets AlwaysOnTop.
    WinGet, OldExStyle, ExStyle, ahk_id %hwnd%
   
    ;WinActivate, ahk_id %hwnd%  ; -- best to use SetWinDelay,-1 if using WinActivate.
    DllCall("SetForegroundWindow", "uint", hwnd)
    DllCall("SetWindowPos", "uint", hwnd, "uint", hwnd_prev
        , "int", 0, "int", 0, "int", 0, "int", 0
        , "uint", 0x13)  ; NOSIZE|NOMOVE|NOACTIVATE (0x1|0x2|0x10)
   
    ; Note NOACTIVATE above: if this is not specified, SetWindowPos activates
    ; the window, bringing it forward (effectively ignoring hwnd_prev...)

    ; Check if AlwaysOnTop status changed.   
    WinGet, ExStyle, ExStyle, ahk_id %hwnd%
    if (OldExStyle ^ ExStyle) & 0x8
        WinSet, AlwaysOnTop, Toggle
}

; Like GetWindow(hwnd, GW_HWNDPREV), but ignores invisible windows.
GetPrevWindow(hwnd)
{
    global GetPrevWindow_RetVal

    static cb_EnumChildProc
    if (!cb_EnumChildProc)
        cb_EnumChildProc := RegisterCallback("GetPrevWindow_EnumChildProc","F")

    ; Set default in case enumeration fails.
    GetPrevWindow_RetVal := DllCall("GetWindow", "uint", hwnd, "uint", 3)
   
    ; Enumerate all siblings of hwnd.
    hwnd_parent := DllCall("GetParent", "uint", hwnd)
    DllCall("EnumChildWindows", "uint", hwnd_parent, "uint", cb_EnumChildProc, "uint", hwnd)
   
    ; Return the last visible window before hwnd.
    return GetPrevWindow_RetVal
}
GetPrevWindow_EnumChildProc(test_hwnd, hwnd)
{
    global GetPrevWindow_RetVal
    ; Continue until hwnd is enumerated.
    if (test_hwnd = hwnd)
        return false
    ; Remember the last visible window before hwnd.
    if (DllCall("IsWindowVisible", "uint", test_hwnd))
        GetPrevWindow_RetVal := test_hwnd
    return true
}


; Gets the index+1 of the taskbar button which the mouse is hovering over.
; Returns an empty string if the mouse is not over the taskbar's task toolbar.
;
; Some code and inspiration from Sean's TaskButton.ahk
GetMouseTaskButton(ByRef hwnd)
{
    MouseGetPos, x, y, win, ctl, 2
    ; Check if hovering over taskbar.
    WinGetClass, cl, ahk_id %win%
    if (cl != "Shell_TrayWnd")
        return
    ; Check if hovering over a Toolbar.
    WinGetClass, cl, ahk_id %ctl%
    if (cl != "ToolbarWindow32")
        return
    ; Check if hovering over task-switching buttons (specific toolbar).
    hParent := DllCall("GetParent", "Uint", ctl)
    WinGetClass, cl, ahk_id %hParent%
    if (cl != "MSTaskSwWClass")
        return

   
    WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd

    hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
    pRB := DllCall("VirtualAllocEx", "Uint", hProc
        , "Uint", 0, "Uint", 20, "Uint", 0x1000, "Uint", 0x4)

    VarSetCapacity(pt, 8, 0)
    NumPut(x, pt, 0, "int")
    NumPut(y, pt, 4, "int")
   
    ; Convert screen coords to toolbar-client-area coords.
    DllCall("ScreenToClient", "uint", ctl, "uint", &pt)
   
    ; Write POINT into explorer.exe.
    DllCall("WriteProcessMemory", "uint", hProc, "uint", pRB+0, "uint", &pt, "uint", 8, "uint", 0)

;     SendMessage, 0x447,,,, ahk_id %ctl%  ; TB_GETHOTITEM
    SendMessage, 0x445, 0, pRB,, ahk_id %ctl%  ; TB_HITTEST
    btn_index := ErrorLevel
    ; Convert btn_index to a signed int, since result may be -1 if no 'hot' item.
    if btn_index > 0x7FFFFFFF
        btn_index := -(~btn_index) - 1
   
   
    if (btn_index > -1)
    {
        ; Get button info.
        SendMessage, 0x417, btn_index, pRB,, ahk_id %ctl%   ; TB_GETBUTTON
   
        VarSetCapacity(btn, 20)
        DllCall("ReadProcessMemory", "Uint", hProc
            , "Uint", pRB, "Uint", &btn, "Uint", 20, "Uint", 0)
   
        state := NumGet(btn, 8, "UChar")  ; fsState
        pdata := NumGet(btn, 12, "UInt")  ; dwData
       
        ret := DllCall("ReadProcessMemory", "Uint", hProc
            , "Uint", pdata, "UintP", hwnd, "Uint", 4, "Uint", 0)
    } else
        hwnd = 0

       
    DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
    DllCall("CloseHandle", "Uint", hProc)


    ; Negative values indicate seperator items. (abs(btn_index) is the index)
    return btn_index > -1 ? btn_index+1 : 0
}


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

he said that the hover min max works intermittently and couldn't be updated

The script can't determine whether you're hovering over a taskbar button or which window it is associated with; there's nothing intermittent about it. I said nothing about "hover min max".

I've updated the script in my first post.

Btw, by changing the A_OSVersion check instead of removing it as I suggested, you will prevent that functionality from working on Windows Vista.

AndyAlbany
  • Members
  • 9 posts
  • Last active: Sep 19 2011 06:42 PM
  • Joined: 24 Feb 2011

The script can't determine whether you're hovering over a taskbar button or which window it is associated with; there's nothing intermittent about it. I said nothing about "hover min max".


Sorry, my mistake

HumbleQuery
  • Guests
  • Last active:
  • Joined: --
At the risk of public embarrassment, what is that entry on line 75?

I tried running Lexikos' updated script from page 1, running with AHK Basic and with AHK_L_ansi on XP-32, and with AHK_L 64 on Vista-64bit.
I get message
"call to non-existing function" specifically
line 75 D("got win " win " :: " ti)

Please, can someone help?
What did I do wrong?

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
It`s probably related to debugging. Try simply removing that line.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I've removed the offending line from the script, but basically D is this:
D(t) {
    e := ErrorLevel
    FileAppend %t%`n, *  ; Output to stdout (SciTE)
    OutputDebug %t%`n    ; Output to debugger (VC++)
    ErrorLevel := e
    return t
}


HumbleQuery
  • Guests
  • Last active:
  • Joined: --
Thanks guys!
that got it.

AndyAlbany
  • Members
  • 9 posts
  • Last active: Sep 19 2011 06:42 PM
  • Joined: 24 Feb 2011
Hello,

I'm still using this script and I love it. The problem I'm having now is that when hover_any_window is "on" (and I can activate a window by hovering over it) I have trouble selecting from drop down boxes in Firefox. As soon as I move my cursor off of the button that activates the drop down menu (to select an item on the menu), the drop down menu disappears.

I can get around this by holding the left mouse key down after I click the button to activate the drop down menu, and then releasing the button to select an item on the menu (as I have hover_no_buttons on, which means that the script doesn't hover to activate when a mouse button is down) but there has to be a better way. Ideally, I'd like to add the drop down menu class to the "disablehover" group, but I can't figure out the class (or even if these types of boxes have classes). The window class in AutoIt Windows Spy doesn't chance when I hover over these menus, and it just returns "MozillaWindowClass" which is just the class name of the main Firefox window. I've also tried with ComboBox and DropDownList but these haven't worked.

Does anyone know the class name for these drop down boxes in Firefox, or have any other suggestions about how I can fix this?

membersound
  • Members
  • 92 posts
  • Last active: Nov 12 2013 02:23 PM
  • Joined: 07 Mar 2009
I have one question: why does this script perform "clicks" in the windows startup menu? Click start > programs > if I then hover any program, it will be RUN!? How can I prevent this?


Here's my config:

hover_task_buttons  = 1 ; hover over taskbar button to activate window
  hover_task_group  = 1 ; hover to select (or exit) from a window-group menu
                        ; (for Windows' "Group similar taskbar buttons" feature)
hover_task_min_info = 0 ; only show info for minimized windows, don't activate
hover_start_button  = 0 ; hover over start button to open start menu
hover_min_max       = 1 ; minimize or maximize by hovering over the min/max buttons
hover_any_window    = 0 ; activate any window by hovering (except the taskbar)

hover_no_buttons    = 1 ; ignore hover if a mouse button is in the down state

hover_delay       = 100 ; hover delay, from when the mouse stops moving


Talisman
  • Moderators
  • 51 posts
  • Last active: Feb 26 2014 02:22 PM
  • Joined: 24 Feb 2010
Just to confirm that Andy's Script (with Lexikos' debug function) works perfectly on Windows 7 Pro 32 bit.
hovering over any window activates it, as well as hovering over any tasklist button activates it's related window.

ChromeUser
  • Guests
  • Last active:
  • Joined: --
Whenever I open a Chrome or Pidgin context menu and move the cursor over it, it closes. anyone encountered a similar issue?