Пример #1
0
STDMETHODIMP TextService::OnKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pfEaten) {
	// Some applications do not trigger OnTestKeyDown()
	// So we need to test it again here! Windows TSF sucks!
	if(isKeyboardDisabled(pContext) || !isKeyboardOpened())
		*pfEaten = FALSE;
	else {
		KeyEvent keyEvent(WM_KEYDOWN, wParam, lParam);
		*pfEaten = (BOOL)filterKeyDown(keyEvent);
		if(*pfEaten) { // we want to eat the key
			HRESULT sessionResult;
			// ask TSF for an edit session. If editing is approved by TSF,
			// KeyEditSession::DoEditSession will be called, which in turns
			// call back to TextService::doKeyEditSession().
			// So the real key handling is relayed to TextService::doKeyEditSession().
			KeyEditSession* session = new KeyEditSession(this, pContext, keyEvent);

			// We use TF_ES_SYNC here, so the request becomes synchronus and blocking.
			// KeyEditSession::DoEditSession() and TextService::doKeyEditSession() will be
			// called before RequestEditSession() returns.
			pContext->RequestEditSession(clientId_, session, TF_ES_SYNC|TF_ES_READWRITE, &sessionResult);
			*pfEaten = session->result_; // tell TSF if we handled the key
			session->Release();
		}
	}
	return S_OK;
}
Пример #2
0
STDMETHODIMP TextService::OnTestKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pfEaten) {
	if(isKeyboardDisabled(pContext) || !isKeyboardOpened())
		*pfEaten = FALSE;
	else {
		KeyEvent keyEvent(WM_KEYUP, wParam, lParam);
		HRESULT sessionResult;
		KeyEditSession* session = new KeyEditSession(this, pContext, keyEvent, true);
		pContext->RequestEditSession(clientId_, session, TF_ES_SYNC | TF_ES_READWRITE, &sessionResult);
		*pfEaten = session->result_; // tell TSF if we handled the key
		session->Release();
	}
	return S_OK;
}
Пример #3
0
STDMETHODIMP TextService::OnKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pfEaten) {
	// Some applications do not trigger OnTestKeyDown()
	// So we need to test it again here! Windows TSF sucks!
	if(isKeyboardDisabled(pContext) || !isKeyboardOpened())
		*pfEaten = FALSE;
	else {
		KeyEvent keyEvent(WM_KEYUP, wParam, lParam);
		HRESULT sessionResult;
		KeyEditSession* session = new KeyEditSession(this, pContext, keyEvent, false);
		pContext->RequestEditSession(clientId_, session, TF_ES_SYNC|TF_ES_READWRITE, &sessionResult);
		*pfEaten = session->result_; // tell TSF if we handled the key
		session->Release();
	}
	return S_OK;
}