Compartilhar via


Interface TextDocumentKeyPressEvents

Define os eventos associados a um pressionamento de tecla. Usar esse objeto para a funcionalidade e consulte TextDocumentKeyPressEventsClass para obter a documentação de membro deste objeto.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (em EnvDTE80.dll)

Sintaxe

'Declaração
<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

O tipo TextDocumentKeyPressEvents expõe os membros a seguir.

Métodos

  Nome Descrição
Método público add_AfterKeyPress Infraestrutura. Somente para uso interno da Microsoft. (Herdado de _dispTextDocumentKeyPressEvents_Event.)
Método público add_BeforeKeyPress Infraestrutura. Somente para uso interno da Microsoft. (Herdado de _dispTextDocumentKeyPressEvents_Event.)
Método público remove_AfterKeyPress Infraestrutura. Somente para uso interno da Microsoft. (Herdado de _dispTextDocumentKeyPressEvents_Event.)
Método público remove_BeforeKeyPress Infraestrutura. Somente para uso interno da Microsoft. (Herdado de _dispTextDocumentKeyPressEvents_Event.)

Superior

Eventos

  Nome Descrição
Evento público AfterKeyPress Infraestrutura. Somente para uso interno da Microsoft. (Herdado de _dispTextDocumentKeyPressEvents_Event.)
Evento público BeforeKeyPress Infraestrutura. Somente para uso interno da Microsoft. (Herdado de _dispTextDocumentKeyPressEvents_Event.)

Superior

Exemplos

Este exemplo cria um dicionário de cadeia de caracteres pequenos e o usa automaticamente converter algumas palavras em inglês para as cores de suas representações hexadecimais conectando-se para um BeforeKeyPress evento. Substitua o código no arquivo Connect. cs com o código de exemplo abaixo. Executar esse suplemento e abrir um documento de texto na Visual Studio o ambiente de desenvolvimento integrado (IDE). No texto do documento, digite "vermelho", "green" ou "blue" para ver o método de captura de evento para traduzir o texto "# ff0000", "# 00cc00" e "# 0000ff", respectivamente. Para obter mais informações sobre como executar os exemplos de automação, consulte Como compilar e executar os exemplos de código do modelo de objeto Automation.

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;
  }
}

Consulte também

Referência

Namespace EnvDTE80