topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Friday March 29, 2024, 9:56 am
  • 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 right mouse button and enable only for specific program  (Read 11971 times)

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Hi, I was wondering if someone could help me with a AHK script that disables the right mouse button, but only enables it within a certain program that is running.
So if the program is active the user can only use the right mouse button within this specific program, trying the right mouse button on the taskbar, start menu button, desktop or even a other program other then mentioned is not allowed..

Thx in advanced!

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #1 on: November 03, 2014, 06:53 AM »
you can use GroupAdd and #IfWinActive to achieve what you want.

here's an example.
Code: Autohotkey [Select]
  1. GroupAdd, $NoRightClick, Foxit PDF Editor        
  2. GroupAdd, $NoRightClick, ahk_class Notepad
  3. GroupAdd, $NoRightClick, ahk_class IEFrame
  4.  
  5. #IfWinActive ahk_group $NoRightClick
  6. ;Disable right click
  7. RButton::Return

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #2 on: November 03, 2014, 08:00 AM »
Hi lanux128, Thx for your quick reply.
Your solution is not exactly what I was looking for. I want to disable the right mouse click for everything, it should only work if a specific program (prog32.exe) is active.
Your solution is only blocking the right mouse button for specified programs.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #3 on: November 03, 2014, 01:48 PM »
Does the prog32.exe have a corresponding window title?

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #4 on: November 04, 2014, 04:50 AM »
If I look it up with AHK, it is ahk_class ProMainWin

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #5 on: November 05, 2014, 08:13 AM »
Give this a try:

Code: Autohotkey [Select]
  1. #IfWinNotActive, ahk_class ProMainWin
  2. {
  3.     ; Disable right click
  4.     RButton::Return
  5. }

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #6 on: November 05, 2014, 08:52 AM »
Hi Skwire, this almost works! If the program window (ahk_class ProMainWin) is active and I go to the toolbar for instance, I can still rightclick.. If  the program window (ahk_class ProMainWin) isn't active it works great. Would it be possible to adjust the code so that it knows the size of the active  program window (ahk_class ProMainWin), so that it only works within the program ?
Or put some extra code in that will deactive the program window if the mouse leaves it ?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #7 on: November 05, 2014, 09:44 AM »
I think I follow you.  Try this instead:

Code: Autohotkey [Select]
  1. RButton::
  2. {
  3.     Click
  4.     WinGet, myProcess, ProcessName, A
  5.     If ( myProcess = "prog32.exe" )
  6.     {
  7.         Click, Right
  8.     }
  9. }
  10. Return

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #8 on: November 05, 2014, 10:14 AM »
Hi Skwire, alomst there, it worked the only thing I see is that when you sript is active and the mouse cursor is is not in the prog32.exe program, the right mouse button acts like a left mouse button.
So if I click with the right button on a shortcut, or Start button it does the same as if I use the left mouse button, could it than be inactive like RButton::return ?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #9 on: November 05, 2014, 10:30 AM »
Try this, please:

Code: Autohotkey [Select]
  1. RButton::
  2. {
  3.     MouseGetPos, , , myID,
  4.     WinGet, myProcess, ProcessName, ahk_id %myID%
  5.     If ( myProcess = "prog32.exe" )
  6.     {
  7.         Click, Right
  8.     }
  9. }
  10. Return

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #10 on: November 05, 2014, 10:34 AM »
Hi Skwire, this has done the trick! you rock!!!!
Thx!

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #11 on: November 05, 2014, 11:25 AM »
Hi Skwire, this has done the trick! you rock!!!!
Thx!

You're welcome.  I'm glad it's working for you.  =]

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Disable right mouse button and enable only for specific program
« Reply #12 on: November 05, 2014, 12:00 PM »
Always great to see threads like this -- except to the extent that skwire makes the rest of us coders look like slackers.. :-\