Keyboard generated double click and Win10 taskbar window switching

Report problems with documented functionality
arnestein
Posts: 2
Joined: 16 Jan 2022, 07:40

Keyboard generated double click and Win10 taskbar window switching

Post by arnestein » 16 Jan 2022, 08:05

I have mapped mouse buttons to the numeric keyboard since some time, and it works fine, the code is this one:

Code: Select all

NumpadIns::
+NumpadIns::
^NumpadIns::
^+NumpadIns::
{
  Click, Down
  keywait, NumpadIns
  Click, Up
}
Return
It works correctly for almost everything, but I do have an issue with switching windows using the preview feature of the Win 10 taskbar. I.e. the thumbnails that come up when you hover over an app with several open windows, the thumbs appear just over the taskbar.

The double click does not register to switch window, but rather goes to the window/app underneath the thumbnail and activates that one.

I am running this AHK script as administrator - and it works for just about every other aspect of Windows.

My AHK version: 1.1.33.06

I attach a GIF where I recorded the problem.

Suggestion, fix or even workaround is welcome (it is a bit tricky to change MDI window without these double clicks).
Attachments
AhkDoubleClickTaskbarIssue.gif
AhkDoubleClickTaskbarIssue.gif (272 KiB) Viewed 1452 times

arnestein
Posts: 2
Joined: 16 Jan 2022, 07:40

Re: Keyboard generated double click and Win10 taskbar window switching

Post by arnestein » 16 Jan 2022, 08:08

When testing more now I find out that it also happens just when single clicking. And it doesn't only happen for the thumbs, it also happens when the title bars of the MDI are stacked on to of each other - and I try to click one of them.

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: Keyboard generated double click and Win10 taskbar window switching

Post by lexikos » 02 Oct 2022, 03:40

I cannot reproduce this (on Windows 11).

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Keyboard generated double click and Win10 taskbar window switching

Post by safetycar » 02 Oct 2022, 04:02

@arnestein The state of NumLock changes the name of the key. Check if by adding a line with Numpad0:: on top of NumpadIns:: you see what you wanted.

Tensai
Posts: 29
Joined: 12 Dec 2019, 14:15

Re: Keyboard generated double click and Win10 taskbar window switching

Post by Tensai » 02 Oct 2022, 08:31

Can confirm this happens in Windows 7 for both v1 and v2. Not sure if this is particularly an ahk bug or just OS design.
This is happening anytime MouseIsOver("ahk_class TaskListThumbnailWnd ahk_exe explorer.exe") or maybe even WinExist for that matter.

From my perspective:
The OS seems to be using a lower keyboard hook than ahk for Aero Peek.
Anytime a key is pressed it will cancel the hover preview, then pass the key through.
So in the case of NumpadIns::Click() the OS immediately cancels Peek, then ahk sends click.

Code: Select all

a:: ; A through Z
z:: ; All immediately cancel peek, then ahk takes over and returns.
{
	return
}
Seems there are a handful of keys Windows allows to be pressed during Peek:

Code: Select all

; These all work
Ctrl::
Shift::
PrintScreen::
LButton::
MButton::
RButton::
XButton1::
XButton2::
{
	Click()
}
Here is a workaround (Windows 7):

Code: Select all

#Requires AutoHotkey v2-
NumpadIns::Click
SetTimer(ActivateOnPeek,50)
ActivateOnPeek(){
	if(WinExist("ahk_class TaskListThumbnailWnd ahk_exe explorer.exe"))	; TaskListThumbnailWnd appears while peeking
		WinActivate("ahk_class Shell_TrayWnd ahk_exe explorer.exe")		; Activating the taskbar allows ahk to click before Peek vanishes
}

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Keyboard generated double click and Win10 taskbar window switching

Post by safetycar » 02 Oct 2022, 09:53

The fix for W7 makes weird things in W10.
In W10 which seems to be the case for the original poster based on the image, what I seem to see is that any normal key dismisses the thumbstrip. For example pressing "q" can make it go away, until you add "q::", after that the hotkey does the job of suppressing the original key and sending the click.
My previous comment about NumLock was because, If NumLock is On, then what is being sent is not NumpadIns but Numpad0. And ahk is not going to supress Numpad0 without being told, and Numpad0 will pass through and dismiss the thumbstrip.

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: Keyboard generated double click and Win10 taskbar window switching

Post by lexikos » 30 Nov 2022, 05:21

I do not know what changed, but I am able to reproduce this now.

It cannot be an AutoHotkey bug that an OS component is reacting to a key press before notifying AutoHotkey that the key was pressed.

Tensai wrote:The OS seems to be using a lower keyboard hook than ahk for Aero Peek.
Anytime a key is pressed it will cancel the hover preview, then pass the key through.
さすが天才 ;)

It is a good guess, but not quite right; it is likely not lower, just more recent. As far as I can tell, the thumbnail handler is registering a keyboard hook when it shows or moves the thumbnail. As the most recently registered hook is called first, the thumbnail is always notified of any keyboard event before any previously-registered hooks. It does not matter whether those other hooks return the "suppress this" value, because by then the thumbnail has already been hidden. It appears that sliding the mouse across the taskbar moves the existing window instead of creating a new one, but still refreshes the thumbnail's keyboard hook.

Attempts to work around this may be disruptive and unreliable. Basically you need AutoHotkey's hook to be unregistered and re-registered every time a thumbnail window is shown or moves. This can be done in script by temporarily suspending hotkeys, unless you have hotkeys or hotstrings which are exempt from suspension, or something else actively requiring the hook (such as Input/InputHook). This appeared to be sufficient:

Code: Select all

#Requires AutoHotkey v1.1

#Include <D>
; #Warn

Loop {
    WinWait ahk_class TaskListThumbnailWnd
    if !A_IsSuspended {
        Suspend On
        Suspend Off
    }
    WinGetPos oldx, oldy
    Loop {
        Sleep 20
        WinGetPos x, y
        if (x = "")
            break
        if (x != oldx || y != oldy)
            break
    }
}

NumpadIns::
+NumpadIns::
^NumpadIns::
^+NumpadIns::
{
  Click, Down
  keywait, NumpadIns
  Click, Up
}
Return
Alternatives include using a timer instead of a loop, or using other types of hooks to detect the thumbnail window (SetWinEventHook or perhaps RegisterShellHookWindow).

For v2, InstallKeybdHook(,true) can be used instead of suspending hotkeys, and will re-register the hook even if some hotkeys are exempt from suspension.

Even this workaround would be completely ineffective for registered hotkeys, because they do not use AutoHotkey's hook; the OS decides how to handle them.

aelius
Posts: 11
Joined: 14 Feb 2023, 15:58

Re: Keyboard generated double click and Win10 taskbar window switching

Post by aelius » 15 Feb 2023, 16:01

Hello - I've observed that the thumbnail is not dismissed by keystrokes when the taskbar is the active "window".

So a simple solution to this might be to set the taskbar as the active window whenever the mouse is hovering over the thumbnails.

I haven't tested this myself because I couldn't get it to work, so I am not 100% sure this approach will be free of quirks.

Here's what I attempted- let me know how to best approach this.

Thanks!

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance

;Windows Taskbar detects Alt before AHK can inhibit it
; Taskbar hides hover-thumbnails when alt is pressed
; see https://www.autohotkey.com/boards/viewtopic.php?f=14&t=98933
; WORKAROUND
; If taskbar is active, then alt does nothing
if MouseIsOver("ahk_class TaskListThumbnailWnd") {
  WinActivate "ahk_class Shell_TrayWnd"
}

MouseIsOver(WinTitle) {
  MouseGetPos ,, &Win
  return WinExist(WinTitle " ahk_id " Win)
}

Post Reply

Return to “Bug Reports”