复制和修改在不同的应用程序中选择文本 [英] Copy and Modify selected text in different application

查看:218
本文介绍了复制和修改在不同的应用程序中选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经运行在后台一个Windows应用程序。我在此应用程序映射到热键功能。就像如果我把一个消息框,这个功能并给予热键为<大骨节病>替代 + <大骨节病>控制 + <大骨节病>ð。然后在pressing <大骨节病>替代,<大骨节病>控制和<大骨节病>ð在一起的消息框出现。我的应用程序工作正常,直到这一点。

I have a windows application running at the backend. I have functions in this applications mapped to hot keys. Like if I put a message box into this function and give hot key as Alt+Ctrl+D. then on pressing Alt, Ctrl and D together the message box comes up. My application is working fine till this point.

现在我想写一个code此函数内,这样,当我使用类似记事本的另一个应用程序,我选择文本和$ P $的特定线路PSS快捷键大骨节病>替代 + <大骨节病>控制 + <大骨节病>ð它应该复制选定的文本与_copied追加并粘贴回记事本。

Now I want to write a code inside this function so that when I am using another application like notepad, I select a particular line of text and press the hot key Alt + Ctrl + D it is supposed to copy the selected text append it with "_copied" and paste it back to notepad.

任何人谁尝试过类似的应用程序,请帮我看看您的宝贵意见。

Anyone who has tried a similar application please help me with your valuable inputs.

推荐答案

您的问题有两个答案

您必须调用API funcion称为RegisterHotKey

You have to call an API funcion called RegisterHotKey

BOOL RegisterHotKey(
    HWND hWnd,         // window to receive hot-key notification
    int id,            // identifier of hot key
    UINT fsModifiers,  // key-modifier flags
    UINT vk            // virtual-key code
);

这里更多信息:<一href="http://www.$c$cproject.com/KB/system/nishhotkeys01.aspx">http://www.$c$cproject.com/KB/system/nishhotkeys01.aspx

最简单的方法是发送CRL-C的窗口,然后捕捉到剪贴板中的内容。

Easiest way is to send crl-C to the window and then capture the clipboard content.

[DllImport("User32.dll")] 
private static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);


.....

private void SendCtrlC(IntPtr hWnd)
    {
    uint KEYEVENTF_KEYUP = 2;
    byte VK_CONTROL = 0x11;
    SetForegroundWindow(hWnd);
    keybd_event(VK_CONTROL,0,0,0);
    keybd_event (0x43, 0, 0, 0 ); //Send the C key (43 is "C")
    keybd_event (0x43, 0, KEYEVENTF_KEYUP, 0);
    keybd_event (VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up

}

免责声明:从这里code。通过马库斯·彼得斯: http://bytes.com/forum/post1029553-5 .HTML
张贴在这里为您提供方便。

Disclaimer: Code by Marcus Peters from here: http://bytes.com/forum/post1029553-5.html
Posted here for your convenience.

这篇关于复制和修改在不同的应用程序中选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆