keybd_event在activex中不起作用,postmessage可以,但无法模拟VK_BACK

发布于 2024-12-07 07:01:30 字数 1560 浏览 2 评论 0原文

我正在开发一个可以与 JavaScript 交互的浏览器插件。我使用开源框架firebreath来开发插件,该插件将打包NPAPI(非ie浏览器)插件和activex(在ie中使用) )在一个 dll 文件中。

以下代码在使用 NPAPI 插件的非 ie 浏览器下完美运行("enter","delete","backspace ”键可以正确按下):

//VKey stands for the key users pressed like "VK_RETURN","VK_BACK","VK_DELETE",etc
 keybd_event(Vkey,0, KEYEVENTF_EXTENDEDKEY | 0,0);

但是如果我在ie中运行插件,什么也没有发生。我也尝试了SendInput,但仍然什么也没有< /strong> 发生:

    KEYBDINPUT kb={0}; 
    INPUT Input={0};  
    kb.wScan = VK_BACK; 
    kb.dwFlags = KEYEVENTF_UNICODE;  
    Input.type = INPUT_KEYBOARD; 
    Input.ki = kb;      
    ::SendInput(1,&Input,sizeof(Input));

奇怪的是按键组合正常工作即。例如(ctrl+x):

>   keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL,0), 0 ,0);
>   keybd_event(bCharKey,(BYTE)0, 0 ,0);    
>   Sleep(10);
>   keybd_event(bCharKey,(BYTE)0, KEYEVENTF_KEYUP,0);
>   keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL,0),
>   KEYEVENTF_KEYUP,0);

所以我将 keybd_event 更改为 PostMessage:

    ::PostMessage(hbrowser,WM_KEYDOWN,vKey,1); //vKey stands for key pressed    
    ::PostMessage(hbrowser,WM_KEYUP,vKey,1);

"VK_TAB","VK_DELETE","VK_RETURN","< strong>VK_TAB”、“VK_SPACE”有效,但“VK_BACK”无效。

I'm developing a browser plugin which would interact with javascript. I used the open-source framework firebreath to develop the plugin which would pack NPAPI(non-ie browsers) plugin and activex(used in ie) in one dll file.

The following code works perfectly under non-ie browsers which uses the NPAPI plugin("enter","delete","backspace" keys can be pressed correctly):

//VKey stands for the key users pressed like "VK_RETURN","VK_BACK","VK_DELETE",etc
 keybd_event(Vkey,0, KEYEVENTF_EXTENDEDKEY | 0,0);

But if I run the plugin in ie,nothing happens.I tried SendInput too,but still nothing happens:

    KEYBDINPUT kb={0}; 
    INPUT Input={0};  
    kb.wScan = VK_BACK; 
    kb.dwFlags = KEYEVENTF_UNICODE;  
    Input.type = INPUT_KEYBOARD; 
    Input.ki = kb;      
    ::SendInput(1,&Input,sizeof(Input));

Which is odd is the combination of keys works correctly in ie. eg(ctrl+x):

>   keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL,0), 0 ,0);
>   keybd_event(bCharKey,(BYTE)0, 0 ,0);    
>   Sleep(10);
>   keybd_event(bCharKey,(BYTE)0, KEYEVENTF_KEYUP,0);
>   keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL,0),
>   KEYEVENTF_KEYUP,0);

So I change the keybd_event to PostMessage:

    ::PostMessage(hbrowser,WM_KEYDOWN,vKey,1); //vKey stands for key pressed    
    ::PostMessage(hbrowser,WM_KEYUP,vKey,1);

"VK_TAB","VK_DELETE","VK_RETURN","VK_TAB","VK_SPACE" works,but "VK_BACK" doesn't work.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文