Jump to content

Mouse click only in specific area of the screen allowed


Go to solution Solved by ad777,

Recommended Posts

Hi,

based on this topic https://www.autoitscript.com/forum/topic/207507-mouse_primarydblclk_event-moved/

i would like to know how i create a function which gives me the possibility to specify a area on the screen where the mouse click will take an effect.

In my case coordinates for top left (980,168)  and bottom right (1700, 1270) are given - in this area the double mouse click script should work - in all other areas not.... 

Link to comment
Share on other sites

Hi @beamtenversteher,

if the suggestion of @Nine is what you're looking for (I am not fully sure), then please don't forget to release the mouse by _MouseTrap() before you end your script 😉 .


Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

@beamtenversteher

Disable DB Mouse Click event:

_MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent")
_MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent", $hGUI)

Enable DB Mouse Click event:

_MouseSetOnEvent($MOUSE_PRIMARYDBLCLK_EVENT)
_MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)

DIsable/Enable DB Mouse Click event:

While 1
    $Left = 980
    $Top = 168
    $Right = 1270
    $Bottom = 1700
    If MouseGetPos(0) > $Left And MouseGetPos(0) < $Right And MouseGetPos(1) > $Top And MouseGetPos(1) < $Bottom Then
        _MouseSetOnEvent($MOUSE_PRIMARYDBLCLK_EVENT)
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
    Else
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent")
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent", $hGUI)
    EndIf
WEnd

 

Edited by ad777

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

many thx!!!

if i understand u correctly it should looks like 

Quote
#include <GUIConstantsEx.au3>
#include "MouseOnEvent.au3"

HotKeySet("{ESC}", "_Quit")

_BlockDBClick()



Func _BlockDBClick()
   Local $hGUI = GUICreate("")
    GUISetState(@SW_HIDE, -1)
        _MouseSetOnEvent($MOUSE_PRIMARYDBLCLK_EVENT)
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)

While 1
    $Left = 400
    $Top = 220
    $Right = 1300
    $Bottom = 900
    If MouseGetPos(1) > $Left And MouseGetPos(1) < $Right And MouseGetPos(0) > $Top And MouseGetPos(0) < $Bottom Then
        _MouseSetOnEvent($MOUSE_PRIMARYDBLCLK_EVENT)
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
    Else
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent")
        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent", $hGUI)
    EndIf
WEnd

EndFunc   ;==>_BlockDBClick
Func _MouseDBEvent()
    Send("u") ;;send u
    ;;;;do stuff
    Return $MOE_BLOCKDEFPROC ;Block
EndFunc   ;==>_MouseDBEvent
Func _Quit()
    Exit
EndFunc   ;==>_Quit

 

that in between the coordinates the script works as expected and outside not doulbe click will be done/possible?

ive switches 0 to 1 and vice versa but the result is not that precise. sometimes the click outside the box (of the coordinates the send of the key still works.

Maybe a bit more save would be if in the area of the coordinates the script is running and out side like no script is working (what means that no key should be sent) 

r

Link to comment
Share on other sites

  • Solution

@beamtenversteher

you mean just like reverse(out side no send) like this:

#include <GUIConstantsEx.au3>
#include "MouseOnEvent.au3"
#include <Misc.au3>

HotKeySet("{ESC}", "_Quit")

_BlockDBClick()



Func _BlockDBClick()
    Global $hGUI = GUICreate("")
    GUISetState(@SW_HIDE, -1)
    _MouseSetOnEvent($MOUSE_PRIMARYDBLCLK_EVENT)
    _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)
    While 1
        $Left = 400
        $Top = 220
        $Right = 1300
        $Bottom = 900
        If MouseGetPos(0) > $Left And MouseGetPos(0) < $Right And MouseGetPos(1) > $Top And MouseGetPos(1) < $Bottom Then
            _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent")
            _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_MouseDBEvent", $hGUI)
        Else
            _MouseSetOnEvent($MOUSE_PRIMARYDBLCLK_EVENT)
            _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)

        EndIf
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
        ;Sleep(10)
    WEnd

EndFunc   ;==>_BlockDBClick
Func _MouseDBEvent()
    Send("u") ;;send Win+r
    ;;;;do stuff
    Return $MOE_BLOCKDEFPROC ;Block
EndFunc   ;==>_MouseDBEvent
Func _Quit()
    Exit
EndFunc   ;==>_Quit

 

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

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...