Share via


방법: 기존 바로 가기 키 유지

Visual Studio의 추가 기능은 Visual Studio 2013에서 사용되지 않습니다. 추가 기능을 VSPackage 확장으로 업그레이드하는 것이 좋습니다. 업그레이드에 대한 자세한 내용은 FAQ: VSPackage 확장으로 추가 기능 변환 을 참조하십시오.

일반적으로 명령의 바로 가기 키를 변경하면 기존 바로 가기 키는 없어집니다. 다음 예제에서는 기존 바로 가기 키를 유지하면서 명령에 두 개의 새 바로 가기 키를 바인딩하는 방법을 보여 줍니다.

명령 목록과 함께 명령의 현재 바로 가기 키를 보려면 방법: 기존 키 바인딩 보기에 설명된 대로 ListKeyBindings 예제를 실행합니다.

참고

표시되는 대화 상자와 메뉴 명령은 활성 설정이나 버전에 따라 도움말에서 설명하는 것과 다를 수 있습니다.이러한 절차는 일반 개발 설정을 사용하여 개발되었습니다.설정을 변경하려면 도구 메뉴에서 설정가져오기 및 내보내기를 클릭합니다.자세한 내용은 Visual Studio에서 개발 설정 사용자 지정을 참조하십시오.

새 바로 가기 키를 추가하고 기존 바로 가기 키를 유지하려면

  1. Visual Studio 추가 기능 마법사를 사용하여 추가 기능을 만듭니다. 프로젝트의 이름을 지정하고 확인을 클릭하여 마법사를 시작합니다.

    Visual Studio 추가 기능 마법사를 사용하는 방법에 대한 자세한 내용은 방법: 추가 기능 만들기를 참조하십시오.

  2. 프로그래밍 언어 선택 페이지에서 Visual C#을 사용하여 추가 기능 만들기를 선택하여 아래의 Visual C# 예제를 실행하거나, Visual Basic을 사용하여 추가 기능 만들기를 선택하여 Visual Basic 예제를 실행합니다.

  3. Visual Studio 추가 기능 마법사를 통해 생성된 코드의 Connect 클래스에 이 항목의 뒤에 나오는 예제 함수를 붙여넣습니다.

  4. 기본 키보드 설정의 복사본을 만들려면 C:\Program Files\Microsoft Visual Studio 10\Common7\IDE를 찾습니다.

  5. .vsk 파일 중 하나를 마우스 오른쪽 단추로 클릭한 다음 복사를 클릭합니다.

  6. 복사본을 같은 폴더에 붙여넣은 다음 이름을 바꿉니다.

  7. 바로 가기 키 목록에 새 .vsk 파일이 나타나는지 확인하려면 Visual Studio에서 도구 메뉴의 옵션을 클릭합니다.

  8. 옵션 대화 상자의 왼쪽 창에서 환경 폴더를 확장하고 키보드를 선택합니다.

    앞에서 지정한 .vsk 파일의 이름이 다음 추가 키보드 매핑 구성표 적용 목록에 나타나는지 확인합니다.

  9. 추가 기능 예제를 실행하기 전에 바로 가기 키를 **(기본값)**으로 설정해야 합니다. 이렇게 하려면 옵션 대화 상자의 키보드 창에서 다시 설정을 클릭합니다.

  10. 추가 기능 예제의 prop.Value = "<Filename.vsk>" 단계에서 <Filename.vsk>를 앞서 지정한 .vsk 파일의 이름으로 바꿉니다.

  11. 방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행에 설명된 대로 OnConnection 메서드에서 함수를 호출합니다.

  12. 추가 기능을 빌드합니다.

  13. 추가 기능을 실행하려면 도구 메뉴에서 추가 기능 관리자를 클릭하고 방금 만든 추가 기능을 선택한 다음 확인을 클릭합니다.

    File.NewFile 명령이 Ctrl+Alt+Shift+Y와 Ctrl+Alt+Shift+U 같은 새 바로 가기 키뿐 아니라 기존 바로 가기 키에도 바인딩됩니다.

예제

다음 추가 기능 예제에서는 기존 바로 가기 키를 유지하면서 명령에 두 개의 새 바로 가기 키를 바인딩하는 방법을 보여 줍니다.

Sub PreserveBindings()
    ' Adds two new key bindings while preserving the existing ones.
    Dim cmds As Commands
    Dim cmd As Command
    Dim props As EnvDTE.Properties = DTE.Properties("Environment", _
    "Keyboard")
    Dim prop As EnvDTE.Property
    Dim bindings() As Object
    Dim bindingNumber As Integer

    ' Set references to the Commands collection and the File.NewFile
    ' command.
    cmds = DTE.Commands
    cmd = cmds.Item("File.NewFile")
    ' Make a writeable copy of the default keymapping scheme.
    prop = props.Item("SchemeName")
    prop.Value = "<FileName.vsk>"
    ' Retrieve the current bindings for the command.
    bindings = cmd.Bindings
    ' Get the number of bindings for the command.
    bindingNumber = bindings.Length
    ' Add two more elements to the array to accomodate two
    ' new commands.
    ReDim Preserve bindings(bindingNumber + 1)
    ' Add the new bindings to the existing ones in the array.
    bindings(bindingNumber) = "Global::CTRL+ALT+SHIFT+Y"
    bindings(bindingNumber + 1) = "Global::CTRL+ALT+SHIFT+U"
    ' Assign the contents of the bindings array to the Bindings 
    ' property.
    cmd.Bindings = bindings
End Sub
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst, ref
 System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    PreserveBindings((_applicationObject); 
}

// Add-in example for TextSelection.FindPattern.
// Also shows usage of these methods and properties:
//    TextSelection.SelectLine
public void PreserveBindings( DTE dte ) 
{ 
    // Adds two new key bindings while preserving the existing ones.
    Commands cmds = null; 
    Command cmd = null; 
    EnvDTE.Properties props = dte.get_Properties( "Environment",
 "Keyboard"); 
    EnvDTE.Property prop = null; 
    Object[] bindings = null; 
    int bindingNumber = 0; 

    //  Set references to the Commands collection and the File.NewFile
    //  command.
    cmds = dte.Commands; 
    cmd = cmds.Item( "File.NewFile", -1 ); 
    // Make a writeable copy of the default keymapping scheme.
    prop = props.Item( "SchemeName" ); 
    prop.Value = "<FileName.vsk>"; 
    // Retrieve the current bindings for the command.
    bindings = ( ( System.Object[] )( cmd.Bindings ) ); 
    // Get the number of bindings for the command.
    bindingNumber = bindings.Length; 
    // Add two more elements to the array to accomodate two
    // new commands.
    // Create temp variable for copying values. 
    // Arrays are zero-based in C#.
    object[] temp = new object[ bindingNumber + 2 ]; 
    System.Array.Copy( bindings, temp, Math.Min( bindings.Length,
 temp.Length ) ); 
    bindings = temp; 
    // Add the new bindings to the existing ones in the array.
    bindings[ bindingNumber ] = "Global::CTRL+ALT+SHIFT+Y"; 
    bindings[ bindingNumber+1 ] = "Global::CTRL+ALT+SHIFT+U"; 
    // Assign the contents of the bindings array to the Bindings 
    // property.
    cmd.Bindings = bindings; 
}

참고 항목

작업

방법: 단일 바로 가기 키에 명령 바인딩

방법: 여러 바로 가기 키에 명령 바인딩

개념

Bindings 속성 매개 변수 형식

기타 리소스

추가 기능 명령을 키에 바인딩