CPU-Auslastug updaten

  • Hallo,
    ich brauche mal wieder Hilfe bei einem Script:
    Mein Sript soll einige Informationen zur Maus anzeigen und gleichzeitig die CPU-Auslastung anzeigen. Leider klappt bei mir immer nur eine der Beiden Aufgaben. Ich hab es schon mit einem zweiten AdlibEnable versucht, aber es klapp einfach nicht ?( . Könnt ihr mir sagen, wo der Fehler ist?

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <ProgressConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $wbemFlagReturnImmediately = 0x10
    Global $wbemFlagForwardOnly = 0x20
    Global $colItems = ""
    Global $strComputer = "localhost"
    Global $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    Global $dpi = _GetLogPixels()
    Global $c = 0, $old = 0
    GUICreate("Mouse Meter", 300, 80, 852, 0, $WS_POPUPWINDOW, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
    $Label1 = GUICtrlCreateLabel('Die Maus hat bisher 0 Zentimeter zurückgelegt!', 0, 0, 300, 20)
    $Label2 = GUICtrlCreateLabel("X-Koordinate: - " & @LF & "Y-Koordinate: -", 0, 13, 300, 30)
    $Label3 = GUICtrlCreateLabel("Farbe der Koordinaten: -", 0, 40, 300, 30)
    $Label4 = GUICtrlCreateLabel("CPU-Auslastung: -", 0, 60, 300, 30)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLogPixels()
    Local $LogPixels
    Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2')
    Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DisplayConfiguration', 'WQL', 0x30)
    If IsObj($colItems) Then
    For $objItem In $colItems
    $LogPixels = $objItem.LogPixels
    Next
    Return $LogPixels
    EndIf
    Return SetError(1, 0, 0)
    EndFunc ;==>_GetLogPixels

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    AdlibEnable("MouseUpdate", 10)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    ProzessorUp()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func MouseUpdate()
    $pos = MouseGetPos()
    $x1 = $pos[0]
    $y1 = $pos[1]
    Sleep(10)
    $pos2 = MouseGetPos()
    $x2 = $pos2[0]
    $y2 = $pos2[1]
    $a = Sqrt(($x2 - $x1) ^ 2 + ($y2 - $y1) ^ 2)
    $b = Round($a, 0)
    $c = $c + $b
    If $c = $old Then Return
    $old = $c
    $cm = Round($c / $dpi * 2.54, 0)
    $p = Hex(PixelGetColor($pos2[0], $pos2[1]), 6)
    GUICtrlSetData($Label1, "Die Maus hat ungefähr " & $cm & " Zentimeter zurückgelegt!")
    GUICtrlSetData($Label2, "X-Koordinate: " & $pos2[0] & @LF & "Y-Koordinate: " & $pos2[1])
    GUICtrlSetData($Label3, "Farbe der Koordinaten: " & $p)
    EndFunc ;==>MouseUpdate

    [/autoit] [autoit][/autoit] [autoit]

    Func ProzessorUp()
    $colItems = $objWMIService.ExecQuery("SELECT LoadPercentage FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj($colItems) Then
    $i = 0
    For $objItem In $colItems
    If $i = 0 Then
    GUICtrlSetData($Label4, "CPU-Auslastung: " & $objItem.LoadPercentage & "%")
    EndIf
    Next
    EndIf
    EndFunc ;==>ProzessorUp

    [/autoit]

    Einmal editiert, zuletzt von xp_fan (28. November 2009 um 14:27)

  • Ich hab es schon mit einem zweiten AdlibEnable versucht, aber es klapp einfach nicht ?( . Könnt ihr mir sagen, wo der Fehler ist?

    Ohne dein Script anzuschauen kann ich dir sagen: benutz die Beta-Version. Da kannst du mit AdlibRegister mehrere Adlibs verwenden.

    EDIT: Und nachdem ich dein Skript angeschaut habe:

    Spoiler anzeigen
    [autoit]

    AdlibEnable("MouseUpdate", 50)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(500)
    ProzessorUp()
    WEnd

    [/autoit]


    und es funzt. 10ms war einfach zu arg bemessen.

    Edit: nein es funktioniert doch nicht. Ich war mal wider ein Dummbatzen

    • Offizieller Beitrag

    Hier mal ein Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <Timers.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $wbemFlagReturnImmediately = 0x10
    Global $wbemFlagForwardOnly = 0x20
    Global $colItems = ""
    Global $strComputer = "localhost"
    Global $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    Global $dpi = _GetLogPixels()
    Global $c = 0, $old = 0
    $GUI= GUICreate("Mouse Meter", 300, 80, 852, 0, $WS_POPUPWINDOW, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
    $Label1 = GUICtrlCreateLabel('Die Maus hat bisher 0 Zentimeter zurückgelegt!', 0, 0, 300, 20)
    $Label2 = GUICtrlCreateLabel("X-Koordinate: - " & @LF & "Y-Koordinate: -", 0, 13, 300, 30)
    $Label3 = GUICtrlCreateLabel("Farbe der Koordinaten: -", 0, 40, 300, 30)
    $Label4 = GUICtrlCreateLabel("CPU-Auslastung: -", 0, 60, 300, 30)
    GUISetState(@SW_SHOW)
    _Timer_SetTimer($GUI,2000,"ProzessorUp")
    Func _GetLogPixels()
    Local $LogPixels
    Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2')
    Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DisplayConfiguration', 'WQL', 0x30)
    If IsObj($colItems) Then
    For $objItem In $colItems
    $LogPixels = $objItem.LogPixels
    Next
    Return $LogPixels
    EndIf
    Return SetError(1, 0, 0)
    EndFunc ;==>_GetLogPixels

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    AdlibEnable("MouseUpdate", 100)

    [/autoit] [autoit][/autoit] [autoit]

    While 1

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func MouseUpdate()
    $pos = MouseGetPos()
    $x1 = $pos[0]
    $y1 = $pos[1]
    Sleep(10)
    $pos2 = MouseGetPos()
    $x2 = $pos2[0]
    $y2 = $pos2[1]
    $a = Sqrt(($x2 - $x1) ^ 2 + ($y2 - $y1) ^ 2)
    $b = Round($a, 0)
    $c = $c + $b
    If $c = $old Then Return
    $old = $c
    $cm = Round($c / $dpi * 2.54, 0)
    $p = Hex(PixelGetColor($pos2[0], $pos2[1]), 6)
    GUICtrlSetData($Label1, "Die Maus hat ungefähr " & $cm & " Zentimeter zurückgelegt!")
    GUICtrlSetData($Label2, "X-Koordinate: " & $pos2[0] & @LF & "Y-Koordinate: " & $pos2[1])
    GUICtrlSetData($Label3, "Farbe der Koordinaten: " & $p)
    EndFunc ;==>MouseUpdate

    [/autoit] [autoit][/autoit] [autoit]

    Func ProzessorUp($hWnd, $Msg, $iIDTimer, $dwTime)
    $Time = TimerInit()
    $colItems = $objWMIService.ExecQuery("SELECT LoadPercentage FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj($colItems) Then
    $i = 0
    For $objItem In $colItems
    If $i = 0 Then
    GUICtrlSetData($Label4, "CPU-Auslastung: " & $objItem.LoadPercentage & "%")
    EndIf
    Next
    EndIf
    ConsoleWrite(TimerDiff($Time)&@CRLF)
    EndFunc ;==>ProzessorUp

    [/autoit]

    Es funktionier zwar aber das Hauptproblem des ganzen ist, das die Func ProcessorUp zu lange braucht. Schau dir mal die Werte in der Console an. Wenn die Funtion 1 Sekunde braucht,
    dann wird die Adlibfunktion erst nach dieser Zeit ausgeführt. Habe den Timer jetzt auf 2 Sekunden :!: stehen, damit ausser der Prozessoranzeige überhaupt etwas funktioniert.

    Edit: Die Zentimeteranzeige funktioniert auch nicht richtig. Irgendwie stimmt deine Formel nicht.

    Edit2: SEuBo erhöhe mal die Sleep-Zeit in der Hautschleife auf über 1 Sekunde und den Delay der AdlibEnabel auf 100 dann sollte wenigstens irgendwas angezeigt werden.

    • Offizieller Beitrag

    Ja, weiß ich. Da es aber nicht mein Script ist, muß ich mir auch nicht umbeding ein Kopf darum machen. :thumbup:
    Das kann ja der Threadersteller machen. ;)