Jump to content

Simple mouse down and up script


Recommended Posts

Hello. I'm trying to write a script that changes F1 to left click down, and then release when F1 is pressed again. This is what I have, and it doesn't work.

Dim $MouseDown

Func LMouseDown()
   $MouseDown = 0
If $MouseDown = 0 Then
   MouseDown("left")
   $MouseDown = 1
Else
   MouseUp("left")
   $MouseDown = 0
   EndIf
EndFunc

Any help is appreciated!

Link to comment
Share on other sites

#include <Misc.au3>
Dim $MouseDown
Local $hDLL = DllOpen("user32.dll")
While 1
   LMouseDown()
   Sleep(100)
   WEnd
Func LMouseDown()
if _IsPressed("70",$hDLL) Then;;;if F1 key press
  if  $MouseDown = 1 Then
   MouseUp("left")
   $MouseDown = 0
     EndIf
   Sleep(100);;Sleep 100 for break it
EndIf
if _IsPressed("70",$hDLL) Then
     if  $MouseDown = 0 Then
  MouseDown("left")
   $MouseDown = 1
     EndIf
   Sleep(100);;Sleep 100 for  break it
EndIf
EndFunc

 

Edited by ad777

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

  • Developers

@ad777, You forgot again to Tidy your code ;) 

... but more importantly, this is not a very efficient script opening the DLL constantly...  so not a script I would recommend to use as is.  

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

  • Developers

That code is still messy,...  so why aren't you simply using Tidy.exe from SciTE (Ctrl+T) when you have the full version installed? 

Secondly:  I think the script is still flawed in several ways...  

  1. The script will be constantly sending Mouse UP&DOWNs when you keep the F1 pressed.... is that wanted?
  2. The F1 is still send as normal F1 to the system as well ....  is that what is wanted?

This is how I would do it when 2 is still desired:

#include <Misc.au3>
Global $MouseDown = False
Global $hDLL = DllOpen("user32.dll")
While 1
    LMouseDown()
    Sleep(10)
WEnd
Func LMouseDown()
    ; F1 key press
    If _IsPressed("70", $hDLL) Then
        MouseDown("left")
        ConsoleWrite("+ Mouse down." & @CRLF)
        While _IsPressed("70", $hDLL)
            sleep(10)
        WEnd
        MouseUp("left")
        ConsoleWrite("+ Mouse Up." & @CRLF)
    EndIf
EndFunc   ;==>LMouseDown

@MarkLeung, Why do you want to change the behavior of the F1 like this anyways? 

 

 

Edited by 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

15 hours ago, Jos said:

That code is still messy,...  so why aren't you simply using Tidy.exe from SciTE (Ctrl+T) when you have the full version installed? 

Secondly:  I think the script is still flawed in several ways...  

  1. The script will be constantly sending Mouse UP&DOWNs when you keep the F1 pressed.... is that wanted?
  2. The F1 is still send as normal F1 to the system as well ....  is that what is wanted?

This is how I would do it when 2 is still desired:

#include <Misc.au3>
Global $MouseDown = False
Global $hDLL = DllOpen("user32.dll")
While 1
    LMouseDown()
    Sleep(10)
WEnd
Func LMouseDown()
    ; F1 key press
    If _IsPressed("70", $hDLL) Then
        MouseDown("left")
        ConsoleWrite("+ Mouse down." & @CRLF)
        While _IsPressed("70", $hDLL)
            sleep(10)
        WEnd
        MouseUp("left")
        ConsoleWrite("+ Mouse Up." & @CRLF)
    EndIf
EndFunc   ;==>LMouseDown

@MarkLeung, Why do you want to change the behavior of the F1 like this anyways? 

 

 

Because I've recently become disabled and can't click very well with the mouse. I need a way to perform drag and drop accurately because my work demands it.

I want to replace F1 entirely as I rarely use it. Regarding the dlls, can you guarantee that I have them?

Thanks so much.

Link to comment
Share on other sites

  • Developers
12 minutes ago, MarkLeung said:

Regarding the dlls, can you guarantee that I have them?

Did you try? ;) 

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

  • Developers

Run the Script from SciTE and tell me what you see in the OutputPane when you do this....  (but as stated before ....the F1 will be performed as well.)

EDIT: You could also check out the Helpfile for HotkeySet() and look at the example as that is pretty close to what you want too!
 

Edited by 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

If I was a teacher (like good old time), I would give a 10% to @ad777 in his homework for not understanding the basic principle of indentation.  But gladly I am not, and I am pretty sure he would still not understand the principle.

Link to comment
Share on other sites

* Click to select the start of the drag and a second click to finish it. 
* Double click to select and highlight a word .etc

  Here's a way to start you off:

#include <Misc.au3>
Global $hDLL = DllOpen("user32.dll")

HotKeySet("{F1} ", "HotKeyPressed")
HotKeySet("{ESC}", "Close") ; Set ESC as a hotkey to exit the script.

While 1
    Sleep(100)
WEnd

Func __dragStartStop()
    While _IsPressed("70", $hDLL)
        Sleep(10)
    WEnd
    If _IsPressed("01", $hDLL) Then
        MouseUp("left")
    Else
        MouseDown("left")
    EndIf
EndFunc   ;==>__IsPressed

Func HotKeyPressed()
    Local Static $hTimer = "881808965525"
    Local $fDiff = TimerDiff($hTimer)
    If Int($fDiff) > 200 Then
        __dragStartStop()
        $hTimer = TimerInit()
        Return
    EndIf
    ;double click determined
    $hTimer = TimerInit()
    MouseClick("left", Default, Default, 1)
EndFunc   ;==>HotKeyPressed

Func Close()
    MouseUp("left")
    Exit
EndFunc   ;==>Close

 

Edited by Deye
Link to comment
Share on other sites

Global $g_bMouseDown = False

HotKeySet('{ESC}', '_Exit')
HotKeySet('{F1}', '_ToggleMouseDown')

While 1
    If $g_bMouseDown Then
        MouseDown('Left')
        While $g_bMouseDown
            Sleep(10)
        WEnd
        MouseUp('Left')
    EndIf
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc

Func _ToggleMouseDown()
    $g_bMouseDown = Not $g_bMouseDown
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...