2010-05-20 2 views
2

비활성화하는 방법 + ⇧Shift + ↹Tab C#을 사용 하시겠습니까? Alt + ↹Tab 두 개의 매개 변수 만 가져 오는 기능을 사용 중지했습니다. 그러나 3 개의 중요한 치기를 무능하게하기 위하여?C#을 사용하여 Alt + Shift + Tab을 비활성화하는 방법은 무엇입니까?

나는 두 개의 키 스트로크 조합을 비활성화하려면 내 코드가 필요하다. 나는 캠에 게시한다. 그러나 그것은 아주 크다.

RegisterGlobalHotKey(Keys.Tab, USE_ALT); 

방법 세 가지 매개 변수 [탭 Alt 키, Shift 키를,] 통과, + ↹Tab 내가 이렇게 Alt를 사용하지 않으려면?

public sealed class KeyboardHook : IDisposable 
{ 
    // Registers a hot key with Windows. 
    [DllImport("user32.dll")] 
    private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk); 
    // Unregisters the hot key with Windows. 
    [DllImport("user32.dll")] 
    private static extern bool UnregisterHotKey(IntPtr hWnd, int id); 

    /// <summary> 
    /// Represents the window that is used internally to get the messages. 
    /// </summary> 
    private class Window : NativeWindow, IDisposable 
    { 
     private static int WM_HOTKEY = 0x0312; 

     public Window() 
     { 
      // create the handle for the window. 
      try 
      { 
       this.CreateHandle(new CreateParams()); 
      } 
      catch (Exception ex) 
      { 
       ExceptionHandler.writeToLogFile(System.Environment.NewLine + "Target : " + ex.TargetSite.ToString() + System.Environment.NewLine + "Message : " + ex.Message.ToString() + System.Environment.NewLine + "Stack : " + ex.StackTrace.ToString()); 
      } 
     } 

     /// <summary> 
     /// Overridden to get the notifications. 
     /// </summary> 
     /// <param name="m"></param> 
     protected override void WndProc(ref Message m) 
     { 
      try 
      { 
       base.WndProc(ref m); 

       // check if we got a hot key pressed. 
       if (m.Msg == WM_HOTKEY) 
       { 
        // get the keys. 
        Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); 
        ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF); 

        // invoke the event to notify the parent. 
        if (KeyPressed != null) 
         KeyPressed(this, new KeyPressedEventArgs(modifier, key)); 
       } 
      } 
      catch (Exception ex) 
      { 
       ExceptionHandler.writeToLogFile(System.Environment.NewLine + "Target : " + ex.TargetSite.ToString() + System.Environment.NewLine + "Message : " + ex.Message.ToString() + System.Environment.NewLine + "Stack : " + ex.StackTrace.ToString()); 
      } 
     } 

     public event EventHandler<KeyPressedEventArgs> KeyPressed; 

     #region IDisposable Members 

     public void Dispose() 
     { 
      this.DestroyHandle(); 
     } 

     #endregion 
    } 

    private Window _window = new Window(); 
    private int _currentId; 

    public KeyboardHook() 
    { 
     try 
     { 
      // register the event of the inner native window. 
      _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) 
      { 
       if (KeyPressed != null) 
        KeyPressed(this, args); 
      }; 
     } 
     catch (Exception ex) 
     { 
      ExceptionHandler.writeToLogFile(System.Environment.NewLine + "Target : " + ex.TargetSite.ToString() + System.Environment.NewLine + "Message : " + ex.Message.ToString() + System.Environment.NewLine + "Stack : " + ex.StackTrace.ToString()); 
     } 
    } 

    /// <summary> 
    /// Registers a hot key in the system. 
    /// </summary> 
    /// <param name="modifier">The modifiers that are associated with the hot key.</param> 
    /// <param name="key">The key itself that is associated with the hot key.</param> 
    public void RegisterHotKey(ModifierKeys modifier, Keys key) 
    { 
     try 
     { 
      // increment the counter. 
      _currentId = _currentId + 1; 

      // register the hot key. 
      if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key)) 
       throw new InvalidOperationException("Couldn’t register the hot key."); 
     } 
     catch (Exception ex) 
     { 
      ExceptionHandler.writeToLogFile(System.Environment.NewLine + "Target : " + ex.TargetSite.ToString() + System.Environment.NewLine + "Message : " + ex.Message.ToString() + System.Environment.NewLine + "Stack : " + ex.StackTrace.ToString()); 
     } 
    } 

    /// <summary> 
    /// A hot key has been pressed. 
    /// </summary> 
    public event EventHandler<KeyPressedEventArgs> KeyPressed; 

    #region IDisposable Members 

    public void Dispose() 
    { 
     // unregister all the registered hot keys. 
     for (int i = _currentId; i > 0; i--) 
     { 
      UnregisterHotKey(_window.Handle, i); 
     } 

     // dispose the inner native window. 
     _window.Dispose(); 
    } 

    #endregion 
} 

/// <summary> 
/// Event Args for the event that is fired after the hot key has been pressed. 
/// </summary> 
public class KeyPressedEventArgs : EventArgs 
{ 
    private ModifierKeys _modifier; 
    private Keys _key; 

    internal KeyPressedEventArgs(ModifierKeys modifier, Keys key) 
    { 
     _modifier = modifier; 
     _key = key; 
    } 

    public ModifierKeys Modifier 
    { 
      get { return _modifier; } 
     } 

     public Keys Key 
     { 
      get { return _key; } 
     } 
    } 

    /// <summary> 
    /// The enumeration of possible modifiers. 
    /// </summary> 
    [Flags] 
    public enum ModifierKeys : uint 
    { 
     Alt = 1, 
     Control = 2, 
     Shift = 4, 
     Win = 8 
    } 
+8

당신이 원하는 것이 왜에? 그것이 내가 의심하는 것이라면, Win + Tab, Win + Shift + Tab, Alt + Esc, Alt + Shift + Esc, Ctrl + Esc, Ctrl + Pause, Win + D, Win + M ... 처리 했습니까? 너무? (기록을 위해 : 사용자가 응용 프로그램을 떠나기 위해 아무 것도하지 못하게하는 키오스크 응용 프로그램을 원한다고 생각합니다.) 그런 경우에는 단순히 사용자에게 키보드를 제공하지 말 것을 제안합니다. – Joey

+1

그건 좋은거야 :) – Anuya

+0

이랬어 : var TabShift = Keys.Tab | 열쇠. 쉬프트; RegisterGlobalHotKey (TabShift, USE_ALT); – Anuya

답변

2

당신은 2 개의 매개 변수를 취하는 함수를 사용했지만 그것이 어떤 기능인지는 언급하지 않았다. 어쨌든 Keys.ShiftKeys.Alt은 변경자 키이므로 "Alt"를 전달하는 모든 항목을 비트 시프트하거나 "Shift"를 사용해야 할 수도 있습니다.

WPF에서

등이 될 것이다 뭔가 :

var altShift = Keys.Alt | Keys.Shift; 
+0

두 개의 매개 변수에 대해 잘 작동하는 위의 코드를 찾으십시오. 지금 세 가지 매개 변수를 사용하고 싶습니다. – Anuya

+0

좋아요, 그래서 제가 말했듯이 ... 현재 ModifierKeys.Alt를 전달하고있는 곳에서 ModifierKeys.Alt | ModifierKeys.Shift를 대신 전달할 것입니다. – Josh

+0

시도, 그것 dosent 작업! – Anuya

관련 문제