Author Topic: How do i clear the Windows Clipboard  (Read 2417 times)

FireSammy

  • Newbie
  • *
  • Posts: 43
How do i clear the Windows Clipboard
« on: December 24, 2023, 02:25:05 AM »
The traditional way to clear windows clipboard is not working. Is there another way to do this?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #1 on: December 24, 2023, 02:26:37 AM »
What do you mean by "The traditional way"?

Using the "Set a Text Value to the Windows Clipboard" action with the "Value" field left blank should clear the clipboard

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #2 on: December 24, 2023, 02:59:28 AM »
Yes that is what i mean. It doesnt work for me. I will try to run as an administrator and see if any difference

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #3 on: December 24, 2023, 03:01:58 AM »
No administrator mode didnt help

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #4 on: December 24, 2023, 03:04:36 AM »
If you open the inline function editor, replace the default example with
Code: [Select]
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;


public class VAInline
{
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern IntPtr GetOpenClipboardWindow();

    [DllImport("user32.dll", SetLastError = true)]
    static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

    public void main()
    {
        IntPtr windowUsingClipboard = GetOpenClipboardWindow();

        if (windowUsingClipboard != IntPtr.Zero)
        {
            uint processId;
            uint threadId = GetWindowThreadProcessId(windowUsingClipboard, out processId);

            VA.WriteToLog("The clipboard is currently open in the process \"" + Process.GetProcessById((int)processId).ProcessName + "\"", "red");
        }
        else
        {
            VA.WriteToLog("The clipboard does not appear to be open", "green");
        }
    }
}
and click "Test Run", what is shown in the log?

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #5 on: December 24, 2023, 03:35:44 AM »
I dont even know what you mean by inline editor... LOL
Here is how i solved my issue:

Clear the Windows clipboard
Clear Dictation Buffer
Say, 'Clear Windows clipboard'  (and wait until it completes)
Open Search Dialog
Pause 2 seconds
Quick Input, 'Clipboard settings'
Pause 2 seconds
Execute command, 'Press Enter; Select' (and wait until it completes)
Pause 3 seconds
Execute command, 'Tab Press' (and wait until it completes)
Execute command, 'Tab Press' (and wait until it completes)
Execute command, 'Tab Press' (and wait until it completes)
Execute command, 'Tab Press' (and wait until it completes)
Execute command, 'Tab Press' (and wait until it completes)
Execute command, 'Press Enter; Select' (and wait until it completes)
Pause 1 second
Execute command, '[Start; Open; Show] Windows Clipboard; Windows Clipboard; Clipboard' (and wait until it completes)
Say, 'Windows clipboard cleared'  (and wait until it completes)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #6 on: December 24, 2023, 03:38:07 AM »
The simplest way to access the editor is to open an "Add a Command" window, then press Ctrl-F10

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #7 on: December 24, 2023, 03:44:32 AM »
I tested your code and here is what it said on the log:

12:42:57.615 The clipboard does not appear to be open

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #8 on: December 24, 2023, 03:49:49 AM »
It's not a foolproof test, necessarily, but that should mean that it's not another application holding the clipboard open.


If you create a new command with these contents, what is written to the log?
Code: [Select]
Set Windows clipboard to 'test'
Write [Blue] '{CLIP}' to log
Clear the Windows clipboard
Write [Blue] '{CLIP}' to log

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #9 on: December 24, 2023, 04:46:06 AM »
Compile errors: 1
Class name VAInline is required for this context

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #10 on: December 24, 2023, 04:53:30 AM »
A command, not an inline function.

It's two "Write a Value to the Event Log" actions, and two "Set a Text Value to the Windows Clipboard" actions.

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #11 on: December 24, 2023, 05:23:12 AM »
ok i try that just a moment

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #12 on: December 24, 2023, 05:27:42 AM »
Open the "Add a Command" window

Press Alt-U
Type "test" into the "Value" field
Click "OK"

Press Alt-E
Type/paste
Code: [Select]
{CLIP}into the "Value" field
Click "OK"

Press Alt-U
Click "OK"

Press Alt-E
Type/paste
Code: [Select]
{CLIP}into the "Value" field
Click "OK"

Click "OK" to add the command to the profile

Right-click the command in the command list, and choose "Execute".

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #13 on: December 24, 2023, 05:31:39 AM »
Now this is strange, it seems to work, first it type "Test", then log results empty, but when i open the windows clipboard Win key + V -it shows Test remaining in the Clipboard. I dont get this??

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #14 on: December 24, 2023, 05:33:08 AM »
Win-V shows clipboard history (I.E. things that were in the clipboard before), as far as I'm aware, not just what's in the clipboard at the time.

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #15 on: December 24, 2023, 05:41:40 AM »
Ok so this works fine then. I didnt realize it shows history like that way. When i tested to CTRL+V its empty, but it shows history in the clipboard log... Ok so the next question is how to delete the history with a command or is it only possible to empty it manually?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do i clear the Windows Clipboard
« Reply #16 on: December 24, 2023, 05:48:43 AM »
Certainly not natively, no.

If you don't want clipboard history, you could turn it off in Windows (on the same settings page as the button to clear it).

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: How do i clear the Windows Clipboard
« Reply #17 on: December 24, 2023, 06:05:19 AM »
Ok thanks alot m8, really nice help. Merry Christmas!!