Abdulla060 Posted March 25, 2018 Posted March 25, 2018 #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
Moderators JLogan3o13 Posted March 26, 2018 Moderators Posted March 26, 2018 @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!
Abdulla060 Posted March 26, 2018 Author Posted March 26, 2018 On 3/26/2018 at 12:57 AM, 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. Expand 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
Bilgus Posted March 26, 2018 Posted March 26, 2018 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?
Bilgus Posted March 26, 2018 Posted March 26, 2018 This is about a worthless script but without knowing your requirements it might be the ticket lol expandcollapse popup#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
Abdulla060 Posted March 26, 2018 Author Posted March 26, 2018 On 3/26/2018 at 8:10 AM, 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? Expand 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
Abdulla060 Posted March 26, 2018 Author Posted March 26, 2018 (edited) On 3/26/2018 at 8:55 AM, Bilgus said: This is about a worthless script but without knowing your requirements it might be the ticket lol expandcollapse popup#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 Expand 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 March 26, 2018 by Abdulla060 Spelling mistakes
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now