Пример #1
0
        private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN))
            {
                // Cast lParam into our structure
                KBHookStruct keypress = (KBHookStruct)Marshal.PtrToStructure(lParam, typeof(KBHookStruct));

                //  Console.WriteLine("ScanCode: {0}, Extended: {1}, KeyCode: {2}, Name: {3}",
                //  keypress.Scancode, keypress.Extended, keypress.VirtualKeyCode, AppController.GetKeyName(keypress.Scancode, keypress.Extended));

                if (keypress.Scancode == 541)
                {
                    // Right Alt, at least on my Dell SK-8115 keyboard
                    // Console.WriteLine("Fixing Dell's Right Alt keyboard bug");

                    keypress.Scancode = 56;
                    keypress.KeyFlags = 1;
                }

                if (keypress.VirtualKeyCode == 19)
                {
                    // Pause. This doesn't capture well - it's extended value is 225
                    // rather than 224, so

                    keypress.Scancode = 29;
                    keypress.KeyFlags = 2;
                }

                // Some keyboards report Num Lock as having the extended bit set
                // on keypress, but that doesn't work in a mapping.
                if (keypress.Scancode == 69 && keypress.Extended == 224)
                {
                    // The Keyboard lies.
                    keypress.Extended = 0;
                }

                // Raise the event:
                if (KeyPressed != null)
                {
                    KeyMapperKeyPressedEventArgs e = new KeyMapperKeyPressedEventArgs(keypress);
                    KeyPressed(new object(), e);
                }

                if (_suppress)
                {
                    // Return 1 to suppress the keypress.
                    return((IntPtr)1);
                }
            }
            return(NativeMethods.CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
Пример #2
0
 // Constructor
 public KeyMapperKeyPressedEventArgs(KBHookStruct key)
 {
     _key = key;
 }
Пример #3
0
 // Constructor
 public KeyMapperKeyPressedEventArgs(KBHookStruct key)
 {
     _key = key;
 }