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 right mouse button and enable only for specific program  (Read 17,836 times)

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
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
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: Disable right mouse button and enable only for specific program
« Reply #1 on: November 03, 2014, 12:53 PM »
you can use GroupAdd and #IfWinActive to achieve what you want.

here's an example.
Code: (autohotkey)
GroupAdd, $NoRightClick, Foxit PDF Editor        
GroupAdd, $NoRightClick, ahk_class Notepad 
GroupAdd, $NoRightClick, ahk_class IEFrame

#IfWinActive ahk_group $NoRightClick
;Disable right click
RButton::Return
#IfWinActive

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Re: Disable right mouse button and enable only for specific program
« Reply #2 on: November 03, 2014, 02:00 PM »
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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Disable right mouse button and enable only for specific program
« Reply #3 on: November 03, 2014, 07:48 PM »
Does the prog32.exe have a corresponding window title?

-Huub-

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

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Disable right mouse button and enable only for specific program
« Reply #5 on: November 05, 2014, 02:13 PM »
Give this a try:

Code: (autohotkey)
#IfWinNotActive, ahk_class ProMainWin
{
    ; Disable right click
    RButton::Return
}
#IfWinNotActive

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Re: Disable right mouse button and enable only for specific program
« Reply #6 on: November 05, 2014, 02:52 PM »
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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Disable right mouse button and enable only for specific program
« Reply #7 on: November 05, 2014, 03:44 PM »
I think I follow you.  Try this instead:

Code: (autohotkey)
RButton::
{
    Click
    WinGet, myProcess, ProcessName, A
    If ( myProcess = "prog32.exe" )
    {
        Click, Right
    }
}
Return

-Huub-

  • Supporting Member
  • Joined in 2014
  • **
  • Posts: 18
Re: Disable right mouse button and enable only for specific program
« Reply #8 on: November 05, 2014, 04:14 PM »
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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Disable right mouse button and enable only for specific program
« Reply #9 on: November 05, 2014, 04:30 PM »
Try this, please:

Code: (autohotkey)
RButton::
{
    MouseGetPos, , , myID,
    WinGet, myProcess, ProcessName, ahk_id %myID%
    If ( myProcess = "prog32.exe" )
    {
        Click, Right
    }
}
Return

-Huub-

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

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Disable right mouse button and enable only for specific program
« Reply #11 on: November 05, 2014, 05:25 PM »
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,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Disable right mouse button and enable only for specific program
« Reply #12 on: November 05, 2014, 06:00 PM »
Always great to see threads like this -- except to the extent that skwire makes the rest of us coders look like slackers.. :-\

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