Jump to content

[SOLVED] ClipGet() consumes 100% of CPU resources


k4rl3on
 Share

Recommended Posts

my script is a clipboard monitor, it checks clipboard content every second

That's the root cause of the issues. Why not register a custom viewer which is invoked every time the clipboard is updated and only then?

You should probably try using _WinAPI_AddClipboardFormatListener instead, or something along the same line.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Sorry for that. I'm still persuaded that there is the possibility to intercept an XP-compatible Windows message denoting that the clipboard got loaded. Unfortunately I curently don't have enough time to dig further.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

That's the root cause of the issues. Why not register a custom viewer which is invoked every time the clipboard is updated and only then?

You should probably try using _WinAPI_AddClipboardFormatListener instead, or something along the same line.

i test it one time (without calling the function avery second) and it causes the problem.

Link to comment
Share on other sites

Can you post such a reproducer? I'm curious to see a well-behaved message handling function eating a whole core.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

 

 

  • the large amount of data: i try to copy 3650 .png files with a size of: 16px = 3650*1.12 = 4088 / 1024 = 3,9 MB
  • type: i want just the list of those files names as ClipGet() returns it = Text
  • version of Windows: XP 500MB RAM.
  • AutoIt (Latest Stable Version) v3.3.14.2

Yes i use

Local $ClipBoardData = StringMid(ClipGet (), 1, 1024)

 

Thank you

jchd

Just call ClipGet() after copying 3650 files and you will constat it.

Link to comment
Share on other sites

Looks like memory shortage then. From where do you select those image files ? Is that in Explorer displaying thumbnails?

I can't test in this conficuration: I run W7 x64 with los of RAM, so the issue doesn't happen.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi,

i finally found a solution to the problem, here is a script:

Local $ClipBoardSec = 0
Local $owner = ""

While True
    $ClipBoardCurSec = _ClipBoard_GetSequenceNumber()
    ; Check if clipboard content changes
    If $ClipBoardSec <> $ClipBoardCurSec Then
        $ClipBoardSec = $ClipBoardCurSec
        $owner = _ClipBoard_GetOwner()
        ConsoleWrite("SequenceNumber: "&$ClipBoardSec&@CRLF)
        ;Clipboard contains Text
        If _ClipBoard_IsFormatAvailable(1) Then
            ConsoleWrite("Texte: "&ClipGet()&@CRLF)
        ;Clipboard contains Bitmap
        ElseIf _ClipBoard_IsFormatAvailable(2) Then
            ConsoleWrite("Image: "&@CRLF)
        ;Clipboard contains Files
        ElseIf _ClipBoard_IsFormatAvailable(15) Then
            ;List of selected files (copied)
            ConsoleWrite("Files: "&_ExplorerGetSelectedItems()&@CRLF)
        EndIf
        ConsoleWrite(" ******** "&@CRLF)
    EndIf
    Sleep(1000)
WEnd

Func _ExplorerGetSelectedItems($sCabinetWClass="[CLASS:CabinetWClass]")
    Local $Ret = ""
    Local $aIndexes, $sSelected, $sSelected_Path
    Local $hSearch, $sCurrentFile

    $sSelected_Path = ControlGetText($sCabinetWClass, "", "Edit1")
    ConsoleWrite($sSelected_Path&@CRLF)
    $aIndexes = StringSplit(ControlListView($sCabinetWClass, "", "SysListView321", "GetSelected", 1), "|")

    If $aIndexes[0] = 1 And ($aIndexes[1] == "" Or $aIndexes[1] = 0) Then Return SetError(1, 0, 0)

    For $i = 1 To $aIndexes[0]
        $sSelected = ControlListView($sCabinetWClass, "", "SysListView321", "GetText", $aIndexes[$i])
        $sCurrentFile = StringRegExpReplace($sSelected_Path, "\\+$", "") & "\" & $sSelected
        If Not FileExists($sCurrentFile) Then ;Search the extension for file...
            $hSearch = FileFindFirstFile($sCurrentFile & ".*")
            If $hSearch <> -1 Then
                $sSelected = FileFindNextFile($hSearch)
                FileClose($hSearch)
            EndIf
        EndIf

        If StringInStr(FileGetAttrib($sCurrentFile), "D") > 0 Then $sSelected = "*"&$sSelected
        $Ret = $Ret&$sSelected&Chr(10)
        Sleep(1)
    Next

    Return $Ret
EndFunc

; From Clipboard.au3
Func _ClipBoard_GetOwner()
    Local $aResult = DllCall("user32.dll", "hwnd", "GetClipboardOwner")
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc

Func _ClipBoard_GetOpenWindow()
    Local $aResult = DllCall("user32.dll", "hwnd", "GetOpenClipboardWindow")
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc

Func _ClipBoard_IsFormatAvailable($iFormat)
    Local $aResult = DllCall("user32.dll", "bool", "IsClipboardFormatAvailable", "uint", $iFormat)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc

Func _ClipBoard_GetSequenceNumber()
    Local $aResult = DllCall("user32.dll", "dword", "GetClipboardSequenceNumber")
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc

Still one issue: Function _ExplorerGetSelectedItems don't get selected items from Desktop it works only for folders in Explorer, how can i make it work for it?

Link to comment
Share on other sites

Thanks JohnOne

i found nothing about the function _ExplorerGetSelectedItemsFromDesktop.

but i found a way to retreive selected items both from Desktop and Explorer, i share it:

Func _SelectedItem($Window=WinGetHandle("[ACTIVE]", ""))
    Local $Ret = ""
    Local $aIndexes, $sSelected, $sSelected_Path
    Local $hSearch, $sCurrentFile
    ;Check if a Edit1 control exists on the active window
    $ÙŽAddressBar = ControlGetHandle($Window, "", "Edit1")
    ;it yes
    If $ÙŽAddressBar <> 0 Then
        ;Items in Folder openned on Explorer
        $sSelected_Path = ControlGetText($Window, "", "Edit1")
    Else
        ;Items on Desktop
        $sSelected_Path = @DesktopDir
    EndIf
    $Ret = $sSelected_Path&Chr(10)
    $aIndexes = StringSplit(ControlListView($Window, "FolderView", "SysListView321", "GetSelected", 1), "|")
    If $aIndexes[0] = 1 And ($aIndexes[1] == "" Or $aIndexes[1] = 0) Then Return SetError(1, 0, 0)
    For $i = 1 To $aIndexes[0]
        $sSelected = ControlListView($Window, "FolderView", "SysListView321", "GetText", $aIndexes[$i])
        $sCurrentFile = StringRegExpReplace($sSelected_Path, "\\+$", "") & "\" & $sSelected
        If Not FileExists($sCurrentFile) Then ;Search the extension for file...
            $hSearch = FileFindFirstFile($sCurrentFile & ".*")
            If $hSearch <> -1 Then
                $sSelected = FileFindNextFile($hSearch)
                FileClose($hSearch)
            EndIf
        EndIf

        If StringInStr(FileGetAttrib($sCurrentFile), "D") > 0 Then $sSelected = "*"&$sSelected
        $Ret = $Ret&$sSelected&Chr(10)
        Sleep(1)
    Next
    Return $Ret
EndFunc

And its solved :D

Edited by k4rl3on
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

×
×
  • Create New...