Sign in to follow this  
Followers 0
xcxooxl

100% cpu?

8 posts in this topic

#1 ·  Posted (edited)

i made a short script to quick close of a game im playing

this is the code

but when im running it, it takes most of the cpu

why is that ?

while 1
If ProcessExists("game.exe")Then
    HotKeySet("q", "quit")
EndIF
wend

Func quit()
    ProcessClose ( "game.exe" )
EndFunc
Edited by xcxooxl

Share this post


Link to post
Share on other sites



Add Sleep(1) in your while loop

Share this post


Link to post
Share on other sites

That's because of the loop. If it has to check if that process exist every loop, it'll take the CPU to 100%. You fix that by adding a Sleep.

while 1
Sleep(100)
If ProcessExists("game.exe")Then
    HotKeySet("q", "quit")
EndIF
wend

Func quit2()
    ProcessClose ( "game.exe" )
EndFunc

Share this post


Link to post
Share on other sites

There is a better way to do this.

HotKeySet("{F2}", "HotKeyFunc")
HotKeySet("{ESC}", "HotKeyFunc")

While 1
    Sleep(60000)
    ; Script part
WEnd

Func HotKeyFunc()
    If WinActive("") Then; Set the window
        Switch @HotKeyPressed
            Case "{F2}"
                ;;;
            Case "{ESC}"
                Exit
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

There is a better way to do this.

HotKeySet("{F2}", "HotKeyFunc")
HotKeySet("{ESC}", "HotKeyFunc")

While 1
    Sleep(60000)
    ; Script part
WEnd

Func HotKeyFunc()
    If WinActive("") Then; Set the window
        Switch @HotKeyPressed
            Case "{F2}"
                ;;;
            Case "{ESC}"
                Exit
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
EndFunc
Interesting...Something new for me

Share this post


Link to post
Share on other sites

There is a better way to do this.

HotKeySet("{F2}", "HotKeyFunc")
HotKeySet("{ESC}", "HotKeyFunc")

While 1
    Sleep(60000)
    ; Script part
WEnd

Func HotKeyFunc()
    If WinActive("") Then; Set the window
        Switch @HotKeyPressed
            Case "{F2}"
                ;;;
            Case "{ESC}"
                Exit
        EndSwitch
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "HotKeyFunc")
    EndIf
EndFunc
Hey, that is very interesting... I still can't figure out how to detect if the user has pressed any key though...

Share this post


Link to post
Share on other sites

Well, I was trying to make a very simple text editor. The thing is that I wanted the 'save' button to be disabled when you just open the editor. But it would be enabled once you type something in.

Now that I think about it, I suppose there are other ways, haha. But how bout a screensaver?

Share this post


Link to post
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
Sign in to follow this  
Followers 0