msd1994 Posted March 5, 2017 Share Posted March 5, 2017 Hello, I wrote a script to left click when I press or hold the 3 key, and right click when i press or hold the 4 key, except it still sends "3" or "4". Is there some way to suppress that input when this script is active, but still have the same behavior otherwise? This is my (simple) program. While 1 If _IsPressed ("33") Then MouseClick("left") Sleep(200) EndIf If _IsPressed ("34") Then MouseClick("right") Sleep(50) EndIf WEnd maximum speed when holding down the 3 key is approx. 5 clicks a second, which is a good speed. Any suggestions would be appreciated. Thanks! Link to comment Share on other sites More sharing options...
Developers Jos Posted March 5, 2017 Developers Share Posted March 5, 2017 Use HotKeySet() instead. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
msd1994 Posted March 7, 2017 Author Share Posted March 7, 2017 On 3/5/2017 at 4:21 AM, Jos said: Use HotKeySet() instead. Jos It behaves differently with HotKeySet(). I tried it originally, but if i held the "3" key down, it would instead constantly call the function, which would then continue left clicking even after I stop holding the key. Is there some way to prevent this? (limit a function to be called every ___ milliseconds?) Thanks! Link to comment Share on other sites More sharing options...
genius257 Posted March 8, 2017 Share Posted March 8, 2017 (edited) Hi @msd1994. Maybe _WinAPI_SetWindowsHookEx with $WH_KEYBOARD_LL (see the example in the function reference) is your answer. The key information is in the $tagKBDLLHOOKSTRUCT and if you return 1 in the hook procedure, you can prevent the key from doing anything else. Edited March 8, 2017 by genius257 My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser Link to comment Share on other sites More sharing options...
msd1994 Posted March 8, 2017 Author Share Posted March 8, 2017 Got it working, with code below. This can be closed unless someone has a better suggestion expandcollapse popup#include <Misc.au3> HotKeySet("!+{R}", "pauseFunc") HotKeySet("{3 down}", "myLeftclick") HotKeySet("{4 down}", "myRightclick") Opt("MouseClickDelay", 500) Global $hDll = DllOpen("user32.dll") Global $p = False Global $xCoord = @DesktopWidth While 1 Sleep(100) WEnd Func pauseFunc() $p = Not $p HotKeySet("{3 down}") HotKeySet("{4 down}") ToolTip("P", 0, 0) While $p Sleep(100) WEnd HotKeySet("{3 down}", "myLeftclick") HotKeySet("{4 down}", "myRightclick") ToolTip("") EndFunc Func myLeftclick() While _IsPressed ("33") MouseClick("left") WEnd EndFunc Func myRightclick() While _IsPressed ("34") MouseClick("right") WEnd EndFunc Link to comment Share on other sites More sharing options...
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