Just1f Posted February 15, 2008 Share Posted February 15, 2008 (edited) When you uses Clipget() you get clipboard buffer as result, and the script holds on until ClipGet() returns. But when you uses ClipPut($data) it sends the data to the clipboard but Autoit does not verify that Windows finished to copy the text to the clipboard before continuing the script. That means that you can have a race condition where your ClipGet() will not sometimes get what you previously set in ClipPut() if there is a short delay between them. How to have ClipPut() blocks the scripts until being sure Windows finished to transfer the data to the clipboard ? Thank you. Edited February 15, 2008 by Just1f Link to comment Share on other sites More sharing options...
BrettF Posted February 15, 2008 Share Posted February 15, 2008 Not to sure on this one, but maybe this example could help? expandcollapse popup#include <GuiConstantsEx.au3> #include <ClipBoard.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $iMemo _Main() Func _Main() Local $hGUI, $btn_SetData, $btn_GetData, $hMemory, $hLock, $tData, $sData, $iSize ; Create GUI $hGUI = GUICreate("Clipboard", 600, 450) $iMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") $btn_SetData = GUICtrlCreateButton("Set ClipBoard Data", 150, 410, 120, 30) $btn_GetData = GUICtrlCreateButton("Get ClipBoard Data", 300, 410, 120, 30) GUISetState() ; Loop until user exits While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn_SetData ; Open clipboard If Not _ClipBoard_Open (0) Then _WinAPI_ShowError ("_ClipBoard_Open failed") ; Empty clipboard If Not _ClipBoard_Empty () Then _WinAPI_ShowError ("_ClipBoard_Empty failed") ; Create global memory buffer (show why using _ClipBoard_SetData is MUCH easier!) $sData = "Hello from AutoIt" $iSize = StringLen($sData) + 1 $hMemory = _MemGlobalAlloc ($iSize, $GHND) If $hMemory = 0 Then _WinAPI_ShowError ("_Mem_GlobalAlloc failed") $hLock = _MemGlobalLock ($hMemory) If $hLock = 0 Then _WinAPI_ShowError ("_Mem_GlobalLock failed") $tData = DllStructCreate("char Text[" & $iSize & "]", $hLock) DllStructSetData($tData, "Text", $sData) _MemGlobalUnlock ($hMemory) ; Write clipboard text If Not _ClipBoard_SetDataEx ($hMemory, $CF_TEXT) Then _WinAPI_ShowError ("_ClipBoard_SetDataEx failed") ; Close clipboard _ClipBoard_Close () Case $btn_GetData MemoWrite(_ClipBoard_GetData ()) EndSwitch WEnd EndFunc ;==>_Main ; Write message to memo Func MemoWrite($sMessage = "") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
MHz Posted February 15, 2008 Share Posted February 15, 2008 How to have ClipPut() blocks the scripts until being sure Windows finished to transfer the data to the clipboard ?This seems to work as it checks against the contents of the clipboard until it is a match with what ClipPut() added. ; example to test For $i = 1 To 100 _ClipPut("some text " & $i) Next Exit Func _ClipPut($text) ClipPut($text) Do Sleep(10) Until ClipGet() = $text ConsoleWrite($text & @CRLF); test output EndFunc Link to comment Share on other sites More sharing options...
Just1f Posted February 15, 2008 Author Share Posted February 15, 2008 Thank you for your answers ! 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