2009-07-29 5 views
0

J'utilise le code ci-dessous pour désactiver les crochets de combinaison de clavier. J'ai reçu ce code pendant que je naviguais sur le net. Je veux connaître la liste des codes clés pour les touches du clavier. [LParam.vkCode == ???] S'il vous plaît me donner le lien pour cela, Merci ..où obtenir le code clé pour le crochet du clavier dans C#

namespace BlockShortcuts 

{ 

public class DisableKeys 

{ 

private delegate int LowLevelKeyboardProcDelegate(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam); 

[DllImport("user32.dll", EntryPoint = "SetWindowsHookExA", CharSet = CharSet.Ansi)] 

private static extern int SetWindowsHookEx(int idHook, LowLevelKeyboardProcDelegate lpfn, int hMod, int dwThreadId); 

[DllImport("user32.dll")] 
private static extern int UnhookWindowsHookEx(int hHook); 

[DllImport("user32.dll", EntryPoint = "CallNextHookEx", CharSet = CharSet.Ansi)] 

private static extern int CallNextHookEx(int hHook, int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam); 

const int WH_KEYBOARD_LL = 13; 

private int intLLKey; 

private struct KBDLLHOOKSTRUCT 
{ 
    public int vkCode; 
    int scanCode; 
    public int flags; 
    int time; 
    int dwExtraInfo; 
} 
private int LowLevelKeyboardProc(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam) 
{ 
    bool blnEat = false; switch (wParam) 
    { 
     case 256: 
     case 257: 
     case 260: 
     case 261: 
      //Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key       
      if (((lParam.vkCode == 9) && (lParam.flags == 32)) || 
       ((lParam.vkCode == 27) && (lParam.flags == 32)) || 
       ((lParam.vkCode == 27) && (lParam.flags == 0)) || 
       ((lParam.vkCode == 91) && (lParam.flags == 1)) || 
       ((lParam.vkCode == 92) && (lParam.flags == 1)) || 
       ((true) && (lParam.flags == 32))) 
      { 
       blnEat = true; 
      } 
      break; 
    } if (blnEat) return 1; else return CallNextHookEx(0, nCode, wParam, ref lParam); 
} 
public void DisableKeyboardHook() 
{ 
    intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, new LowLevelKeyboardProcDelegate(LowLevelKeyboardProc), System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]).ToInt32(), 0); 
} 
private void ReleaseKeyboardHook() 
{ 
    intLLKey = UnhookWindowsHookEx(intLLKey); 
} 
#endregion 
} 

} 

Répondre

5

Commencez par regarder la définition de la fonction de rappel LowLevelKeyboardProc. Puis, examinez la définition de la structure lparam. De là, vous pouvez voir que vkcode est un code clé virtuel. Il y a a list of those on MSDN as well.

EDIT: Par commentaire, lien mis à jour pour pointer vers la section Entrée de clavier Windows de MSDN plutôt que la section Entrée de clavier Windows CE de MSDN.

+0

Je recommanderais d'aller pour cette liste: http://msdn.microsoft.com/de-de/ms645540%28en-us,VS.85%29.aspx L'autre est pour Windows CE;) –

Questions connexes