xcxooxl Posted September 3, 2007 Share Posted September 3, 2007 (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 September 3, 2007 by xcxooxl Link to comment Share on other sites More sharing options...
Generator Posted September 3, 2007 Share Posted September 3, 2007 Add Sleep(1) in your while loop Link to comment Share on other sites More sharing options...
Nahuel Posted September 3, 2007 Share Posted September 3, 2007 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 Link to comment Share on other sites More sharing options...
Bert Posted September 3, 2007 Share Posted September 3, 2007 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 The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Generator Posted September 3, 2007 Share Posted September 3, 2007 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 EndFuncInteresting...Something new for me Link to comment Share on other sites More sharing options...
Nahuel Posted September 3, 2007 Share Posted September 3, 2007 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... Link to comment Share on other sites More sharing options...
Bert Posted September 3, 2007 Share Posted September 3, 2007 why do you need to know that? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Nahuel Posted September 3, 2007 Share Posted September 3, 2007 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? 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