Jump to content

Recommended Posts

Posted (edited)

I want to do something while my Right Mouse Button is held down, but in the below code the console message only fires after the mouse button has been released (which defeats the purpose). Basically I'm wanting to temporarily change my mouse cursor when I'm holding down the mouse button. I have working code for changing the cursor (and their are also modifier keys being held as well, all of which works fine), but I can't get things to work for holding down the mouse button.

Any help/guidance is greatly appreciated! :)

 

; Include the Misc UDF which contains the _IsPressed function
#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")

While 1
    ; Check if the right mouse button is pressed (hex code '02')
    If _IsPressed("02", $hDLL) Then
        ; This code block is supposed to execute as long as the right button is held
        ConsoleWrite("Right mouse button is currently held down! (This only fires AFTER mouse button is RELEASED.)" & @CRLF)
            ; Wait for button to be released to prevent repeated firing (removing the below does not fix my problem)
            While _IsPressed("02", $hDLL)
                ConsoleWrite("Right mouse button is currently held down!!!!! (This also only fires AFTER mouse button is RELEASED -- it just fires a bunch of times at that point.)" & @CRLF)
                Sleep(10)
            WEnd
    EndIf
    ; Sleep for a short duration to prevent the script from using 100% CPU usage
    Sleep(10)
WEnd

 

Edited by ilikeautoit
  • Developers
Posted

Not sure I understand what it is you want to do other than what you coded, which is to stay in the inner loop while the mouse is pressed?
So do what you have to do in that inner loop... no?

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

Posted (edited)

Thanks much for the reply @Jos! Ideally, the first ConsoleWrite would fire while the mouse button is held down, but it doesn't fire until after it is released. And the same is true for the inner loop as well.

Basically, I want to do something when the mouse button is first held down, and then reverse that action whenever the mouse button is released. But with the above code nothing is executed until the mouse button is released. The above _IsPressed code works fine for when holding a key down (eg, a modifier key), but not for the mouse button for some reason.

Edited by ilikeautoit
  • Solution
Posted
47 minutes ago, ilikeautoit said:

but it doesn't fire until after it is released. And the same is true for the inner loop as well.

This is not what is happening with my computer (and a couple other ones).  So there must be a problem with your setup.  It works for me as expected.

Posted
13 minutes ago, Nine said:

This is not what is happening with my computer (and a couple other ones).  So there must be a problem with your setup.  It works for me as expected.

Ah, okay -- that is very helpful to know! I do have some other software that could possibly be interfering. I will investigate. I was so puzzled as to why the code was not working! 😆 Thanks much for testing and replying -- appreciate it!

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
×
×
  • Create New...