MarkLeung Posted January 1, 2022 Share Posted January 1, 2022 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 More sharing options...
ad777 Posted January 1, 2022 Share Posted January 1, 2022 (edited) #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 January 1, 2022 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 More sharing options...
Developers Jos Posted January 1, 2022 Developers Share Posted January 1, 2022 @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 More sharing options...
ad777 Posted January 1, 2022 Share Posted January 1, 2022 (edited) Jos oh i did fix the code Edited January 1, 2022 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 More sharing options...
Developers Jos Posted January 1, 2022 Developers Share Posted January 1, 2022 (edited) 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... The script will be constantly sending Mouse UP&DOWNs when you keep the F1 pressed.... is that wanted? 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 January 1, 2022 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 More sharing options...
MarkLeung Posted January 2, 2022 Author Share Posted January 2, 2022 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... The script will be constantly sending Mouse UP&DOWNs when you keep the F1 pressed.... is that wanted? 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 More sharing options...
Developers Jos Posted January 2, 2022 Developers Share Posted January 2, 2022 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 More sharing options...
MarkLeung Posted January 2, 2022 Author Share Posted January 2, 2022 8 minutes ago, Jos said: Did you try? Hehe, just did. If I press F1 again it doesn't mouseup. Instead it resets the cycle. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 2, 2022 Developers Share Posted January 2, 2022 (edited) 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 January 2, 2022 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 More sharing options...
Nine Posted January 2, 2022 Share Posted January 2, 2022 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
junkew Posted January 4, 2022 Share Posted January 4, 2022 Windows has this dragging with keys build in with mousekeys. Maybe that helps also https://www.computerhope.com/issues/ch000542.htm https://support.microsoft.com/en-us/windows/use-mouse-keys-to-move-the-mouse-pointer-9e0c72c8-b882-7918-8e7b-391fd62adf33 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Deye Posted January 4, 2022 Share Posted January 4, 2022 (edited) * 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: expandcollapse popup#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 January 4, 2022 by Deye Link to comment Share on other sites More sharing options...
Deye Posted January 4, 2022 Share Posted January 4, 2022 (edited) No edit button for me ? edit : ok got it .. a little rusty .. Edited January 4, 2022 by Deye Link to comment Share on other sites More sharing options...
Luke94 Posted January 5, 2022 Share Posted January 5, 2022 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now