Jump to content

How can i block the mouse click input


Recommended Posts

#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 :(

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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