[英]C Clipboard updating very slow
I want to monitor key events given to another application, and whenever ctrl+d is pressed, send ctrl+c, grab the (new) clipboard content and depending on it perform other actions. 我想监视给另一个应用程序的关键事件,每当按下ctrl + d时,发送ctrl + c,抓取(新)剪贴板内容并依赖它执行其他操作。
My code: 我的代码:
void PressKeyboardKey(char key){
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wVk = key;
ip.ki.wScan = 0;
ip.ki.dwFlags = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
}
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam ){
char pressedKey;
// Declare a pointer to the KBDLLHOOKSTRUCTdsad
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
switch( wParam )
{
case WM_KEYUP:
{
pressedKey = (char)pKeyBoard->vkCode; //get the key code
if ((pressedKey == -94) || (pressedKey == -93)){ //Ctrl
CtrlPressed = FALSE;
}else if (pressedKey == 68){ //d
if (CtrlPressed && IsTargetApplicationActive()){
PressKeyboardKey(67); //c
//Read from Clipboard
Sleep(CLIPBOARD_SLEEP_TIME);
HANDLE h;
if (!OpenClipboard(NULL)){
break; //abort
}
h = GetClipboardData(CF_TEXT);
const char* output = evaluateItem((char*)h); // For now prints the content of the clipboard
Sleep(ADDITIONAL_SLEEP_TIME); //Ususally not there, added just for testing
CloseClipboard();
.....
}
If CLIPPBOARD_SLEEP_TIME >= 350 (minimum), everything works as expected, tough the time is too long for a good workflow. 如果CLIPPBOARD_SLEEP_TIME> = 350(最小值),一切都按预期工作,对于良好的工作流程来说,时间太长了。 Otherwise, I only get the old clipboard content.
否则,我只获得旧的剪贴板内容。
My first guess was, that the target application fills clipboard very slow, however the following ahk script: 我的第一个猜测是,目标应用程序填充剪贴板非常慢,但是以下ahk脚本:
^d::
Send, ^c
MsgBox, %clipboard%
works seemingly instantaneous. 工作看似瞬间。 Therefore there must be a faster way to grab the clipboards content.
因此,必须有更快的方法来获取剪贴板内容。
Anyone knows how to do it in C - what am I doing wrong? 任何人都知道如何在C中做到这一点 - 我做错了什么?
你必须使用SetClipboardViewer()
,不要使用Sleep()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.