Jump to content

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


Recommended Posts

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

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

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
Link to comment
Share on other sites

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

 

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