xcxooxl Posted September 3, 2007 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
Nahuel Posted September 3, 2007 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
Bert Posted September 3, 2007 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/
Generator Posted September 3, 2007 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
Nahuel Posted September 3, 2007 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...
Bert Posted September 3, 2007 Posted September 3, 2007 why do you need to know that? The Vollatran project My blog: http://www.vollysinterestingshit.com/
Nahuel Posted September 3, 2007 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?
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