k4rl3on Posted January 12, 2016 Posted January 12, 2016 (edited) hello I have problem with ClipGet () function: If the clipboard contains a large amount of data the use of the function pushes the consumption of cpu resources to 100% and my script unresponds until I force it to end. I tried to work around the problem by limiting the size of the recovered data from the clipboard Local = $ClipBoardData = StringMid(ClipGet (), 1.1024) I also used: DllCall ("psapi.dll", "int", "EmptyWorkingSet", "long", -1) to free the memory after each call to ClipGet () Edited January 16, 2016 by k4rl3on
water Posted January 12, 2016 Posted January 12, 2016 Welcome to Autoit and the forum!A few questions:How large is "a large amount of data"? How many MB?What type of data? Text, picture ...?Which version of Windows do you run?Which version of AutoIt do you run?Local = $ClipBoardData = StringMid(ClipGet (), 1.1024)won't work as it has some syntax errors. I think it should beLocal $ClipBoardData = StringMid(ClipGet (), 1, 1024)to grab the first 1024 bytes of the data from the clipboard. But this will not solve your performance problems as it first retrieves ALL data from the clipboard before StringMid is being executed. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
k4rl3on Posted January 12, 2016 Author Posted January 12, 2016 (edited) the large amount of data: i try to copy 3650 .png files with a size of: 16px = 3650*1.12 = 4088 / 1024 = 3,9 MBtype: i want just the list of those files names as ClipGet() returns it = Textversion of Windows: XP 500MB RAM.AutoIt (Latest Stable Version) v3.3.14.2Yes i useLocal $ClipBoardData = StringMid(ClipGet (), 1, 1024) Thank you Edited January 12, 2016 by k4rl3on
water Posted January 12, 2016 Posted January 12, 2016 How do you fill the clipboard? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted January 12, 2016 Posted January 12, 2016 Do I understand you correctly that you just want the names of the selected files, not the files itself?If this is true then this little script shows how to grab the list of selected files from Windows Explorer: My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
k4rl3on Posted January 12, 2016 Author Posted January 12, 2016 Thank you for your help, But what i need is to get the content of the clipboard, however if its a simple copied text or a list of files names, my problem like is presented above: ClipGet() do correctly that until there is big data in the clipboard, ClipGet() consumes 100% of CPU resources. what i need is an alternative to ClipGet() that dont crash my script when there is big data in the clipboard.
BrewManNH Posted January 12, 2016 Posted January 12, 2016 You might want to try using _Clipboard_GetData with the text format to see if it's any faster or lighter on your CPU. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
k4rl3on Posted January 13, 2016 Author Posted January 13, 2016 thank you but still slower on my cpu and when i use $CF_HDROP returns the handle to the files list how can i with this handle get the files names?
JohnOne Posted January 13, 2016 Posted January 13, 2016 What cpu? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
EmilyLove Posted January 13, 2016 Posted January 13, 2016 Is it necessary to store data in the clipboard? What are you trying to use the data you copy into clipboard in and how will it interact with the program?
k4rl3on Posted January 13, 2016 Author Posted January 13, 2016 my script is a clipboard monitor, it checks clipboard content every second and store it into a log file.
jguinch Posted January 13, 2016 Posted January 13, 2016 It's a bad idea to read the clipboard content so often. Use _ClipBoard_SetViewer instead (look at the help page). Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
JohnOne Posted January 13, 2016 Posted January 13, 2016 Why not post it?Part of finding a problem is letting other people try it.So many times I've seen threads like these go on for weeks, then the op says "oops sorry I had spilled iron brew on my laptop and broke it" Bert 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
EmilyLove Posted January 13, 2016 Posted January 13, 2016 Seeing your source and what you have already tried would help us figure out the issue.
k4rl3on Posted January 13, 2016 Author Posted January 13, 2016 (edited) Hi,Following the suggestion from jguinch about Using _ClipBoard_SetViewer instead of ClipGet()Here is what i done:expandcollapse popup#include <Clipboard.au3> #include <GUIConstantsEx.au3> #include <SendMessage.au3> #include <WindowsConstants.au3> Global $g_idMemo, $g_hNext = 0 Example() Func Example() Local $hGUI ; Create GUI $hGUI = GUICreate("Clipboard", 400, 100) ;~ $hGUI = WinGetHandle(WinGetTitle("")) ;~ $g_idMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL) ;~ GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) ; Initialize clipboard viewer $g_hNext = _ClipBoard_SetViewer($hGUI) GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN") GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD") MemoWrite("GUI handle ....: " & $hGUI) MemoWrite("Viewer handle .: " & _ClipBoard_GetViewer()) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Shut down clipboard viewer _ClipBoard_ChangeChain($hGUI, $g_hNext) EndFunc ;==>Example ; Write message to memo Func MemoWrite($sMessage = "") ConsoleWrite($sMessage & @CRLF) EndFunc ;==>MemoWrite ; Handle $WM_CHANGECBCHAIN messages Func WM_CHANGECBCHAIN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; Show that message was received MemoWrite("***** $WM_CHANGECBCHAIN *****") ; If the next window is closing, repair the chain If $wParam = $g_hNext Then $g_hNext = $lParam ; Otherwise pass the message to the next viewer ElseIf $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_CHANGECBCHAIN, $wParam, $lParam, 0, "hwnd", "hwnd") EndIf EndFunc ;==>WM_CHANGECBCHAIN ; Handle $WM_DRAWCLIPBOARD messages Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; Display any text on clipboard ;Check clipboard Content type If _ClipBoardContentType() = 4 Then ; If files copied: $Content = _ClipBoard_GetData($CF_HDROP) Else $Content = _ClipBoard_GetData() EndIf FileWrite("ClipBoardLog.txt",_TimeStamp()&" - "&$Content&@CRLF) ; Pass the message to the next viewer If $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_DRAWCLIPBOARD, $wParam, $lParam) EndFunc ;==>WM_DRAWCLIPBOARD Func _ClipBoardContentType() DllCall("User32.dll", "int", "OpenClipboard", "hwnd", "") $ret = DllCall("User32.dll", "int", "EnumClipboardFormats", "int", 49158) DllCall("User32.dll", "int", "CloseClipboard") If $ret[0] = 49159 Then Return 4 Else Return 3 EndIf EndFunc Func _TimeStamp() Local $Ret $Ret = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0) If Not @error Then Return $Ret[0] Else Return "" EndIf EndFuncthe code based on the example of _ClipBoard_SetViewer with litte modification to check the clipboard content's type, and log it into a .txt file, and its work without any problem concerning CPU ressources consumption.but still two problems to resolve:In case of files in clipboard _ClipBoard_GetData($CF_HDROP) returns binary data like: 0x14000000000000000000000000000000010000004.... how can i get file name from it?how can i run this without creating a new GUI: doing something like :$hGUI = WinGetHandle(WinGetTitle(""))and thank you again Edited January 13, 2016 by k4rl3on
BrewManNH Posted January 13, 2016 Posted January 13, 2016 (edited) In case of files in clipboard _ClipBoard_GetData($CF_HDROP) returns binary data like: 0x14000000000000000000000000000000010000004.... how can i get file name from it?Everything you might want to know about this can be found here.https://msdn.microsoft.com/en-us/library/windows/desktop/bb776902(v=vs.85).aspx#CF_HDROP Edited January 13, 2016 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
k4rl3on Posted January 13, 2016 Author Posted January 13, 2016 (edited) thank you BrewManNH for the link.here is what i tried to do:from the documention of DragQueryFile i created a function:Func WM_DROPFILES_FUNC($Content) Local $nSize, $pFileName Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", 0xFFFFFFFF, "ptr", 0, "int", 255) ConsoleWrite("["&$nAmt[0]&"]"&@CRLF) For $i = 0 To $nAmt[0] - 1 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", $i, "ptr", 0, "int", 0) $nSize = $nSize[0] + 1 $pFileName = DllStructCreate("char[" & $nSize & "]") DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize) ReDim $gaDropFiles[$i + 1] $gaDropFiles[$i] = DllStructGetData($pFileName, 1) MemoWrite($gaDropFiles[$i]) ;If StringInStr(FileGetAttrib($gaDropFiles[$i]), "D") Then $gaDropFiles[$i] = $gaDropFiles[$i] & "\*.*" $pFileName = 0 Next EndFunci gave it the return of _ClipBoard_GetData($CF_HDROP) as parameter as explained in te docuentation of DragQueryFile function:hDrop [in]Type: HDROPIdentifier of the structure that contains the file names of the dropped files.is this the expected value?DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)which must return the number of file in clipboard, returns -1 when i'm copying a file the complete code:expandcollapse popup#include <Clipboard.au3> #include <GUIConstantsEx.au3> #include <SendMessage.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $gaDropFiles[1] Global $g_idMemo, $g_hNext = 0 Example() Func Example() Local $hGUI ; Create GUI $hGUI = GUICreate("Clipboard", 400, 100) ;~ $hGUI = WinGetHandle(WinGetTitle("")) ;~ $g_idMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL) ;~ GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) ; Initialize clipboard viewer $g_hNext = _ClipBoard_SetViewer($hGUI) GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN") GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD") ;~ GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC") MemoWrite("GUI handle ....: " & $hGUI) MemoWrite("Viewer handle .: " & _ClipBoard_GetViewer()) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Shut down clipboard viewer _ClipBoard_ChangeChain($hGUI, $g_hNext) EndFunc ;==>Example ; Write message to memo Func MemoWrite($sMessage = "") ConsoleWrite($sMessage & @CRLF) EndFunc ;==>MemoWrite ; Handle $WM_CHANGECBCHAIN messages Func WM_CHANGECBCHAIN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; Show that message was received MemoWrite("***** $WM_CHANGECBCHAIN *****") ; If the next window is closing, repair the chain If $wParam = $g_hNext Then $g_hNext = $lParam ; Otherwise pass the message to the next viewer ElseIf $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_CHANGECBCHAIN, $wParam, $lParam, 0, "hwnd", "hwnd") EndIf EndFunc ;==>WM_CHANGECBCHAIN ; Handle $WM_DRAWCLIPBOARD messages Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; Display any text on clipboard If _ClipBoardContentType() = 4 Then $Bin = _ClipBoard_GetData($CF_HDROP) WM_DROPFILES_FUNC($Bin) Else $Content = _ClipBoard_GetData() EndIf FileWrite("ClipBoardLog.txt",_TimeStamp()&" - "&$Content&@CRLF) ; Pass the message to the next viewer If $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_DRAWCLIPBOARD, $wParam, $lParam) EndFunc ;==>WM_DRAWCLIPBOARD Func WM_DROPFILES_FUNC($Content) Local $nSize, $pFileName Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", 0xFFFFFFFF, "ptr", 0, "int", 255) ConsoleWrite("["&$nAmt[0]&"]"&@CRLF) For $i = 0 To $nAmt[0] - 1 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", $i, "ptr", 0, "int", 0) $nSize = $nSize[0] + 1 $pFileName = DllStructCreate("char[" & $nSize & "]") DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize) ReDim $gaDropFiles[$i + 1] $gaDropFiles[$i] = DllStructGetData($pFileName, 1) MemoWrite($gaDropFiles[$i]) ;If StringInStr(FileGetAttrib($gaDropFiles[$i]), "D") Then $gaDropFiles[$i] = $gaDropFiles[$i] & "\*.*" $pFileName = 0 Next EndFunc Func _ClipBoardContentType() DllCall("User32.dll", "int", "OpenClipboard", "hwnd", "") $ret = DllCall("User32.dll", "int", "EnumClipboardFormats", "int", 49158) DllCall("User32.dll", "int", "CloseClipboard") If $ret[0] = 49159 Then Return 4 Else Return 3 EndIf EndFunc Func _TimeStamp() Local $Ret $Ret = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0) If Not @error Then Return $Ret[0] Else Return "" EndIf EndFunc Edited January 13, 2016 by k4rl3on
BrewManNH Posted January 13, 2016 Posted January 13, 2016 Is there something you need the list of files for or is this just something you thought you'd try and get working? If you just need a list of files in a folder, there are easier ways of going about this. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
k4rl3on Posted January 13, 2016 Author Posted January 13, 2016 (edited) my script is a clipboard monitor, it checks clipboard content every second and store it into a log file.i tried with $hdrop = _ClipBoard_GetDataEx($CF_HDROP)which returns a handle of the object in the clipboard callFunc WM_DROPFILES_FUNC($Content) Local $nSize, $pFileName Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", 0xFFFFFFFF, "ptr", 0, "int", 255) ConsoleWrite("["&$nAmt[0]&"]"&@CRLF) For $i = 0 To $nAmt[0] - 1 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", $i, "ptr", 0, "int", 0) $nSize = $nSize[0] + 1 $pFileName = DllStructCreate("char[" & $nSize & "]") DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $Content, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize) ReDim $gaDropFiles[$i + 1] $gaDropFiles[$i] = DllStructGetData($pFileName, 1) MemoWrite($gaDropFiles[$i]) ;If StringInStr(FileGetAttrib($gaDropFiles[$i]), "D") Then $gaDropFiles[$i] = $gaDropFiles[$i] & "\*.*" $pFileName = 0 Next EndFuncwith it as parameter, but still returns -1 as number of files in the clipboard after copying or drag drop some files as test Edit: i also tried to put the created GUI handle as parameter for the function with no result Edited January 13, 2016 by k4rl3on
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