开发者

keybd_event doesn't work in activex,postmessage does,but can't simulate VK_BACK

开发者 https://www.devze.com 2023-04-08 08:55 出处:网络
I\'m developing a br开发者_JS百科owser 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

I'm developing a br开发者_JS百科owser 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消