7
votes

Comment puis-je désactiver la clé Windows en C #?

Comment puis-je désactiver ou verrouiller le bouton Windows?


2 commentaires

définitivement ou juste pendant que votre programme est en cours d'exécution?


Juste le bouton Windows ou trucs comme CTRL + ESC aussi?


4 Réponses :


4
votes

Vous avez besoin d'un crochet de clavier. Commence quelque part comme ceci: xxx

et continuer comme ceci: xxx

et pour plus de détails: http://www.codeproject.com/kb/winsdk/antoniowinlock.aspx


0 commentaires

1
votes

En supposant que vous souhaitiez désactiver la touche Windows permanente et non seulement lorsque votre code est au centre, vous pouvez le faire en modifiant le registre comme suit:

pour désactiver : Ajoutez une nouvelle reg_binary valeur appelée " Scancode mappe " à " HKEY_LOCAL_ Machine \ System \ CurrentControlset \ Control \ Mise en page " avec une valeur de données de " 000000000000000003000000000000000B000005CE000000000 "

pour activer : Supprimer la carte " Scancode mappe " Valeur entièrement du registre.


1 commentaires

+1, merci pour cela. Je ne serais pas heureux avec le gars qui détruisait mon clavier cependant.



3
votes
    /// <summary>
    /// Security routines related to the Windows Key on a standard personal computer Keyboard
    /// </summary>
    public static class WindowsKey {
        /// <summary>
        /// Disables the Windows Key
        /// </summary>
        /// <remarks>May require the current user to logoff or restart the system</remarks>
        public static void Disable() {
            RegistryKey key = null;
            try {
                key = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Keyboard Layout", true);
                byte[] binary = new byte[] { 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x03, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x5B, 
                    0xE0, 
                    0x00, 
                    0x00, 
                    0x5C, 
                    0xE0, 
                    0x00, 
                    0x00, 
                    0x00, 
                    0x00 
                };
                key.SetValue("Scancode Map", binary, RegistryValueKind.Binary);
            }
            catch (System.Exception ex) {
                Debug.Assert(false, ex.ToString());
            }
            finally {
                key.Close();
            }
        }

        /// <summary>
        /// Enables the Windows Key
        /// </summary>
        /// <remarks>May require the current user to logoff or restart the system</remarks>
        public static void Enable() {
            RegistryKey key = null;
            try {
                key = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Keyboard Layout", true);
                key.DeleteValue("Scancode Map", true);
            }
            catch (System.Exception ex) {
                Debug.Assert(false, ex.ToString());
            }
            finally {
                key.Close();
            }
        }
    }

1 commentaires

Demander l'accès au registre n'est pas autorisé à afficher une solution.



6
votes

L'utilisation des hameçons Windows est beaucoup plus propre que de modifier le registre. En outre, parfois, les gens ont configuré des cartes de scancode personnalisées de leur propre et la répandle n'est pas une chose très gentille à faire.

Pour utiliser les fonctions de crochet de la clé Windows, vous devez dllimport quelques fonctions Winapi: P>

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetModuleHandle(string lpModuleName);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetWindowsHookEx(int idHook, HookHandlerDelegate lpfn, IntPtr hMod, uint dwThreadId);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWindowsHookEx(IntPtr hhk);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode); 


0 commentaires