[英]Setting Clipboard content using a Background Task [Windows 10] [UWP]
[英]Put text to clipboard in the background process on locked Windows 10 machine
我正在構建一個進程(到目前為止,我已經在 .Net Framework 4.7.2 上嘗試過 VBA、Python 和 C#),它需要將一些字符串放在鎖定屏幕后面的 Windows 10 機器上的剪貼板上。 為了測試,我將它減少到只有兩個命令(偽代碼,因為使用了 3 種語言。問題末尾的詳細信息):
SleepForFiveSec(); //to provide time for locking screen
// now locking machine
SetClipboardContent();
剪貼板對解鎖會話有響應,但在機器鎖定時變得不可用並返回“剪貼板鎖定”錯誤(特定於語言)。
我已經測試了在 google/stackoverflow 中發現的幾種與剪貼板相關的技術,用於提到的語言(總共大約 6 種),但到目前為止都沒有。
機器在 Windows 10 Enterprise 上運行(在 3 台具有相同版本的不同機器上測試)。
代碼示例:
C# 選項 1:
using System.Windows.Forms;
.....
[STAThread]
static void Main()
{
System.Threading.Thread.Sleep(5000);
Clipboard.SetText("test copy clip");
}
C# opt 2(檢查什么是鎖定剪貼板):
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr GetOpenClipboardWindow();
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int GetWindowText(int hwnd, StringBuilder text, int count);
private static string getOpenClipboardWindowText()
{
IntPtr hwnd = GetOpenClipboardWindow();
StringBuilder sb = new StringBuilder(501);
GetWindowText(hwnd.ToInt32(), sb, 500);
return sb.ToString();
}
蟒蛇選擇1:
import pyperclip
import time
time.sleep(5)
pyperclip.copy('text')
蟒蛇選擇2:
import win32clipboard
import time
time.sleep(5)
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText('text')
win32clipboard.CloseClipboard()
VBA 選項 1:
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText "text for input"
clipboard.PutInClipboard
VBA opt.2: VBA Windows 10 問題中的文本到剪貼板
為此,您的后台進程應該在用戶帳戶中運行,並且應該在用戶登錄期間啟動。
在 python 中使用 tkinter,更多信息在這里https://www.daniweb.com/programming/software-development/code/487653/access-the-clipboard-via-tkinter但以下內容適用於我在 PC 時從剪貼板獲取數據被鎖住了。 在我的情況下,粘貼功能在另一個軟件中是自動化的,但您可以使用 cb.clipboard_append('text') 來獲取文本。
from tkinter import Tk
try:
cb = Tk()
cb.selection_get(selection='CLIPBOARD')
except:
selection=None
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.