coolbk Posted July 21, 2011 Posted July 21, 2011 Hello, Got an easy script: when I press F1 and F2 it just does INSTANT mouse1 click in the coordinates and make mouse back in start position. The problem: It uses from 50 to 100% cpu usage constant. Only stops when I switch it off. Where's the problem? Also maybe there's chance to make this code easier and to make keybindings working only for certain application? Biggest thanks! Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) Global $Paused HotKeySet("{F3}", "Stop") Func Stop() Exit EndFunc while 1 If WinActive("[CLASS:SunAwtFrame]") Then HotKeySet("{F1}","turn") HotKeySet("{F2}","pass") #HotKeySet("{b}","turn") #HotKeySet("{n}","pass") Else EndIf WEnd func turn() If WinActive("[CLASS:SunAwtFrame]") Then $pos = MouseGetPos() MouseClick("left",590,280,1,0) MouseMove($pos[0], $pos[1], 0) EndIf EndFunc func pass() If WinActive("[CLASS:SunAwtFrame]") Then $pos2 = MouseGetPos() MouseClick("left",638,279,1,0) MouseMove($pos2[0], $pos2[1], 0) EndIf EndFunc
monoscout999 Posted July 21, 2011 Posted July 21, 2011 it uses a lot of CPU because 1. The While loop dont have any sleep on it. 2. You are setting the hotkeys again and again and again and forever, because you put it in a loop, That`s tottaly wrong you should set the hotkeys at the start of the script and never re setting the hoykey if you dont have a reason to do it. Try removing the HotKeySet() Functions from the main loop and add a little sleep inside( a sleep(do your own tests) will be enough).
coolbk Posted July 21, 2011 Author Posted July 21, 2011 Thanks, this one solved, and also question: How can I make to F3 pause the script fully? and then resume by pressing same hotkey
monoscout999 Posted July 21, 2011 Posted July 21, 2011 (edited) You will need to create a pause() function and a hotkey for that. something like this. HotKeySet("{F3}", "_Pause") Global $Pause = False ; This is necesary Global $i = 0 ; This is only for the example While True $i += 1 ConsoleWrite($i & @CRLF) ; ...or any function you have in the loop Sleep(500) WEnd Func _Pause() $Pause = Not $Pause ; If $Pasue = FALSE then TRUE, if $Pause = TRUE then FALSE While $Pause Sleep(800) WEnd EndFunc ;==>_Pause EDIT: About #HotKeySet("{b}","turn") ? I don`t have any idea of what is this... is not any directive so you should remove it. Edited July 21, 2011 by monoscout999
coolbk Posted July 22, 2011 Author Posted July 22, 2011 You will need to create a pause() function and a hotkey for that. something like this. HotKeySet("{F3}", "_Pause") Global $Pause = False ; This is necesary Global $i = 0 ; This is only for the example While True $i += 1 ConsoleWrite($i & @CRLF) ; ...or any function you have in the loop Sleep(500) WEnd Func _Pause() $Pause = Not $Pause ; If $Pasue = FALSE then TRUE, if $Pause = TRUE then FALSE While $Pause Sleep(800) WEnd EndFunc ;==>_Pause EDIT: About #HotKeySet("{b}","turn") ? I don`t have any idea of what is this... is not any directive so you should remove it. Hmm it doesn't work. Inserted it, but it doesn't even pause the script. I need to pause it totally to make hotkeys work as default.
monoscout999 Posted July 22, 2011 Posted July 22, 2011 My example works for me... :S Did you see the console stop writing?
AdmiralAlkex Posted July 22, 2011 Posted July 22, 2011 Hmm it doesn't work. Inserted it, but it doesn't even pause the script. I need to pause it totally to make hotkeys work as default.You don't want to pause it, you want to unset HotKeySet(). Just open helpfile and go to HotKeySet() it tells you exactly what to do. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
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