trust Posted November 9, 2023 Share Posted November 9, 2023 Hello, i try to find script: when i press RMB > RMB hold down, if press RMB one more time > RMB unhold i find some similar script (when press RMB > hold N button/ press again > N unhold) but when i run this, script use 50% cpu, looks like something wrong in code can anyone help create new or fix old code please ? expandcollapse popup#include <Misc.au3> $status = 0 Local $hDLL = DllOpen("user32.dll") Func status () if _IsPressed("02",$hDLL) = true then $status = $status-1 do _IsPressed("02",$hDLL) until _IsPressed("02",$hDLL) = false $status = $status+2 If $status = 3 Then $status = 1 EndIf EndIf EndFunc while 1 status () if $status = 1 Then ;ConsoleWrite("_IsPressed - Click_1." & @CRLF) ;Для отладки Send("{n down}") Do status () until $status = 2 ElseIf $status = 2 Then ;ConsoleWrite("_IsPressed - Click_2." & @CRLF) ;Для отладки Send("{n up}") Do status () until $status = 1 EndIf sleep(30) WEnd DllClose($hDLL) Link to comment Share on other sites More sharing options...
Developers Jos Posted November 9, 2023 Developers Share Posted November 9, 2023 RMB? There is a close loop in your code without any Sleep() so high CPU is expected. 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...
trust Posted November 9, 2023 Author Share Posted November 9, 2023 5 minutes ago, Jos said: RMB? Yep, right mouse button 6 minutes ago, Jos said: There is a close loop in your code without any Sleep() so high CPU is expected. Im totally 0 in code, so i dont know where need sleep xd Link to comment Share on other sites More sharing options...
Solution Andreik Posted November 9, 2023 Solution Share Posted November 9, 2023 Using some pauses as Jos suggested would fix your CPU usage. expandcollapse popup#include <Misc.au3> $status = 0 Local $hDLL = DllOpen("user32.dll") Func status () if _IsPressed("02",$hDLL) = true then $status -= 1 Do _IsPressed("02",$hDLL) Sleep(10) until Not _IsPressed("02", $hDLL) $status += 2 If $status = 3 Then $status = 1 EndIf EndFunc While True status () if $status = 1 Then ;ConsoleWrite("_IsPressed - Click_1." & @CRLF) ;Для отладки Send("{n down}") Do status () Sleep(10) until $status = 2 ElseIf $status = 2 Then ;ConsoleWrite("_IsPressed - Click_2." & @CRLF) ;Для отладки Send("{n up}") Do status() Sleep(10) until $status = 1 EndIf sleep(30) WEnd DllClose($hDLL) trust 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
trust Posted November 9, 2023 Author Share Posted November 9, 2023 49 minutes ago, Andreik said: Using some pauses as Jos suggested would fix your CPU usage. expandcollapse popup#include <Misc.au3> $status = 0 Local $hDLL = DllOpen("user32.dll") Func status () if _IsPressed("02",$hDLL) = true then $status -= 1 Do _IsPressed("02",$hDLL) Sleep(10) until Not _IsPressed("02", $hDLL) $status += 2 If $status = 3 Then $status = 1 EndIf EndFunc While True status () if $status = 1 Then ;ConsoleWrite("_IsPressed - Click_1." & @CRLF) ;Для отладки Send("{n down}") Do status () Sleep(10) until $status = 2 ElseIf $status = 2 Then ;ConsoleWrite("_IsPressed - Click_2." & @CRLF) ;Для отладки Send("{n up}") Do status() Sleep(10) until $status = 1 EndIf sleep(30) WEnd DllClose($hDLL) working perfect, thank you so much 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