대다수의 주요 이벤트를 가로 채고 싶습니다. 많은 도움말을 검색했으며, this article에서 영감을 받았습니다. 내가 무슨 짓을하는 것입니다 :텍스트 뷰에 명령 필터를 추가 한 후 문제가 발생했습니다.
새로운 클래스를 생성하고 "IVsTextManagerEvents에게"모든 텍스트 뷰를 등록하는 인터페이스를 구현합니다.
public void OnRegisterView(IVsTextView pView) { CommandFilter filter = new CommandFilter(); IOleCommandTarget nextCommandTarget; pView.AddCommandFilter(filter, out nextCommandTarget); filter.NextCommandTarget = nextCommandTarget; }
우리는 우리가
protected override void Initialize() { base.Initialize(); IConnectionPointContainer textManager = (IConnectionPointContainer)GetService(typeof(SVsTextManager)); Guid interfaceGuid = typeof(IVsTextManagerEvents).GUID; textManager.FindConnectionPoint(ref interfaceGuid, out tmConnectionPoint); tmConnectionPoint.Advise(new TextManagerEventSink(), out tmConnectionCookie); }
public class CommandFilter : IOleCommandTarget
{
public IOleCommandTarget NextCommandTarget
{
get;
set;
}
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
NextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
return VSConstants.S_OK;
}
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
{
if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID)
{
switch (nCmdID)
{
case (uint)VSConstants.VSStd2KCmdID.RETURN:
MessageBox.Show("enter");
break;
}
}
NextCommandTarget.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
return VSConstants.S_OK;
}
}
대에서 olecommand 가로 챌 수있는 IOleCommandTarget을 구현할 새로운 클래스 "CommandFilter"을 추가 위의
을 준비한 후 이제 키 이벤트를 가로 챌 수 있습니다. 스트로크 키 "입력"후에 메시지 상자를 볼 수 있습니다. 내가 문서를 저장할 수 없습니다
- 이상 수행 한 후에
내 질문은 내가 CTRL + S를 쓰다 때, 즉 의미이다, 아무 일도하지 않습니다.
- 단어를 입력 할 때 명백한 지연을 볼 수 있습니다. 내 꾸러미가 뭔가를 처리하는 데 오랜 시간이 걸리는 것 같지만 위에서 볼 수 있듯이 전혀하지 않았습니다.
은 MSDN 포럼에 게시물에 대한 내 대답을 참조하십시오. http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/46b211d6-5405-40ff-99a7-360f6e1f16ef –