コード例 #1
0
ファイル: KeyboardHook.cs プロジェクト: fritterhoff/VncSharp
        private static int OnKey(int msg, NativeMethods.KBDLLHOOKSTRUCT key)
        {
            var result = 0;

            foreach (var notificationEntry in NotificationEntries)
            {
                // It error code is Null, have to ignore the exception
                // For some unknow raison, sometime GetFocuseWindows throw an exception
                // Mainly when the station is unlocked, or after an admin password is asked
                try
                {
                    if (GetFocusWindow() != notificationEntry.WindowHandle || notificationEntry.KeyCode != key.vkCode)
                    {
                        continue;
                    }
                    var modifierKeys = GetModifierKeyState();
                    if (!ModifierKeysMatch(notificationEntry.ModifierKeys, modifierKeys))
                    {
                        continue;
                    }

                    var wParam = new IntPtr(msg);
                    var lParam = new HookKeyMsgData
                    {
                        KeyCode      = key.vkCode,
                        ModifierKeys = modifierKeys,
                        WasBlocked   = notificationEntry.Block
                    };

                    if (!PostMessage(notificationEntry.WindowHandle, HookKeyMsg, wParam, lParam))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    if (notificationEntry.Block)
                    {
                        result = 1;
                    }
                }
                catch (Win32Exception e)
                {
                    if (e.NativeErrorCode != 0)
                    {
                        throw;
                    }
                }
            }

            return(result);
        }
コード例 #2
0
ファイル: KeyboardHook.cs プロジェクト: xalauc/dRemote
        private static int OnKey(Int32 msg, Win32.KBDLLHOOKSTRUCT key)
        {
            var result = 0;

            foreach (var notificationEntry in NotificationEntries)
            {
                try
                {
                    if (GetFocusWindow() == notificationEntry.WindowHandle && notificationEntry.KeyCode == key.vkCode)
                    {
                        var modifierKeys = GetModifierKeyState();
                        if (!ModifierKeysMatch(notificationEntry.ModifierKeys, modifierKeys))
                        {
                            continue;
                        }

                        var wParam = new IntPtr(msg);
                        var lParam = new HookKeyMsgData
                        {
                            KeyCode      = key.vkCode,
                            ModifierKeys = modifierKeys,
                            WasBlocked   = notificationEntry.Block,
                        };

                        if (!PostMessage(notificationEntry.WindowHandle, HookKeyMsg, wParam, lParam))
                        {
                            throw new Win32Exception(Marshal.GetLastWin32Error());
                        }

                        if (notificationEntry.Block)
                        {
                            result = 1;
                        }
                    }
                }
                catch { }
            }

            return(result);
        }
コード例 #3
0
 private static extern bool PostMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, HookKeyMsgData lParam);
コード例 #4
0
ファイル: KeyboardHook.cs プロジェクト: kmscode/VncSharpNG
        private static int OnKey(Int32 msg, Win32.KBDLLHOOKSTRUCT key)
        {
            var result = 0;

            foreach (var notificationEntry in NotificationEntries)
                if (GetFocusWindow() == notificationEntry.WindowHandle && notificationEntry.KeyCode == key.vkCode)
                {
                    var modifierKeys = GetModifierKeyState();
                    if (notificationEntry.ModifierKeys != 0 && (modifierKeys & notificationEntry.ModifierKeys) == 0) continue;

                    var wParam = new IntPtr(msg);
                    var lParam = new HookKeyMsgData
                    {
                        KeyCode = key.vkCode,
                        ModifierKeys = modifierKeys,
                        WasBlocked = notificationEntry.Block,
                    };

                    if (!PostMessage(notificationEntry.WindowHandle, HookKeyMsg, wParam, lParam))
                        throw new Win32Exception(Marshal.GetLastWin32Error());

                    if (notificationEntry.Block) result = 1;
                }

            return result;
        }
コード例 #5
0
ファイル: KeyboardHook.cs プロジェクト: kmscode/VncSharpNG
 public static extern bool PostMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, HookKeyMsgData lParam);