airrs Posted August 3, 2012 Share Posted August 3, 2012 (edited) Hi there i made a script for checking if i copied something with ctrl+c. then a window pops up with a selection of some websites. you choose one and then search starts on the chosen site with the copied string. no problems until here. but if the programm runs the cpu usage grows up to 50%, a bit too much for such a tiny programm. i guess the problem lays within the while loop in the _check() function. i hope someone can figure it out and maybe help me here the file i included for checking if the buttons are pressed ( is there another/better way?) IsPressedEx_UDF.au3 here my source expandcollapse popup#include <FF.au3> #include <IsPressedEx_UDF.au3> Local $hDLL = DllOpen("user32.dll") Global $ram = "" Global $page[10][2] HotKeySet("{ESC}","_Quit") $page[0][0] = "http://www.google.de/" $page[0][1] = "gbqfq" $page[1][0] = "http://wikipedia.de/" $page[1][1] = "txtSearch" $page[2][0] = "www.youtube.com/" $page[2][1] = "masthead-search-term" $page[3][0] = "www.imdb.com" $page[3][1] = "navbar-query" _start() Func _start() $startWin = GUICreate("Start",115,70,-1,-1,0x80880000) GUICtrlCreateLabel("HELLO" & @CRLF & " - Welcome to copyBOX",5,5) $btn = GUICtrlCreateButton("START",65,40,-1,-1,0x0001) GUISetState(@SW_SHOW,$startWin) WHile 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $btn GUISetState(@SW_HIDE,$startWin) GUIDelete($StartWin) _check() Case $msg[0] = -3 ;$GUI_EVENT_CLOSE ExitLoop EndSelect WEnd EndFunc Func _check() Local $pCh = "" While 1 $press = _IsPressedEx("{CTRL}+C", $hDll) If $press = 1 Then $ram = ClipGet() $mPos = MouseGetPos() $choose = GUICreate("choose",200,160,$mPos[0],$mPos[1],0x80880000) $rb1 = GUICtrlCreateRadio("google",40,50) GUICtrlSetState($rb1, 1) ;$GUI_CHECKED $rb2 = GUICtrlCreateRadio("wiki",40,75) $rb3 = GUICtrlCreateRadio("youTube",40,100) $rb4 = GUICtrlCreateRadio("IMDb",40,125) $btn = GUICtrlCreateButton("go",65,20,-1,-1,0x0001) $btn2 = GUICtrlCreateButton("don't",95,20,-1,-1) GUISetState(@SW_SHOW, $choose) While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $btn If GUICtrlRead($rb1) = 1 Then $pCh = 0 GUISetState(@SW_HIDE, $choose) GUIDelete($choose) _openParse($pCh,$ram) ElseIf GUICtrlRead($rb2) = 1 Then $pCh = 1 GUISetState(@SW_HIDE, $choose) GUIDelete($choose) _openParse($pCh,$ram) ElseIf GUICtrlRead($rb3) = 1 Then $pCh = 2 GUISetState(@SW_HIDE, $choose) GUIDelete($choose) _openParse($pCh,$ram) ElseIf GUICtrlRead($rb4) = 1 Then $pCh = 3 GUISetState(@SW_HIDE, $choose) GUIDelete($choose) _openParse($pCh,$ram) EndIf Case $msg[0] = $btn2 GUISetState(@SW_HIDE, $choose) ExitLoop Case $msg[0] = -3;$GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Endif WEnd EndFunc Func _openParse($p,$r) If ProcessExists("firefox.exe") = 0 Then run("C:\Program Files\Mozilla Firefox\firefox.exe") EndIf _FFConnect() _FFTabAdd($page[$p][0],true,true) _FFAction("max") _FFSetValue($r,$page[$p][1],"id") _FFFormsubmit() _check() EndFunc Func _Quit() DllClose($hDll) Exit EndFunc greets airrs Edited August 29, 2012 by airrs Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 3, 2012 Moderators Share Posted August 3, 2012 airrs,Your guess is almost certainly correct. Look at the structure of your loop:While 1 $press = _IsPressedEx("{CTRL}+C", $hDLL) If $press = 1 Then ; [code] While 1 $msg = GUIGetMsg(1) ; [code] WEnd EndIf WEndIf the key is pressed then you end up in the inner loop with a GUIGetMsg and its built-in pause to keep the CPU happy. But f the key is not pressed, you immediately reloop giving the CPU no break at all. I would add a Sleep in there if teh key is not pressed like this:While 1 $press = _IsPressedEx("{CTRL}+C", $hDLL) If $press = 1 Then ; [code] While 1 $msg = GUIGetMsg(1) ; [code] WEnd Else Sleep(10) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf WEndI reckon that should solve your problem - does it? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
November Posted August 3, 2012 Share Posted August 3, 2012 (edited) I reckon that should solve your problem - does it? M23 Its does... lol from 25% to 1% in my Intel Core i3-2330M @2.20 Ghz You were just a bit more fast than I Cheers Func _check() Local $pCh = "" While 1 $press = _IsPressedEx("{CTRL}+C", $hDll) sleep(50) ... Edited August 3, 2012 by November Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font] Link to comment Share on other sites More sharing options...
airrs Posted August 3, 2012 Author Share Posted August 3, 2012 thanks a lot. now my pc is silent again @November don't be sad. next time you're faster November 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 3, 2012 Moderators Share Posted August 3, 2012 airrs, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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