Jump to content

[SOLVED]Prolem with CPU usage


 Share

Recommended Posts

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

#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 by airrs
Link to comment
Share on other sites

  • Moderators

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
WEnd

If 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
WEnd

I reckon that should solve your problem - does it? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 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

  • Moderators

airrs,

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...