Jump to content

Hold down left mouse, left clicks while down, then stop when releasing.


Recommended Posts

This is the first time I haven't been able to find some code to piece together what I want to accomplish, I know this is super simple.  Its for an legacy program that we use for a water plant, you have to left click several times to increase pressure.

How would I code left mouse down, left mouse clicks while mouse is down, then stops when mouse is brought back up?

Link to comment
Share on other sites

sorry but

in which legacy program you would have to click that often when it's not a game? :doh:also weird to start a mouseclick loop with a mouseclick no?

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

Not even sure it is possible to do it.  At the moment, I cannot think of a simple way to perform such a task.  Maybe someone else will bring a solution.  But my first impression is that you would need to use a secondary key.  For example, if you press Ctrl and left click, you could continue left clicking until the Ctrl key is released.

Link to comment
Share on other sites

Its a 30 year old program called "Pressure IT", was custom written for a water plant.  Small town, no money, working with what they have.  Operator has used this for 30 years and has arthritis now, I wanted to make something beyond simple. "Vern, now you just move the mouse pointer to the INC button hold the mouse button down, no more clicking it 50 times".

A secondary key would be ok, or maybe even a toggle so its on then off?  I do have a script with a toggle that works well.

Link to comment
Share on other sites

15 minutes ago, Tech2491 said:

I do have a script with a toggle that works well.

Post it using this tool.  Maybe we can enhance it ?  Tell Vern we are working on something :)

Edit : I know nothing about Water Plant, but isn't that a bit dangerous to have to key toggle to increase pressure ?  I mean, if you forget to put it off ?  I think it is preferable to hold a key instead.

Edited by Nine
Link to comment
Share on other sites

11 minutes ago, Nine said:

Post it using this tool.  Maybe we can enhance it ?  Tell Vern we are working on something :)

Could you please also provide a screenshot just to get an impression of the 'user interface' (blurr sensitive data).

Quote

  I know nothing about Water Plant, but isn't that a bit dangerous to have to key toggle to increase pressure ?  I mean, if you forget to put it off ?  I think it is preferable to hold a key instead. 

@Nine : Funny, I was just thinking the same thing :lol:.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

; Function to toggle the mouse button
; Hotkeys posted below in red, - on, = off
Func ToggleMouse()
   ; Variable to indicate whether the mouse is already down
    Global $Down
    If $Down Then
        MouseClick('Left')
    Else
        MouseDown('Left')
    EndIf
   ; Swap the value of the variable to reflect the new state
    $Down = Not $Down
EndFunc

; Function to end the script
Func Off()
    Exit
EndFunc

; Set the hotkeys up
HotkeySet('-', 'ToggleMouse')
HotkeySet('=', 'Off')

; Do nothing (keeps the script around to process the keys)
While 1
    Sleep(1000)
WEnd

I found this in my collection, I cant remember what I used it for, but was going to edit it.  I found it on the forums at some point I'm sure, I know enough to find something and then edit to make it do what I need, until now.

By toggle I meant, press F1 on your keyboard, now when you press the mouse button it repeats pushing the mouse button many times, you just hold it down and it continually clicks.  To turn the toggle off, you press F2, now when you press the mouse button its just a single click.  With this, I could also control how quickly the mouse button is pressed with a variable, to control how quickly the the button is pressed.

The plant is 2 hours away, when I go back I can get a SS.

Link to comment
Share on other sites

Here a bit different approach.  As I said, I believe it is more reliable to use a key to hold and release :

#include <Constants.au3>
#include <Misc.au3>
#include <GUIConstants.au3>
#include <WinAPISys.au3>

Opt ("GUIOnEventMode", 1)
Local $hGUI = GUICreate ("Test")
GUISetOnEvent ($GUI_EVENT_CLOSE, _Exit)
Local $idButton = GUICtrlCreateButton ("Click", 100, 100, 100, 30)
GUICtrlSetOnEvent (-1, _Click)
GUISetState ()

Local $bStart = False, $aPos, $tRect

While True
  While _IsPressed ("11") ; control key
    If _IsPressed ("01") And Not $bStart Then ; left mouse click
      $aPos = MouseGetPos ()
      $tRect = _WinAPI_GetWindowRect (GUICtrlGetHandle ($idButton))
      ; make sure it is the right contol to increase pressure
      ; don't know yet if it is possible to get its handle, but we will manage that later
      $bStart = $aPos[0] >= $tRect.left And $aPos[0] <= $tRect.right And $aPos[1] >= $tRect.top And $aPos[1] <= $tRect.bottom
    EndIf
    If $bStart Then
      ConsoleWrite ("click" & @CRLF)
      MouseClick ("left", $aPos[0], $aPos[1], 1, 1) ; make sure the click is always performed at the right coordinates
    EndIf
    Sleep (50)
  WEnd
  $bStart = False
  Sleep (100)
WEnd

Func _Exit ()
  Exit
EndFunc

Func _Click ()
  ConsoleWrite ("Button" & @CRLF)
EndFunc

The GUI is only there to ensure that the clicks are correctly performed...

Edited by Nine
corrected a small bug
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...