TextDocumentKeyPressEvents 인터페이스

키 누름에 관련된 이벤트를 정의합니다. 이 기능을 위해 이 개체를 사용합니다. 이 개체의 멤버 설명서는 TextDocumentKeyPressEventsClass를 참조하십시오.

네임스페이스:  EnvDTE80
어셈블리:  EnvDTE80(EnvDTE80.dll)

구문

‘선언
<GuidAttribute("505B7600-8FCC-487C-9E4F-C7FD0B5FB690")> _
Public Interface TextDocumentKeyPressEvents _
    Inherits _TextDocumentKeyPressEvents, _dispTextDocumentKeyPressEvents_Event
[GuidAttribute("505B7600-8FCC-487C-9E4F-C7FD0B5FB690")]
public interface TextDocumentKeyPressEvents : _TextDocumentKeyPressEvents, 
    _dispTextDocumentKeyPressEvents_Event
[GuidAttribute(L"505B7600-8FCC-487C-9E4F-C7FD0B5FB690")]
public interface class TextDocumentKeyPressEvents : _TextDocumentKeyPressEvents, 
    _dispTextDocumentKeyPressEvents_Event
[<GuidAttribute("505B7600-8FCC-487C-9E4F-C7FD0B5FB690")>]
type TextDocumentKeyPressEvents =  
    interface
        interface _TextDocumentKeyPressEvents
        interface _dispTextDocumentKeyPressEvents_Event
    end
public interface TextDocumentKeyPressEvents extends _TextDocumentKeyPressEvents, _dispTextDocumentKeyPressEvents_Event

TextDocumentKeyPressEvents 형식에서는 다음과 같은 멤버를 노출합니다.

메서드

  이름 설명
Public 메서드 add_AfterKeyPress 인프라입니다. Microsoft 내부용입니다. (_dispTextDocumentKeyPressEvents_Event에서 상속됨)
Public 메서드 add_BeforeKeyPress 인프라입니다. Microsoft 내부용입니다. (_dispTextDocumentKeyPressEvents_Event에서 상속됨)
Public 메서드 remove_AfterKeyPress 인프라입니다. Microsoft 내부용입니다. (_dispTextDocumentKeyPressEvents_Event에서 상속됨)
Public 메서드 remove_BeforeKeyPress 인프라입니다. Microsoft 내부용입니다. (_dispTextDocumentKeyPressEvents_Event에서 상속됨)

위쪽

이벤트

  이름 설명
Public 이벤트 AfterKeyPress 인프라입니다. Microsoft 내부용입니다. (_dispTextDocumentKeyPressEvents_Event에서 상속됨)
Public 이벤트 BeforeKeyPress 인프라입니다. Microsoft 내부용입니다. (_dispTextDocumentKeyPressEvents_Event에서 상속됨)

위쪽

예제

이 예제에서는 작은 문자열 사전을 만들고 BeforeKeyPress 이벤트에 연결한 다음 이 사전을 사용하여 색상을 나타내는 몇 가지 영어 단어를 해당 16진수 표현으로 자동 변환합니다. Connect.cs 파일의 코드를 아래에 있는 예제 코드로 바꿉니다. Visual Studio IDE(통합 개발 환경)에서 이 추가 기능을 실행하고 텍스트 문서를 엽니다. 텍스트 문서에 "red", "green" 또는 "blue"를 입력하면 메서드를 캡처하는 이벤트를 통해 텍스트가 각각 "#ff0000", "#00cc00" 또는 "#0000ff"로 변환됩니다. 자동화 예제를 실행하는 방법에 대한 자세한 내용은 방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행을 참조하십시오.

namespace myAddin
{
  using System;
  using Microsoft.VisualStudio.CommandBars;
  using Extensibility;
  using EnvDTE;
  using EnvDTE80;
  using System.Windows.Forms;
  public class Connect : Object, IDTExtensibility2
  {
  public Connect()
  {
  }
  public void OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
  {
      _applicationObject = (DTE2)application;
      _addInInstance = (AddIn)addInInst;
      // Create a small string dictionary with keys and corresponding
      // values.
      myStringDictionary = new
 System.Collections.Specialized.StringDictionary();
      myStringDictionary.Add("red", "#ff0000");
      myStringDictionary.Add("green", "#00cc00");
      myStringDictionary.Add("blue", "#0000ff");
      EnvDTE80.Events2 events =
 (EnvDTE80.Events2)_applicationObject.Events;
      textDocKeyEvents =
 (EnvDTE80.TextDocumentKeyPressEvents)
events.get_TextDocumentKeyPressEvents(null);
      // Connect to the BeforeKeyPress delegate exposed from the
      // TextDocumentKeyPressEvents object retrieved above.
      textDocKeyEvents.BeforeKeyPress +=new
 _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler
(BeforeKeyPress);
  }
  public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
  {
      if (textDocKeyEvents != null)
      {
          textDocKeyEvents.BeforeKeyPress -= new 
_dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler
(BeforeKeyPress);
      }
  }
  public void OnAddInsUpdate(ref Array custom)
  {
  }
  public void OnStartupComplete(ref Array custom)
  {
  }
  public void OnBeginShutdown(ref Array custom)
  {
  }
  void BeforeKeyPress(string Keypress, EnvDTE.TextSelection Selection,
 bool InStatementCompletion, ref bool CancelKeypress)
  {
  if ((Keypress == " ") || (Keypress == "\t"))
      {
          EditPoint ep = Selection.ActivePoint.CreateEditPoint();
          EditPoint sp = ep.CreateEditPoint();
          sp.CharLeft(1);
          while (true)
          {
              string txt = sp.GetText(ep);
              if (myStringDictionary.ContainsKey(txt))
              {
                  sp.Delete(txt.Length);
                  sp.Insert(myStringDictionary[txt]);
                  CancelKeypress = true;
                  return;
              }
          sp.CharLeft(1);
          if ((ep.Line != sp.Line) || ((ep.DisplayColumn == 1) 
&& (ep.Line == 1)))
              break;
          }
       }
  }
  private DTE2 _applicationObject;
  private AddIn _addInInstance;
  private EnvDTE80.TextDocumentKeyPressEvents textDocKeyEvents;
  System.Collections.Specialized.StringDictionary myStringDictionary;
  }
}

참고 항목

참조

EnvDTE80 네임스페이스