| View previous topic :: View next topic |
| Author |
Message |
ManaUser
Joined: 24 May 2007 Posts: 900
|
Posted: Fri Aug 10, 2007 7:24 am Post subject: Odd Clipboard related error |
|
|
I'm getting "Error: GetClipboardData" when I access the Clipboard variable when certain contents are in the clipboard. Specifically when the clipboard contains a Firefox bookmark folder. Normally, Clipboard should just be blank if there's no text in the clipboard, right? Here's the script I was using.
| Code: | AppsKey & v::
;Paste as text
If (ClipBoard != "")
PutText(ClipBoard)
Return
PutText(MyText)
{
SavedClip := ClipboardAll
Clipboard := MyText
Send ^v
Sleep 100
Clipboard := SavedClip
Return
} |
These steps should reproduce the error:
Start Firefox, click the Bookmarks menu, right-click "Bookmarks Toolbar Folder", select Copy, run the script above, and press AppsKey+V. |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1090 Location: USA
|
Posted: Fri Aug 10, 2007 10:22 pm Post subject: |
|
|
Confim the error.
Get the same error with this.
| Code: | AppsKey & v::
abc := Clipboard
return |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3941 Location: Pittsburgh
|
Posted: Fri Aug 10, 2007 10:56 pm Post subject: |
|
|
It happens to me, too.
- It does not matter what hotkey I use
- I tried #ClipboardTimeout 10000 (10 sec), the only difference is that the error dialog appears later.
- The clipboard does contain data. If I paste it into Word, I get Bookmarks Toolbar Folder |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3941 Location: Pittsburgh
|
Posted: Fri Aug 10, 2007 11:14 pm Post subject: |
|
|
| If you use "abc := ClipboardAll", there is no error, but, of course, you don't see the text content of the clipboard, either. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1240
|
Posted: Sat Aug 11, 2007 2:20 am Post subject: |
|
|
I'm not sure if it's an AHK's fault. When doing this with firefox, the clipboard is really populated by firefox. The available formats are:
moz/bookmarkclipboarditem, text/html, HTML Format, CF_UNICODETEXT, CF_TEXT.
The first three are custom formats and contain actual data, i.e., the type of the storage medium is TYMED_HGLOBAL, so no problem with GetClipboardData.
However, the last two are of type TYMED_NULL, i.e., no actual data has been passed. Thus, GetClipboardData produced errors on these, naturally.
Refer the link for more detail:
http://msdn2.microsoft.com/en-us/library/ms691227.aspx |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3941 Location: Pittsburgh
|
Posted: Sat Aug 11, 2007 3:41 am Post subject: |
|
|
| In the AHK assignment x := ClipBoard the CF_TEXT format is used, isn't it? Was not it easy to check, if its content is TYMED_NULL, and if yes, assign the empty string to x? In MS Word I can Paste Special / Unformatted text, which does not crash or give an error, but pastes nothing. This should happen in AHK, too. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1240
|
Posted: Sat Aug 11, 2007 4:37 am Post subject: |
|
|
| Laszlo wrote: | | In the AHK assignment x := ClipBoard the CF_TEXT format is used, isn't it? Was not it easy to check, if its content is TYMED_NULL, and if yes, assign the empty string to x? In MS Word I can Paste Special / Unformatted text, which does not crash or give an error, but pastes nothing. This should happen in AHK, too. |
The ordinary Clipboard APIs can't get infos about the storage medium types.
Have to use OLE's clipboard functions, OleGetClipboard etc, and deal with a COM object IDataObject.
I'll post a sample script on these later. |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 900
|
Posted: Sat Aug 11, 2007 4:53 am Post subject: |
|
|
| Laszlo wrote: | | In the AHK assignment x := ClipBoard the CF_TEXT format is used, isn't it? Was not it easy to check, if its content is TYMED_NULL, and if yes, assign the empty string to x? In MS Word I can Paste Special / Unformatted text, which does not crash or give an error, but pastes nothing. This should happen in AHK, too. |
Exactly. It does sound like Firefox is using the clipboard oddly, but from an AHK user/programmer's point of view, I need to know that I can always safely access the clipboard, even when it doesn't contain usable text. (In which case it should be blank.)
It also causes an error if I run this and then copy a bookmark folder.
| Code: | ClipBoard =
ClipWait
MsgBox %ClipBoard% |
So the TYMED_NULL CF_TEXT apparently fools ClipWait too. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1240
|
Posted: Sat Aug 11, 2007 12:43 pm Post subject: |
|
|
| ManaUser wrote: | | Exactly. It does sound like Firefox is using the clipboard oddly, but from an AHK user/programmer's point of view, I need to know that I can always safely access the clipboard, even when it doesn't contain usable text. (In which case it should be blank.) |
IMO, AHK or Chris was too innocent.
If there was an error to obtain hGlobal, could just ignore it and you'd never notice about it (:no offense intended here). |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10463
|
Posted: Sat Aug 18, 2007 12:46 am Post subject: |
|
|
If it seems okay with everyone, the next release will have the following change:
Eliminated the "GetClipboardData" error dialog. Instead, an empty string is retrieved when the data cannot be retrieved within the #ClipboardTimeout period.
This seems unlikely to break many (if any) existing scripts. But please let me know if you see any problems with it.
Thanks for all the detailed posts about it. |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 900
|
Posted: Tue Aug 21, 2007 7:17 pm Post subject: |
|
|
| Certainly sounds good to me. |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 400 Location: Galil, Israel
|
Posted: Wed Aug 22, 2007 4:13 pm Post subject: |
|
|
second that,
maybe also set errorlevel in such a case... _________________ Joyce Jamce |
|
| Back to top |
|
 |
|