gpt4 book ai didi

c++ - 如何从剪贴板粘贴文本?

转载 作者:太空宇宙 更新时间:2023-11-04 12:12:04 25 4
gpt4 key购买 nike

我有代码;

HWND MShwnd = FindWindowA("MapleStoryClass", NULL);
PostMessage(MShwnd, WM_KEYDOWN, 0x09, MapVirtualKeyA(0x09, 0) << 16);

效果很好。之前,我将文本复制到剪贴板。

我想知道的是如何使用postmessage并粘贴文本。

到处找了,没看懂。

谢谢。

最佳答案

这是一个 C# 代码转换它或用我的代码制作一个 c# dll:(您需要添加引用 Microsoft.VisualBasic)

public string GetClipboardText()
{
Microsoft.VisualBasic.Devices.Computer c = new Microsoft.VisualBasic.Devices.Computer();
return c.Clipboard.GetText();
}

public void SetClipboardText(string stext)
{
Microsoft.VisualBasic.Devices.Computer c = new Microsoft.VisualBasic.Devices.Computer();
c.Clipboard.SetText(stext);
}

更新 C++ 代码:

System::String^ GetClipboardText()
{
Microsoft::VisualBasic::Devices::Computer^ c = gcnew Microsoft::VisualBasic::Devices::Computer();
return c->Clipboard->GetText();
}

void SetClipboardText(System::String^ stext)
{
Microsoft::VisualBasic::Devices::Computer^ c = gcnew Microsoft::VisualBasic::Devices::Computer();
c->Clipboard->SetText(stext);
}

更新 2

我想你需要本地代码,所以你没有使用我上面不需要句柄的代码,如果你实现了 HWND MShwnd = FindWindowA("MapleStoryClass", NULL); 所以你有一个句柄......我建议最后一种方法的任何方式如下:

keybd_event(0x11, 0, 0, 0); // press ctrl
keybd_event(0x56, 0, 0, 0); // press v
keybd_event(0x56, 0, 2, 0); // release v
keybd_event(0x11, 0, 2, 0); // release ctrl

关于c++ - 如何从剪贴板粘贴文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9357893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com