topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 5:34 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
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
    • View Profile
    • Donate to Member
Try this script

Code: Autohotkey [Select]
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. #IfWinActive ahk_class Shell_TrayWnd
  6. $LButton::
  7. 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
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
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.pngDisable left mouse click on windows taskbar only at the most right icons

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
the far left icons
the far right icons, right...?

-Huub-

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

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
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.
[ Invalid Attachment ]

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


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
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 [Select]
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. #IfWinActive ahk_class Shell_TrayWnd
  6. $LButton::
  7. MouseGetPos,X,Y,Win,Contr
  8. If (Contr != "ToolBarWindow321")
  9.         Send, {LButton}
  10. 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,629
    • View Profile
    • Donate to Member
Edit: If you are on Windows 10 the control name may be ToolBarWindow322.
Confirmed: ToolBarWindow322 when on Win10. :up:

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
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.pngDisable left mouse click on windows taskbar only at the most right icons

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 [Select]
  1. #include "MouseOnEvent.au3" ; MouseOnEvent UDF
  2.  
  3. HotKeySet("^!+f", "_Exit") ; Ctrl + Shift + Alt + f
  4. OnAutoItExitRegister("_Exit") ; Call the _Exit routine when the program is terminated somehow
  5.  
  6. ; Set up tray icon menu/tooltip
  7. Opt("TrayMenuMode", 3)
  8. Opt("TrayOnEventMode", 1)
  9. TrayCreateItem('Exit',-1,-1,0)
  10. TrayItemSetOnEvent(-1,'_Exit')
  11.  
  12. ; Display area
  13.  
  14. ; Hook into Primary Mouse Button down event
  15. _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_PrimaryDown")
  16.  
  17. ;~      Twiddle twiddle
  18.  
  19. Func _Exit()
  20.         ; Release the event hooks and Exit
  21.         _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
  22.         OnAutoItExitUnRegister("_Exit")
  23.         Exit
  24.  
  25. Func _PrimaryDown() ; PMB pressed
  26.         Local $bBlock = False
  27.         ; Get taskbar size and position, it should be visible if we're clicking on it
  28.         Local $aTaskbar_Pos = WinGetPos( "[Class:Shell_TrayWnd]")
  29.         ;~ $aTaskbar_Pos[0] = x
  30.         ;~ $aTaskbar_Pos[1] = y
  31.         ;~ $aTaskbar_Pos[2] = width
  32.         ;~ $aTaskbar_Pos[3] = height
  33.  
  34.         If IsArray($aTaskbar_Pos) Then ; Check if array is returned
  35.  
  36.                 ; Get location of Notification area but only interested in the width/height
  37.                 ; X/Y position returned is incorrect if Taskbar is Bottom or Right
  38.                 Local $aTray_Pos = ControlGetPos(WinGetHandle("[CLASS:Shell_TrayWnd]"), "", "[CLASS:TrayNotifyWnd]")
  39.                 ;~ $aTray_Pos[0] = x
  40.                 ;~ $aTray_Pos[1] = y
  41.                 ;~ $aTray_Pos[2] = width
  42.                 ;~ $aTray_Pos[3] = height
  43.  
  44.                 ; Check if Taskbar is visible
  45.                 If ( $aTaskbar_Pos[0] > -3) And ( $aTaskbar_Pos[1] > -3) And ( $aTaskbar_Pos[0] < ( @DesktopWidth - 5)) And ( $aTaskbar_Pos[1] < ( @DesktopHeight - 5)) Then
  46.                         $aMouse_Pos = MouseGetPos() ; Get current mouse position
  47.                 ;~ $aMouse_Pos[0] = x
  48.                 ;~ $aMouse_Pos[1] = y
  49.                         Select
  50.                                 Case $aTaskbar_Pos[2] = @DesktopWidth   ; Taskbar at Top or Bottom
  51.                                         If $aTaskbar_Pos[1] = 0 Then                    ; Top
  52.                                                 If ($aMouse_Pos[0] >= (@DesktopWidth - $aTray_Pos[2])) And ($aMouse_Pos[0] <= @DesktopWidth) Then
  53.                                                         If ($aMouse_Pos[1] >= 0) And ($aMouse_Pos[1] <= $aTray_Pos[3]) Then
  54.                                                                 $bBlock = True
  55.                                                         EndIf
  56.                                                 EndIf
  57.                                         Else ; Bottom
  58.                                                 If ($aMouse_Pos[0] >= (@DesktopWidth - $aTray_Pos[2])) And ($aMouse_Pos[0] <= @DesktopWidth) Then
  59.                                                         If ($aMouse_Pos[1] >= (@DesktopHeight - $aTray_Pos[3])) And ($aMouse_Pos[1] <= @DesktopHeight) Then
  60.                                                                 $bBlock = True
  61.                                                         EndIf
  62.                                                 EndIf
  63.                                         EndIf
  64.                                 Case $aTaskbar_Pos[3] = @DesktopHeight  ; Taskbar at Left or Right
  65.                                         If $aTaskbar_Pos[0] = 0 Then                    ; Left
  66.                                                 If ($aMouse_Pos[0] <= $aTray_Pos[2]) And ($aMouse_Pos[0] >= 0) Then
  67.                                                         If ($aMouse_Pos[1] >= (@DesktopHeight - $aTray_Pos[3])) And ($aMouse_Pos[1] <= @DesktopHeight) Then
  68.                                                                 $bBlock = True
  69.                                                         EndIf
  70.                                                 EndIf
  71.                                         Else ; Right
  72.                                                 If ($aMouse_Pos[0] >= (@DesktopWidth - $aTray_Pos[2])) And ($aMouse_Pos[0] <= @DesktopWidth) Then
  73.                                                         If ($aMouse_Pos[1] >= @DesktopHeight - ($aTray_Pos[3])) And ($aMouse_Pos[1] <= @DesktopHeight) Then
  74.                                                                 $bBlock = True
  75.                                                         EndIf
  76.                                                 EndIf
  77.                                         EndIf
  78.                                 Case Else
  79. ;~                                      ConsoleWrite("Mouse X: " & $aMouse_Pos[0] & "    Mouse Y: " & $aMouse_Pos[1] & @CRLF)
  80.                         EndSelect
  81.                 EndIf
  82.         EndIf
  83.         If $bBlock Then
  84. ;~              ConsoleWrite("SysTray click X: " & $aMouse_Pos[0] & "    Mouse Y: " & $aMouse_Pos[1] & @CRLF)
  85.                 Return 1 ; Block the default processing
  86.         EndIf
  87. 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)
« Last Edit: July 06, 2016, 05:59 AM by 4wd »

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
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.PNGDisable left mouse click on windows taskbar only at the most right icons

Any idea what could cause this ?

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

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
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
« Last Edit: July 06, 2016, 05:43 AM by 4wd »

MilesAhead

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

Code: Autohotkey [Select]
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. $LButton::
  7. MouseGetPos,X,Y,Win,Contr
  8. If (Contr != "ToolBarWindow321")
  9.         Send, {LButton}
  10. return

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
The script from 4wd worked only I got an error when I was double clicking the start menu button.

It's been fixed.  :)

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Hello 4wd,

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


Br

Huub

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
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, 04:33 PM by MilesAhead, Reason: more typos »

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
What part/line did you change ?

Code: AutoIt [Select]
  1. If IsArray($aTaskbar_Pos) Then ; Check if array is returned

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
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.pngDisable left mouse click on windows taskbar only at the most right icons
2016-07-07 13_10_04.pngDisable left mouse click on windows taskbar only at the most right icons
2016-07-07 13_10_22.pngDisable left mouse click on windows taskbar only at the most right icons
2016-07-07 13_16_28.pngDisable left mouse click on windows taskbar only at the most right icons

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.
« Last Edit: July 06, 2016, 10:19 PM by 4wd »

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
If IsArray($aTaskbar_Pos) Then ; Check if array is returned

Thx 4wd!!!

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
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 [Select]
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. $LButton::
  7. MouseGetPos,X,Y,Win,Contr
  8. If (Contr != "TrayClockWClass1")
  9.         Send, {LButton}
  10. 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
    • View Profile
    • Donate to Member
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.