I have an IE BHO created over 3 years ago that uses IHTMLEventObj::put_keyCode function. This function has worked as documented in IE6, IE7 and IE8. However, when testing with IE9 RC it no longer works as documented. The function is called the same way and the result is S_OK, but the key does not show up in the input field. The call is being made in the DISPID_HTMLELEMENTEVENTS2_ONKEYPRESS even of my Invoke() function.
I found someone with a similar problem: http://social.msdn.microsoft.com/Forums/is/ieextensiondevelopment/thread/abcbaffd-ed8a-45b8-840b-8ad8d7d10081, however for some reason I am not able to view the issue. I was able to view it using google cache: http://webcache.googleusercontent.com/search?q=cache:3OkEceoi6jwJ:social.msdn.microsoft.com/Forums/is/ieextensiondevelopment/thread/abcbaffd-ed8a-45b8-840b-8ad8d7d10081+put_keyCode+IE9&cd=1&hl=pt-BR&ct=clnk&gl=br&source=www.google.com.br.
Any help would be greatly appreciated this is a critical issue that needs to be addressed asap.
Thanks in advance.
UPDATE: Here is some code, but wanted to stress, that this code works perfectly in IE6, IE7 and IE8. In IE9, it returns S_OK, but the key is not changed.
BOOL CToolBandObj::InvokeElementOnKeyPress ( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT* pvarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
CComPtr<IDispatch> spEventObj;
spEventObj = pDispParams->rgvarg[0].pdispVal;
CComPtr<IHTMLEventObj> pHtmlEvent;
HRESULT hr = spEventObj->QueryInterface(IID_IHTMLEventObj,(LPVOID*)&pHtmlEvent);
if (SUCCEEDED(hr) && pHtmlEvent)
{
CComPtr<IHTMLElement>spElement;
hr = pHtmlEvent->get_srcElement(&spElement);
_bstr_t bstrTag;
spElement->get_tagName(&bstrTag.GetBSTR());
if (SUCCEEDED(hr) && spElement)
{
LONG lKeyCode = 0;
pHtmlEvent->get_keyCode(&lKeyCode);
pHtmlEvent->put_keyCode(lKeyCode);
pvarResult->vt = VT_BOOL;
pvarResult->boolVal = VARIANT_TRUE;
return TRUE;
}
}
}
UPDATE 2
We have filed a MSDN Case, they have found the issue, and last we heard from them were going to fix it.
Finally after opening a case and many weeks, a fix was released: The IHTMLEventObj::put_keyCode function does not work in Internet Explorer 9 Standards mode.
Thank you Microsoft!
来源:https://stackoverflow.com/questions/5127079/ihtmleventobjput-keycode-fails-in-ie9-rc