DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Disable left mouse click on windows taskbar only at the most right icons  (Read 30,552 times)

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Hi all,

Does someone know a way of disabling the left mouse click but only on the windows taskbar and only for the most left icons like the clock, network and sound icons. Not for the windows start icon or a program window.

So only for this area:
clock.png

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Try this script

Code: (autohotkey)
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#IfWinActive ahk_class Shell_TrayWnd
$LButton::
return

To use it you need the free AutoHotkey tools from here:
https://autohotkey.com/

You can either run the script as is, or compile it to exe so that it will run on PCs without AHK installed.

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Hi MilesAhead,

This blocks all left mouse clicks, I would only like to disable it on the far left icons, in this screenshot I have marked the area in yellow that I would like to disable the lefts mouse click for.
LeftMouse.png

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
the far left icons
the far right icons, right...?
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Of course, I mean the area far right, it's marked yellow on the picture.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Hi MilesAhead,

This blocks all left mouse clicks, I would only like to disable it on the far left icons, in this screenshot I have marked the area in yellow that I would like to disable the lefts mouse click for.
[attachment 1 not found]

I should have known it would not be that easy.  :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
This one seems to prevent a double click.  But if an icon does something on a single click of the left mouse button it will still fire.

Code: (autohotkey)
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#IfWinActive ahk_class Shell_TrayWnd
$LButton::
MouseGetPos,X,Y,Win,Contr
If (Contr != "ToolBarWindow321")
	Send, {LButton}
return

Edit: If you are on Windows 10 the control name may be ToolBarWindow322.  You can use the Window Spy tool that comes with AutoHotkey to check the Class NN of the control.

I think ToolBarWindow321 is good for XP up to Windows 8.1.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Edit: If you are on Windows 10 the control name may be ToolBarWindow322.
Confirmed: ToolBarWindow322 when on Win10. :up:
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
I posted my script on the AHK "ask for help" forum.  Perhaps someone there can get it to block single clicks when the focus shifts from another window.  It seems the system reacts to the mouse click before the click changes the focus.

This is interesting to me because many of my tray utilities will show an about box if the icon is left clicked once.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
This will block the LMB in the SysTray.

HOWEVER, there may possibly be unforeseen consequences, ie. how do you propose to use any tray icon menu item if it appears within the SysTray area?

Screenshot - 6_07_2016 , 15_12_59.png

The Exit menu item for BTLMB falls within the area covered by the SysTray, since the LMB is blocked there is no way to choose the menu item and exit the program.

This is why it has a hotkey of Ctrl+Shift+Alt+f to exit it  ;)

Ideally you'd check to see what is under the mouse and process depending on what's there, (menu, etc), but since I'm lazy ... the source is there to get you started  :P

You could probably fudge it by subtracting the number of pixels covered by what you don't want affected, (which will be static because the size of the Clock, etc aren't dynamic).

Only tested on Win10Pro x64.

BTLMB.au3 - Block Tray LMB
Code: ( autoit)
#include "MouseOnEvent.au3" ; MouseOnEvent UDF

HotKeySet("^!+f", "_Exit") ; Ctrl + Shift + Alt + f
OnAutoItExitRegister("_Exit") ; Call the _Exit routine when the program is terminated somehow

; Set up tray icon menu/tooltip
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
TraySetToolTip(StringLeft(@ScriptName, StringLen(@ScriptName) - 4))
TrayCreateItem('Exit',-1,-1,0)
TrayItemSetOnEvent(-1,'_Exit')

; Display area

; Hook into Primary Mouse Button down event
_MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_PrimaryDown")

While Sleep(100)
;~ 	Twiddle twiddle
WEnd

Func _Exit()
	; Release the event hooks and Exit
	_MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
	OnAutoItExitUnRegister("_Exit")
	Exit
EndFunc

Func _PrimaryDown() ; PMB pressed
	Local $bBlock = False
	; Get taskbar size and position, it should be visible if we're clicking on it
	Local $aTaskbar_Pos = WinGetPos( "[Class:Shell_TrayWnd]")
	;~ $aTaskbar_Pos[0] = x
	;~ $aTaskbar_Pos[1] = y
	;~ $aTaskbar_Pos[2] = width
	;~ $aTaskbar_Pos[3] = height

	If IsArray($aTaskbar_Pos) Then ; Check if array is returned

		; Get location of Notification area but only interested in the width/height
		; X/Y position returned is incorrect if Taskbar is Bottom or Right
		Local $aTray_Pos = ControlGetPos(WinGetHandle("[CLASS:Shell_TrayWnd]"), "", "[CLASS:TrayNotifyWnd]")
		;~ $aTray_Pos[0] = x
		;~ $aTray_Pos[1] = y
		;~ $aTray_Pos[2] = width
		;~ $aTray_Pos[3] = height

		; Check if Taskbar is visible
		If ( $aTaskbar_Pos[0] > -3) And ( $aTaskbar_Pos[1] > -3) And ( $aTaskbar_Pos[0] < ( @DesktopWidth - 5)) And ( $aTaskbar_Pos[1] < ( @DesktopHeight - 5)) Then
			$aMouse_Pos = MouseGetPos() ; Get current mouse position
		;~ $aMouse_Pos[0] = x
		;~ $aMouse_Pos[1] = y
			Select
				Case $aTaskbar_Pos[2] = @DesktopWidth	; Taskbar at Top or Bottom
					If $aTaskbar_Pos[1] = 0 Then			; Top
						If ($aMouse_Pos[0] >= (@DesktopWidth - $aTray_Pos[2])) And ($aMouse_Pos[0] <= @DesktopWidth) Then
							If ($aMouse_Pos[1] >= 0) And ($aMouse_Pos[1] <= $aTray_Pos[3]) Then
								$bBlock = True
							EndIf
						EndIf
					Else ; Bottom
						If ($aMouse_Pos[0] >= (@DesktopWidth - $aTray_Pos[2])) And ($aMouse_Pos[0] <= @DesktopWidth) Then
							If ($aMouse_Pos[1] >= (@DesktopHeight - $aTray_Pos[3])) And ($aMouse_Pos[1] <= @DesktopHeight) Then
								$bBlock = True
							EndIf
						EndIf
					EndIf
				Case $aTaskbar_Pos[3] = @DesktopHeight	; Taskbar at Left or Right
					If $aTaskbar_Pos[0] = 0 Then			; Left
						If ($aMouse_Pos[0] <= $aTray_Pos[2]) And ($aMouse_Pos[0] >= 0) Then
							If ($aMouse_Pos[1] >= (@DesktopHeight - $aTray_Pos[3])) And ($aMouse_Pos[1] <= @DesktopHeight) Then
								$bBlock = True
							EndIf
						EndIf
					Else ; Right
						If ($aMouse_Pos[0] >= (@DesktopWidth - $aTray_Pos[2])) And ($aMouse_Pos[0] <= @DesktopWidth) Then
							If ($aMouse_Pos[1] >= @DesktopHeight - ($aTray_Pos[3])) And ($aMouse_Pos[1] <= @DesktopHeight) Then
								$bBlock = True
							EndIf
						EndIf
					EndIf
				Case Else
;~ 					ConsoleWrite("Mouse X: " & $aMouse_Pos[0] & "    Mouse Y: " & $aMouse_Pos[1] & @CRLF)
			EndSelect
		EndIf
	EndIf
	If $bBlock Then
;~ 		ConsoleWrite("SysTray click X: " & $aMouse_Pos[0] & "    Mouse Y: " & $aMouse_Pos[1] & @CRLF)
		Return 1 ; Block the default processing
	EndIf
EndFunc   ;==>_PrimaryDown

BTW, the reason I'm grabbing coords for the Taskbar and Tray on LMB click is because you can move the Taskbar around while the program is still running and it'll be happy.
The If...Then statements could probably be consolidated a bit better too, (did I mention I'm lazy?).

Might give someone an idea or two.

UPDATE:
  • Check if an array is returned for Taskbar position/size (Win 10 doesn't return array for second click on Start)
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: July 06, 2016, 10:59 AM by 4wd »

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Hello 4wd,

I tried your suggestion with the autoit stuff, it seems to work all fine but when I double click the windows start menu I get following error:

error.PNG

Any idea what could cause this ?

br
« Last Edit: July 06, 2016, 08:44 AM by -Huub- »

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
OK, I don't get that because I use ClassicShell to replace the Win10 Start Menu - I can see where it's happening, I'll have a look at it.

EDIT: Apparently the second click on the Start button doesn't result in an array being returned when the Taskbar position is fetched.  This should be easy to fix by just putting in a check and exiting the function if an array is not returned.

UPDATED
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: July 06, 2016, 10:43 AM by 4wd »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Removing the #IfWinActive and making the LButton global seems to have done the trick.  Try this out if you will.

Code: (autohotkey)
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

$LButton::
MouseGetPos,X,Y,Win,Contr
If (Contr != "ToolBarWindow321")
        Send, {LButton}
return

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Hi MilesAhead,

Thanks for your effort but this still doesn't work, I can still click on the systray clock icon with the left mouse button.
The script from 4wd worked only I got an error when I was double clicking the start menu button.
Is there a way of disabling the left mous click based on the mouse position x and Y area ?


br

Huub

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
The script from 4wd worked only I got an error when I was double clicking the start menu button.

It's been fixed.  :)
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Hello 4wd,

Yes you fixed it, cool! What part/line did you change ?


Br

Huub

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Hi MilesAhead,

Thanks for your effort but this still doesn't work, I can still click on the systray clock icon with the left mouse button.
The script from 4wd worked only I got an error when I was double clicking the start menu button.
Is there a way of disabling the left mous click based on the mouse position x and Y area ?


br

Huub

You simply need to use the Window Spy to get the name of the control/window under the mouse cursor and add to the If statement.  It will vary with version of Windows etc..

All I have now is Windows 8.0.  Also I only have a Laptop.  I cannot test other versions of Windows or multi-monitor stuff.
« Last Edit: July 06, 2016, 09:33 PM by MilesAhead »

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
What part/line did you change ?

Code: ( autoit)
 If IsArray($aTaskbar_Pos) Then ; Check if array is returned
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
You simply need to use the Window Spy to get the name of the control/window under the mouse cursor and add to the If statement.  It will vary with version of Windows etc..

Windows 10:
2016-07-07 13_07_56.png
2016-07-07 13_10_04.png
2016-07-07 13_10_22.png
2016-07-07 13_16_28.png

The control for the icon tray is determined by the particular Instance number, so I don't know if it's always going to be ToolbarWindow322 as shown in image 1, same with the control for the Input Method button in image 4, (and the button for Hidden icons if it exists).
Kind of why I went for area rather than a specific control.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: July 07, 2016, 03:19 AM by 4wd »

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Quote
If IsArray($aTaskbar_Pos) Then ; Check if array is returned

Thx 4wd!!!

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Hi MilesAhead,

Your suggestion worked partial, but it has a negative side effect if I use your code together with the window name under win 10, the LMB on the clock is blocked like I asked.

Code: ( autohotkey)
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
 
$LButton::
MouseGetPos,X,Y,Win,Contr
If (Contr != "TrayClockWClass1")
        Send, {LButton}
return

I can even use the LMB on the windows start menu. But the negative side effect is that the LMB also doesn't work anymore for all program windows, I could not move the open program windows on my screen.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Huub I guess it is not so simple.  I tried a bunch of things but if I free up the drag operation then left click in the off limits zone leaks through the first time.  Just like my first script.  If the au3 script is working I guess I would go with that.

I did not get any response when I posted on the ahk help forum. So I am out of ideas.

Original address: https://www.donationcoder.com/forum/index.php?topic=42800.0