Jump to content
Abdulla060

How can i block the mouse click input

Recommended Posts

Abdulla060
#include <Misc.au3>

Global $togglestate = False

HotKeySet("`", toggledestate)
While 1
    If _IsPressed("01") And $togglestate = True Then
        Send("{space}")
    Elseif _IsPressed("01") And $togglestate = False Then
        MouseClick("left")
    EndIf
    Sleep(200)
WEnd

Func toggledestate()
    $togglestate = Not $togglestate
EndFunc

i have this function that sends the space bar or a left mouse click depending the %togglestate variable how ever in both states the send another left click since i'm not blocking it in any way. i know i have to use a hook but i don't know how :(

Share this post


Link to post
Share on other sites
JLogan3o13

@Abdulla060 so your code is going to send either Spacebar or Mouseclick every 200 ms? And Send does not care what window it is targeting, so the code is very prone to causing issues. What exactly are you trying to accomplish, as I guarantee there is a better way to do it.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Abdulla060
7 hours ago, JLogan3o13 said:

@Abdulla060 so your code is going to send either Spacebar or Mouseclick every 200 ms? And Send does not care what window it is targeting, so the code is very prone to causing issues. What exactly are you trying to accomplish, as I guarantee there is a better way to do it.

No im trying to make the mouse button send either a left mouse click or a spacebar depending on the $togglestate variable the 200ms is just for the while loop

Share this post


Link to post
Share on other sites
Bilgus

ok So you are getting a left mouse click and you want to block it and send instead a space if togglestate is true

Conversely if togglestate is false you want to send a second left click making it a double left click am I getting that right?

NExt what is the reason you are trying to do this what is your end goal with this functionality?

Share this post


Link to post
Share on other sites
Bilgus

This is about a worthless script but without knowing your requirements it might be the ticket lol

#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>

Opt("GUIOnEventMode", 1)
Global $hGui = GUICreate("", 10, 10, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
Global $togglestate = False
Global $aPos ;

HotKeySet("{F1}", toggledestate)
GUISetOnEvent($GUI_EVENT_CLOSE, _Exit)
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, MouseMv)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, L_Click)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, R_Click)
HotKeySet("{ESC}", _Exit)

GUISetState(@SW_SHOW)
$aPos = MouseGetPos()
MouseMv()

While 1
    Sleep(200)
WEnd

Func MouseMv()
    $aPos = MouseGetPos()
    WinMove($hGui, "", $aPos[0] - 5, $aPos[1] - 5)
EndFunc   ;==>MouseMv

Func toggledestate()
    ConsoleWrite("Toggled" & @CRLF)
    $togglestate = Not $togglestate
EndFunc   ;==>toggledestate

Func L_Click()
    ConsoleWrite("LClick*" & @CRLF)
    GUISetState(@SW_HIDE)
    If $togglestate Then
        Send("{space}")
    Else
        MouseClick( $MOUSE_CLICK_PRIMARY, $aPos[0], $aPos[1], 2)
    EndIf
    GUISetState(@SW_SHOW)
EndFunc   ;==>L_Click

Func R_Click()
    ConsoleWrite("RClick*" & @CRLF)
    GUISetState(@SW_HIDE)
        MouseClick( $MOUSE_CLICK_SECONDARY, $aPos[0], $aPos[1], 2)
    GUISetState(@SW_SHOW)
EndFunc   ;==>L_Click

Func _Exit()
    Exit
EndFunc   ;==>_Exit

And its fun :P

Share this post


Link to post
Share on other sites
Abdulla060
40 minutes ago, Bilgus said:

ok So you are getting a left mouse click and you want to block it and send instead a space if togglestate is true

Conversely if togglestate is false you want to send a second left click making it a double left click am I getting that right?

NExt what is the reason you are trying to do this what is your end goal with this functionality?

If togglestate is false then just send a single click (not double click since im blocking the original click)

My end goal is to make left mouse click do two different ghings depending on the state of togglestate

So when you press the button either you are going to get a normal click as usual or you will get a space bar 

Im writing this script for a friend who has 6 of his fingers missing since birth and he is the who requested this script :)

Share this post


Link to post
Share on other sites
Abdulla060
5 minutes ago, Bilgus said:

This is about a worthless script but without knowing your requirements it might be the ticket lol

#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>

Opt("GUIOnEventMode", 1)
Global $hGui = GUICreate("", 10, 10, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
Global $togglestate = False
Global $aPos ;

HotKeySet("{F1}", toggledestate)
GUISetOnEvent($GUI_EVENT_CLOSE, _Exit)
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, MouseMv)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, L_Click)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, R_Click)
HotKeySet("{ESC}", _Exit)

GUISetState(@SW_SHOW)
$aPos = MouseGetPos()
MouseMv()

While 1
    Sleep(200)
WEnd

Func MouseMv()
    $aPos = MouseGetPos()
    WinMove($hGui, "", $aPos[0] - 5, $aPos[1] - 5)
EndFunc   ;==>MouseMv

Func toggledestate()
    ConsoleWrite("Toggled" & @CRLF)
    $togglestate = Not $togglestate
EndFunc   ;==>toggledestate

Func L_Click()
    ConsoleWrite("LClick*" & @CRLF)
    GUISetState(@SW_HIDE)
    If $togglestate Then
        Send("{space}")
    Else
        MouseClick( $MOUSE_CLICK_PRIMARY, $aPos[0], $aPos[1], 2)
    EndIf
    GUISetState(@SW_SHOW)
EndFunc   ;==>L_Click

Func R_Click()
    ConsoleWrite("RClick*" & @CRLF)
    GUISetState(@SW_HIDE)
        MouseClick( $MOUSE_CLICK_SECONDARY, $aPos[0], $aPos[1], 2)
    GUISetState(@SW_SHOW)
EndFunc   ;==>L_Click

Func _Exit()
    Exit
EndFunc   ;==>_Exit

And its fun :P

I'm at school now and going to try this script when i return home. I've also found This which might be the thing i am looking for

Edited by Abdulla060
Spelling mistakes

Share this post


Link to post
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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.