如何从剪贴板粘贴文本?

发布于 2025-01-07 00:58:57 字数 275 浏览 2 评论 0原文

我有代码;

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

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

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

我到处找了也没明白。

谢谢。

I have the code;

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

which works just fine. Before hand, I copied to the clipboard a text.

What I want to know is how can I use postmessage and paste the text.

I searched everywhere and do not understand.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走干脆点 2025-01-14 00:58:57

这是一个 C# 代码,将其转换或使用我的代码制作 ac# 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

This is a C# code convert it or make a c# dll with my code:
(You need to add reference 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);
}

Update C++ code :

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);
}

Update 2

I suppose that you need native code, so you didn't use my code up there that didn't require a handle, plus if you acheive HWND MShwnd = FindWindowA("MapleStoryClass", NULL); so you have a handle... Any way i suggest one last method is the following:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文