# Clipboard - New content notifications?

**URL:** <https://forum.xojo.com/t/clipboard-new-content-notifications/65160>\
**Category:** Windows\
**Created:** [August 22, 2021, 12:22am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160 "2021-08-22T00:22:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Boyle](https://forum.xojo.com/user_avatar/forum.xojo.com/ken_boyle/32/2030_2.png) [@Ken\_Boyle](https://forum.xojo.com/u/Ken_Boyle)\
**Post date:** [August 22, 2021, 12:22am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/1 "2021-08-22T00:22:20Z")

</div>

Is there a (recommended?) way to know when the clipboard content changes?

Any help/suggestions will be appreciated.

Ken.

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [August 22, 2021, 1:33am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/2 "2021-08-22T01:33:25Z")

</div>

To be notified you’ll need to be able to receive raw window messages from the system and then [register to receive clipboard notification messages](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-addclipboardformatlistener). This is doable in Xojo but not simple; see the [HotKeyHelper class in the Windows Functionality Suite](https://github.com/arbp/WFS/blob/master/Windows%20Functionality%20Suite/Miscellaneous/Classes/HotKeyHelperWFS.rbbas) for an example of receiving window messages.

A much simpler solution is to [poll the clipboard sequence number](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboardsequencenumber):

```auto
Function HasClipboardChanged() As Boolean
  Declare Function GetClipboardSequenceNumber Lib "User32" () As Integer
  Static lastSeqNum As Integer
  Dim current As Integer = GetClipboardSequenceNumber()
  If current <> lastSeqNum Then
    lastSeqNum = current
    Return True
  End If
End Function

```

---

<div class="post-metadata">

**Author:** ![Ken\_Boyle](https://forum.xojo.com/user_avatar/forum.xojo.com/ken_boyle/32/2030_2.png) [@Ken\_Boyle](https://forum.xojo.com/u/Ken_Boyle)\
**Post date:** [August 22, 2021, 1:40am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/3 "2021-08-22T01:40:24Z")

</div>

Thanks Andrew.

So would I put that code onto a timer to constantly monitor the clipboard?

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [August 22, 2021, 1:54am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/4 "2021-08-22T01:54:42Z")

</div>

Yes. I’d suggest using the shortest possible period (1ms) for the Timer.

---

<div class="post-metadata">

**Author:** ![Ken\_Boyle](https://forum.xojo.com/user_avatar/forum.xojo.com/ken_boyle/32/2030_2.png) [@Ken\_Boyle](https://forum.xojo.com/u/Ken_Boyle)\
**Post date:** [August 22, 2021, 1:55am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/5 "2021-08-22T01:55:22Z")

</div>

Many thanks. 😉

---

<div class="post-metadata">

**Author:** ![Ivan\_Tellez](https://forum.xojo.com/letter_avatar_proxy/v4/letter/i/a9a28c/32.png) [@Ivan\_Tellez](https://forum.xojo.com/u/Ivan_Tellez)\
**Post date:** [August 22, 2021, 3:14am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/6 "2021-08-22T03:14:36Z")

</div>

> [@Andrew\_Lambert](#):
>
> Yes. I’d suggest using the shortest possible period (1ms) for the Timer.

You cant use a period shorter than 16ms in windows with regular timers.

The propper way is with declares: [sensing when the clip board has changed - #10 by David\_Cox](https://forum.xojo.com/t/sensing-when-the-clip-board-has-changed/37296/10)

But the timer can work Ok

---

<div class="post-metadata">

**Author:** ![Andrew\_Lambert](https://forum.xojo.com/user_avatar/forum.xojo.com/andrew_lambert/32/215_2.png) [@Andrew\_Lambert](https://forum.xojo.com/u/Andrew_Lambert)\
**Post date:** [August 22, 2021, 3:33am UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/7 "2021-08-22T03:33:10Z")

</div>

The intent of using a 1ms period here is to have the timer run on every iteration of the event loop, however frequently that may be.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [August 22, 2021, 1:25pm UTC](https://forum.xojo.com/t/clipboard-new-content-notifications/65160/8 "2021-08-22T13:25:04Z")

</div>

Then you can use “timer timeout of 0 that means the next event loop” you can use timer.Calllater 0, AddressOf AMethod
