Edu*_*eni 13
你的问题有两个答案
你必须调用一个名为RegisterHotKey的API函数
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
);
Run Code Online (Sandbox Code Playgroud)
更多信息:http://www.codeproject.com/KB/system/nishhotkeys01.aspx
最简单的方法是将crl-C发送到窗口然后捕获剪贴板内容.
[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
}
Run Code Online (Sandbox Code Playgroud)
免责声明:Marcus Peters的代码来自这里:http://bytes.com/forum/post1029553-5.html
发布在这里为了您的方便.