# sensing when the clip board has changed

**URL:** <https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296>\
**Category:** Windows\
**Created:** [April 24, 2017, 3:47am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296 "2017-04-24T03:47:56Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Cullins](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/73ab20/32.png) [@David\_Cullins](https://forum.xojo.com/u/David_Cullins)\
**Post date:** [April 24, 2017, 3:47am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/1 "2017-04-24T03:47:56Z")

</div>

In VB 6 there was a way to sense the event when the clipboard was performing a copy ( outside of the application )  
the text could then be assigned to a text field without the need to do a manual paste.

Does Xojo have this capability ?  
It there a plugin that will handle this ??

Please advise.

---

<div class="post-metadata">

**Author:** ![Douglas\_Handy](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@Douglas\_Handy](https://forum.xojo.com/u/Douglas_Handy)\
**Post date:** [April 24, 2017, 5:37am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/2 "2017-04-24T05:37:35Z")

</div>

I quit using VB6 many years ago, after discovering Xojo (or rather its predecessors). So I don’t remember exactly what you are referring to here, or what action you are really looking to perform. I only recall there being a way to put something into the clipboard, or retrieving the contents of the clipboard.

You can accomplish those things easily in Xojo too. See the Clipboard class:

[](http://developer.xojo.com/clipboard)

There is example code at the above class description for programatically placing text onto the clipboard. I just checked, and in the Examples shipped with Xojo under Text there is both a ClipBoard and DragText sample project. You may want to look at those projects as well.

---

<div class="post-metadata">

**Author:** ![Thomas\_Tempelmann](https://forum.xojo.com/user_avatar/forum.xojo.com/thomas_tempelmann/32/315_2.png) [@Thomas\_Tempelmann](https://forum.xojo.com/u/Thomas_Tempelmann)\
**Post date:** [April 24, 2017, 5:55am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/3 "2017-04-24T05:55:37Z")

</div>

Please move this question to the Windows channel as it’s apparently specific to Windows (I had an answer for Mac)

---

<div class="post-metadata">

**Author:** ![Douglas\_Handy](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@Douglas\_Handy](https://forum.xojo.com/u/Douglas_Handy)\
**Post date:** [April 24, 2017, 6:07am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/4 "2017-04-24T06:07:47Z")

</div>

It isn’t clear to me the OP is looking for a Windows specific solution. I interpreted it as a request to perform an action similar to what the OP did in VB6, but that does not necessarily mean the capability is not now desired cross platform. What is even less clear to me is exactly what action is desired here. I must not remember VB6 well enough now.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [April 24, 2017, 6:56am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/5 "2017-04-24T06:56:38Z")

</div>

On macOS you need to use a timer and check yourself if the content has changed as there is no notification sent out when the clipboard changes.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [April 24, 2017, 7:00am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/6 "2017-04-24T07:00:26Z")

</div>

I see no such event here [https://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1](https://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1)

It should be pretty simple to monitor the clipboard in a timer, say 500ms period, and look for its content.

Monitoring picture, pictureAvailable, Text or TextAvailable and RawDataAvailable changes, and the value of the clipboard, I see no major hurdle here.

David : to move this discussion to Windows, click on Controls and select “Change Channel”.

---

<div class="post-metadata">

**Author:** ![Douglas\_Handy](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@Douglas\_Handy](https://forum.xojo.com/u/Douglas_Handy)\
**Post date:** [April 24, 2017, 7:49am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/7 "2017-04-24T07:49:15Z")

</div>

Oh, I evidently misinterpreted this part of the OP question:

> [@](#):
>
> sense the event when the clipboard was performing a copy ( outside of the application ) the text could then be assigned to a text field without the need to do a manual paste.

I was thinking the OP meant to assign the text to a field outside the application, similar to asking about dragging listbox rows out of the application. If it is the reverse, detecting when the clipboard has new contents you want to auto-paste in the application, then I agree a timer is the way to go. One scenario where I can see that being potentially useful is a license dialog. If the clipboard text changes and is a valid format for your license scheme, auto pasting it into an open license dialog is marginally convenient.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [April 24, 2017, 8:15am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/8 "2017-04-24T08:15:36Z")

</div>

> [@327442:@Eli Ott](#):
>
> On macOS you need to use a timer and check yourself if the content has changed as there is no notification sent out when the clipboard changes.

this could work on any platform, not only on macos ?

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [April 24, 2017, 8:22am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/9 "2017-04-24T08:22:18Z")

</div>

> [@327450:@Jean-Yves Pochez](#):
>
> this could work on any platform, not only on macos ?

Yes, of course polling will work on any platform.

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [April 24, 2017, 8:26am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/10 "2017-04-24T08:26:21Z")

</div>

You could event-check if the clipboard has changed each time the application or window is brought to the foreground.

---

<div class="post-metadata">

**Author:** ![Mattias\_Sandström](https://forum.xojo.com/user_avatar/forum.xojo.com/mattias_sandstr%C3%B6m/32/16744_2.png) [@Mattias\_Sandström](https://forum.xojo.com/u/Mattias_Sandstr%C3%B6m)\
**Post date:** [April 24, 2017, 8:38am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/11 "2017-04-24T08:38:51Z")

</div>

See [https://msdn.microsoft.com/en-us/library/windows/desktop/ms649025(v=vs.85).aspx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms649025(v=vs.85).aspx)  
I haven’t used this functionality myself, but I am using MBS plug-in to listen to other WM messages sent in the system.  
[http://www.monkeybreadsoftware.net/class-winnotificationmbs.shtml](http://www.monkeybreadsoftware.net/class-winnotificationmbs.shtml)

---

<div class="post-metadata">

**Author:** ![shao\_sean](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/ed8c4c/32.png) [@shao\_sean](https://forum.xojo.com/u/shao_sean)\
**Post date:** [April 24, 2017, 8:48am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/12 "2017-04-24T08:48:34Z")

</div>

> [@](#):
>
> Only clipboard viewer windows receive this message. These are windows that have been added to the clipboard viewer chain by using the SetClipboardViewer function.

---

<div class="post-metadata">

**Author:** ![Mattias\_Sandström](https://forum.xojo.com/user_avatar/forum.xojo.com/mattias_sandstr%C3%B6m/32/16744_2.png) [@Mattias\_Sandström](https://forum.xojo.com/u/Mattias_Sandstr%C3%B6m)\
**Post date:** [April 24, 2017, 8:49am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/13 "2017-04-24T08:49:35Z")

</div>

> [@327455:@shao sean](#):
>
> I guess calling SetClipboardViewer would be possible…

---

<div class="post-metadata">

**Author:** ![shao\_sean](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/ed8c4c/32.png) [@shao\_sean](https://forum.xojo.com/u/shao_sean)\
**Post date:** [April 24, 2017, 2:01pm UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/14 "2017-04-24T14:01:04Z")

</div>

Apparently that is the older way to monitor the clipboard… Microsoft recommends using some newer commands… The following code is just something off the top of my head as I’m on a MacBook right now so can’t test Windows declares…

[GetClipboardSequenceNumber function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms649042(v=vs.85).aspx)

```auto
Declare Function GetClipboardSequenceNumber Lib "user32.dll" () As Int32
```

The system keeps a serial number for the clipboard for each window station. This number is incremented whenever the contents of the clipboard change or the clipboard is emptied. You can track this value to determine whether the clipboard contents have changed

[AddClipboardFormatListener function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms649033(v=vs.85).aspx)

```auto
Declare Function AddClipboardFormatListener Lib "user32.dll" (HWND As Integer) As Boolean
```

Places the given window in the system-maintained clipboard format listener list.  
Returns TRUE if successful, FALSE otherwise.  
When a window has been added to the clipboard format listener list, it is posted a [WM\_CLIPBOARDUPDATE](https://msdn.microsoft.com/en-us/library/windows/desktop/ms649021(v=vs.85).aspx) message whenever the contents of the clipboard have changed.

[RemoveClipboardFormatListener function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms649050(v=vs.85).aspx)

```auto
Declare Function RemoveClipboardFormatListener Lib "user32.dll" (HWND As Integer) As Boolean
```

Removes the given window from the system-maintained clipboard format listener list.  
Returns TRUE if successful, FALSE otherwise.  
When a window has been removed from the clipboard format listener list, it will no longer receive WM\_CLIPBOARDUPDATE messages.

---

<div class="post-metadata">

**Author:** ![David\_Cullins](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/73ab20/32.png) [@David\_Cullins](https://forum.xojo.com/u/David_Cullins)\
**Post date:** [April 26, 2017, 4:04am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/15 "2017-04-26T04:04:28Z")

</div>

I am Developing primarily for MAC OS and have a should i still move this to a windows discussion?

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [April 26, 2017, 6:14am UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/16 "2017-04-26T06:14:42Z")

</div>

If indeed you develop cross platform that is fine as it is. Maybe next time, it would be worthwhile to mention in your original post the cross-platform nature of your development, so specialists of both platforms can help.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:44pm UTC](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/17 "2020-10-29T18:44:21Z")

</div>


