msd1994

how to stop sending "3" key with "ispressed"

5 posts in this topic

#1 ·  Posted

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!

Share this post


Link to post
Share on other sites



#3 ·  Posted

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!

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by genius257

Share this post


Link to post
Share on other sites

#5 ·  Posted

Got it working, with code below. This can be closed unless someone has a better suggestion

 

#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

 

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