Jump to content

disable Right Click


Recommended Posts

This will not disable, and is a basic thrown together script to stop the context menu in notepad. As you can see it is buggy as hell, so it may or may not work for you in your app, but may give you ideas:

#include<misc.au3>
While 1
    While WinActive("Untitled - Notepad")
        If _IsPressed("02") Then
            Sleep(100)
            ControlSend( "Untitled - Notepad", "", 15, "{esc}" )
        EndIf
        Sleep(10)
    Wend
    Sleep(10)
WEnd
Link to comment
Share on other sites

So, does anyone know how to do this?

or is this not posible?

Thanks

I've been messing with this all night lol

There is another GUIGetMSG() command that looks interesting:

$GUI_EVENT_SECONDARYDOWN the secondary mouse button was pressed. 
$GUI_EVENT_SECONDARYUP the secondary mouse button was released.

Those will effectively trap right clicks, however, not quite sure how to stop the context from coming up; may be able to just move the mouse cursor over a few ticks on the x,y plane and do a double click, which would effectively close the context menu. Or you can send an 'exit' to either one and it will close the window; or you can send an {esc} to the control, which if it's an autoit window will still close it; *sighs*, still havn't figured it out.

THERE HAS to be some sort of DLL call that happens when you press the secondary mouse button. If there is, and someone knows what it is, you may be able to call that dll and automatically close the context menu. I KNOW VBSCRIPT and Javascript have functions to disable the right click, just not sure how to translate those over to autoit haha.

Still pluggin away :)

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

So, does anyone know how to do this?

or is this not posible?

Thanks

Well, while trolling this forum for hours, searching the helpfile, and searching various VB and .NET sites, i was able to at least point you in this direction:

While it doesn't DISABLE the right click menu, it essentially clears the right click menu and puts 'Disabled' in it's place. Thus, whenever anyone right clicks on an contextual control, it will just show 'Disabled'. Secondly, the '5D' code there is for keyboards who have the 'menu' key on the right hand side, which will also just show 'Disabled'.

#include <GuiConstants.au3>
#Include <Misc.au3>
$Gui = GUICreate("Right Click Test", 400, 400)

;- ///// Credit an Edit and Input box to show contextual menus for //////
$edit = GUICtrlCreateEdit("Test Information", 0, 0, 400, 200)
$input = GUICtrlCreateInput("Test Input", 0, 220, 120, 25)

;- //// Create a dummy Context Menu ////////
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
;- //// Add the 'Disabled' item to the menu //////
    GUICtrlCreateMenuItem("Disabled", $ContextMenu)

;- //// Open the DLL responsible for keyclicks/controls/etc ////
$dll = DllOpen("user32.dll")

GUISetState()

While 1

    $Msg = GUIGetMsg()

;- //// If the right 'menu' context key is pressed then show the disabled context menu ////
    if _IsPressed("5D", $dll) Then
            Context($Gui, $ContextMenu)
    EndIf
    
    Select
        Case $Msg = $gui_event_close
            DllClose($dll)
            Exit

;- //// If the Right Mouse Button is clicked, show the disabled context menu ////
        Case $Msg = -9
            Context($Gui, $ContextMenu)

    EndSelect
WEnd

;- //// This is the context menu function to be able to show the menu ////
Func Context($hWnd, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)

;- /// Get current mouse position ////
    $arPos = MouseGetPos()

;- /// Break up mouse positions into variables ////
    Local $x = $arPos[0]
    Local $y = $arPos[1]

;- //// Call the dll file opened above to show the custom context menu at the current mouse position ////
    DllCall($dll, "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>ShowMenu

I'm tired haha. Putting multiple scripts together coupled with hours of searching really does take alot out of a guy. I hope this helps for your project. I'm not wholey to thank for this script, so don't fully thank me. You can thank me for putting it together, if you wish; but kudos also go to the various other autoit forum members who have worked similar projects before.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Hi,

you can edit this example to your needs.

#include <MouseSetOnEvent_UDF.au3>

_BlockMouseClicksInput(0)

ToolTip('MouseClicks is disabled')
Sleep(3000)

_BlockMouseClicksInput(1)

ToolTip('MouseClicks is enabled')
Sleep(3000)

Func _BlockMouseClicksInput($iOpt=0)
    If $iOpt = 0 Then
        _MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT, "__Dummy")
    Else
        _MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT)
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
        _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT)
        _MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT)
    EndIf
EndFunc   ;==>_BlockMouseClicksInput

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

you can edit this example to your needs.

#include <MouseSetOnEvent_UDF.au3>

_BlockMouseClicksInput(0)

ToolTip('MouseClicks is disabled')
Sleep(3000)

_BlockMouseClicksInput(1)

ToolTip('MouseClicks is enabled')
Sleep(3000)

Func _BlockMouseClicksInput($iOpt=0)
    If $iOpt = 0 Then
        _MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT, "__Dummy")
    Else
        _MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT)
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
        _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT)
        _MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT)
    EndIf
EndFunc   ;==>_BlockMouseClicksInput

Mega

Thanks for your relpy,

I tried to compile the script and I got an error

#include <mousesetonevent_UDF.au3> Error opening the file.

I do not know what that means, what should i do?

Thanks again

Link to comment
Share on other sites

Hi,

you can edit this example to your needs.

#include <MouseSetOnEvent_UDF.au3>

_BlockMouseClicksInput(0)

ToolTip('MouseClicks is disabled')
Sleep(3000)

_BlockMouseClicksInput(1)

ToolTip('MouseClicks is enabled')
Sleep(3000)

Func _BlockMouseClicksInput($iOpt=0)
    If $iOpt = 0 Then
        _MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT, "__Dummy")
        _MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT, "__Dummy")
    Else
        _MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT)
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
        _MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT)
        _MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT)
    EndIf
EndFunc   ;==>_BlockMouseClicksInput

Mega

Thanks for your relpy,

I tried to compile the script and I got an error

#include <mousesetonevent_UDF.au3> Error opening the file.

I do not know what that means, what should i do?

Thanks again

Link to comment
Share on other sites

Thanks for your relpy,

I tried to compile the script and I got an error

#include <mousesetonevent_UDF.au3> Error opening the file.

I do not know what that means, what should i do?

Thanks again

Download the mousesetonevent_UDF.au3 from this link http://www.autoitscript.com/forum/index.ph...st&id=19407, put it in the Include folder and compile your script again

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

Hello,

So thanks for all your help on this, now I have one more question

If i wanted to apply the not right click to a specific window only how would l do this. the name of the window could be "Notepad - survey"

Thanks

Link to comment
Share on other sites

Hi,

I guess you need to check whether that window is active and then start the blocking function.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hello, Thank for your script. I'm a newbie still and I can't seem to see how i can applu your code to another window. let's say I wanted to apply the no right click to the window "TPS REPORT" how would i do it. Thanks

Well, while trolling this forum for hours, searching the helpfile, and searching various VB and .NET sites, i was able to at least point you in this direction:

While it doesn't DISABLE the right click menu, it essentially clears the right click menu and puts 'Disabled' in it's place. Thus, whenever anyone right clicks on an contextual control, it will just show 'Disabled'. Secondly, the '5D' code there is for keyboards who have the 'menu' key on the right hand side, which will also just show 'Disabled'.

#include <GuiConstants.au3>
#Include <Misc.au3>
$Gui = GUICreate("Right Click Test", 400, 400)

;- ///// Credit an Edit and Input box to show contextual menus for //////
$edit = GUICtrlCreateEdit("Test Information", 0, 0, 400, 200)
$input = GUICtrlCreateInput("Test Input", 0, 220, 120, 25)

;- //// Create a dummy Context Menu ////////
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
;- //// Add the 'Disabled' item to the menu //////
    GUICtrlCreateMenuItem("Disabled", $ContextMenu)

;- //// Open the DLL responsible for keyclicks/controls/etc ////
$dll = DllOpen("user32.dll")

GUISetState()

While 1

    $Msg = GUIGetMsg()

;- //// If the right 'menu' context key is pressed then show the disabled context menu ////
    if _IsPressed("5D", $dll) Then
            Context($Gui, $ContextMenu)
    EndIf
    
    Select
        Case $Msg = $gui_event_close
            DllClose($dll)
            Exit

;- //// If the Right Mouse Button is clicked, show the disabled context menu ////
        Case $Msg = -9
            Context($Gui, $ContextMenu)

    EndSelect
WEnd

;- //// This is the context menu function to be able to show the menu ////
Func Context($hWnd, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)

;- /// Get current mouse position ////
    $arPos = MouseGetPos()

;- /// Break up mouse positions into variables ////
    Local $x = $arPos[0]
    Local $y = $arPos[1]

;- //// Call the dll file opened above to show the custom context menu at the current mouse position ////
    DllCall($dll, "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>ShowMenu

I'm tired haha. Putting multiple scripts together coupled with hours of searching really does take alot out of a guy. I hope this helps for your project. I'm not wholey to thank for this script, so don't fully thank me. You can thank me for putting it together, if you wish; but kudos also go to the various other autoit forum members who have worked similar projects before.

Link to comment
Share on other sites

I was messing around with this. The script you posted above won't work for what you want, since it only works for your own created GUI, afaik. If you want to disable the right mouse button in an external program, you have to set a hook to capture right mouse button events. The MouseSetOnEvent UDF unfortunately doesn't allow you to specify a target window, that I can see. So, I modified it to do this. (I don't know what the etiquette is for doing this kind of stuff on the forum, so I hope MsCreatoR doesn't get upset, since I think he's awesome. :-) )

So, I added a parameter to the _MouseSetOnEvent function for target window handle. The hook you set should only work on that target window you specify now.

The modified MouseSetOnEvent UDF:

#include-once

Global Const $WH_MOUSE_LL                   = 14

Global Const $MOUSE_MOVE_EVENT              = 512
Global Const $MOUSE_PRIMARYDOWN_EVENT       = 513
Global Const $MOUSE_PRIMARYUP_EVENT         = 514
Global Const $MOUSE_SECONDARYDOWN_EVENT     = 516
Global Const $MOUSE_SECONDARYUP_EVENT       = 517
Global Const $MOUSE_WHELLDOWN_EVENT         = 519
Global Const $MOUSE_WHELLUP_EVENT           = 520
Global Const $MOUSE_WHELLSCROLL_EVENT       = 522
Global Const $MOUSE_EXTRABUTTONDOWN_EVENT   = 523
Global Const $MOUSE_EXTRABUTTONUP_EVENT     = 524

Global $hKey_Proc                           = -1
Global $hM_Module                           = -1
Global $hM_Hook                             = -1
Global $aMouse_Events[1][1]
Global $hTarget                             = -1


Func OnAutoItExit()
    If IsArray($hM_Hook) And $hM_Hook[0] > 0 Then
        DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
        $hM_Hook[0] = 0
    EndIf
    
    If IsPtr($hKey_Proc) Then
        DllCallbackFree($hKey_Proc)
        $hKey_Proc = 0
    EndIf
EndFunc

Func _MouseSetOnEvent($iEvent, $sFuncName="", $sParam1="", $sParam2="", $hTargetWnd="")
    If $sFuncName = "" Then ;Unset Event
        If $aMouse_Events[0][0] < 1 Then Return 0
        Local $aTmp_Mouse_Events[1][1]
        
        For $i = 1 To $aMouse_Events[0][0]
            If $aMouse_Events[$i][0] <> $iEvent Then
                $aTmp_Mouse_Events[0][0] += 1
                ReDim $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]+1][4]
                $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][0] = $aMouse_Events[$i][0]
                $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][1] = $aMouse_Events[$i][1]
                $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][2] = $aMouse_Events[$i][2]
                $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][3] = $aMouse_Events[$i][3]
            EndIf
        Next
        
        $aMouse_Events = $aTmp_Mouse_Events
        
        If $aMouse_Events[0][0] < 1 Then OnAutoItExit()
        
        Return 1
    EndIf
    
    If $aMouse_Events[0][0] < 1 Then
        $hKey_Proc  = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
        $hM_Module  = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
        $hM_Hook    = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _
            "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)
    EndIf
    
    If IsHWnd($hTargetWnd) Then $hTarget = $hTargetWnd
    
    $aMouse_Events[0][0] += 1
    ReDim $aMouse_Events[$aMouse_Events[0][0]+1][4]
    $aMouse_Events[$aMouse_Events[0][0]][0] = $iEvent
    $aMouse_Events[$aMouse_Events[0][0]][1] = $sFuncName
    $aMouse_Events[$aMouse_Events[0][0]][2] = $sParam1
    $aMouse_Events[$aMouse_Events[0][0]][3] = $sParam2
EndFunc

Func _Mouse_Events_Handler($nCode, $wParam, $lParam)
    Local $iEvent = BitAND($wParam, 0xFFFF)
        
    If WinActive($hTarget) = 0 Then
        Return 0
    EndIf
    
    If $aMouse_Events[0][0] < 1 Then
        OnAutoItExit()
        Return 0
    EndIf
    
    For $i = 1 To $aMouse_Events[0][0]
        If $aMouse_Events[$i][0] = $iEvent Then
            Call($aMouse_Events[$i][1], $aMouse_Events[$i][2], $aMouse_Events[$i][3])
            If @error Then Call($aMouse_Events[$i][1], $aMouse_Events[$i][2])
            If @error Then Call($aMouse_Events[$i][1])
            
            Return 1 ;Block default processing
        EndIf
    Next
EndFuncoÝ÷ Øw«{l¶­zËlr¸©´¬yв¢×µÓXÊ°j{m¢ÚòÚ'6^¥§m¢Ç¶­Ü(®KºÚ"µÍÚ[ÛYH    ][ÝÓ[ÝÙTÙ]Û][ÕQ]LÉ][ÝÂ[   ][ÝÓÝY   ][ÝÊBÚ[ØZ]
    ][ÝÕ[]YHÝY   ][ÝÊBÓ[ÝÙTÙ]Û][
    ÌÍÓSÕTÑWÔÑPÓÓTQÕÓÑUS    ][ÝÓ[ÝÙTÙXÛÛUÑ][    ][ÝË  ][ÝÉ][ÝË    ][ÝÉ][ÝËÚ[Ù][J    ][ÝÕ[]YHÝY   ][ÝÊJBÛY
ML
HÈMHÙXÛÛÈÈ^HÝ[[XZÙHÝH]ÛÜÜËÓ[ÝÙTÙ]Û][
    ÌÍÓSÕTÑWÔÑPÓÓTQÕÓÑUS
HÑ[XH[ÝÙH]ÛXÚË[È[ÝÙTÙXÛÛUÑ][

BNÈ][Y[ÝHÛÌÎNÝÈ[][ÈK[ÝHYYH[Ý[ÛÈØ[ÜHÛÚË[[oÝ÷ Ù*¢¶°whÂØ­çS=$D
Link to comment
Share on other sites

So, I added a parameter to the _MouseSetOnEvent function for target window handle. The hook you set should only work on that target window you specify now.

The modified MouseSetOnEvent UDF:

Nice, i will add added this feature to my UDF if you don't mind, thanks :) Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...