2010-06-04 18 views
6

Aşağıdaki kod kullanılarak iki tuş bileşimi için genel kısayol tuşlarını yaptım. Aynı işlemi (ctrl + shift + esc) (ctrl + shift + tab) gibi üç tuş kombinasyonu için nasıl yapabilirim? iki anahtar kombinasyonu içinNasıl Yapılır? C anahtarını kullanarak üç tuş bileşimi için kısayol tuşu nasıl kaydedilir? #

Kodu: Bunun gibi

var TabShift = Keys.Tab | Keys.Shift; 
    RegisterGlobalHotKey(TabShift, USE_ALT); 


    DllImport("user32.dll")] 


    private static extern int RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk); 

    [DllImport("user32.dll")] 
    private static extern int UnregisterHotKey(IntPtr hwnd, int id); 


    private void RegisterGlobalHotKey(Keys hotkey, int modifiers) 
    { 
     try 
     { 
      // increment the hot key value - we are just identifying 
      // them with a sequential number since we have multiples 
      mHotKeyId++; 

      if (mHotKeyId > 0) 
      { 
       // register the hot key combination 
       if (RegisterHotKey(this.Handle, mHotKeyId, modifiers, Convert.ToInt16(hotkey)) == 0) 
       { 
        // tell the user which combination failed to register - 
        // this is useful to you, not an end user; the end user 
        // should never see this application run 
        MessageBox.Show("Error: " + mHotKeyId.ToString() + " - " + 
         Marshal.GetLastWin32Error().ToString(), 
         "Hot Key Registration"); 
       } 
      } 
     } 
     catch 
     { 
      // clean up if hotkey registration failed - 
      // nothing works if it fails 
      UnregisterGlobalHotKey(); 
     } 
    } 

    private void UnregisterGlobalHotKey() 
    { 
     // loop through each hotkey id and 
     // disable it 
     for (int i = 0; i < mHotKeyId; i++) 
     { 
      UnregisterHotKey(this.Handle, i); 
     } 
    } 

cevap

13

Sadece "veya" birlikte değerler olabilir:

// Alt + Shift + Tab 
RegisterGlobalHotKey(Keys.Tab, MOD_ALT | MOD_SHIFT); 

Not olduğunu MOD_ALT ve arkadaş WinUser.h içinde tanımlanan:

#define MOD_ALT   0x0001 
#define MOD_CONTROL  0x0002 
#define MOD_SHIFT  0x0004 
#define MOD_WIN   0x0008 

Bu nedenle, orada değiştiriciler için doğru değerleri ilettiğinizden emin olmanız gerekir.

+2

Aslında, "Alt + Shift + Sekme" nin mümkün olduğundan emin değilim, zira görev değiştirici tarafından zaten kullanıldığından, ancak siz bu fikri elde edersiniz ... –

0

:

Keys.Control | Keys.Shift | Keys.Tab 
İlgili konular