Пример #1
0
        public static void Reset()
        {
            if (GUI.IsElevatedAdmin)
            {
                bool   doCheck = false;
                byte[] state   = new byte[256];

                // reset toggle buttons
                if (IsCapsLockOn)
                {
                    NM.keybd_event(NM.VK_CAPITAL, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_CAPITAL, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                    doCheck = true;
                }

                if (IsNumLockOn)
                {
                    NM.keybd_event(NM.VK_NUMLOCK, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_NUMLOCK, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                    doCheck = true;
                }

                if (IsScrollLockOn)
                {
                    NM.keybd_event(NM.VK_SCROLL, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_SCROLL, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                    doCheck = true;
                }

                if (doCheck)
                {
                    while (true)
                    {
                        GetCurrentInputState(ref state);
                        if (IsCapsLockOn == IsToggleKeyOn(state[NM.VK_CAPITAL]))
                        {
                            if (IsNumLockOn == IsToggleKeyOn(state[NM.VK_NUMLOCK]))
                            {
                                if (IsScrollLockOn == IsToggleKeyOn(state[NM.VK_SCROLL]))
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                NM.BlockInput(false);
            }

            BlockCount = 0;
        }
Пример #2
0
        public static void Block(IntPtr ParentHandle, IntPtr ControlHandle)
        {
            if (BlockCount == 0)
            {
                if (GUI.IsElevatedAdmin)
                {
                    bool doCheck = false;
                    bool Return  = NM.BlockInput(true);
                    if (!Return)
                    {
                        throw new Exception("Failed to block input");
                    }

                    byte[] state = new byte[256];


                    GetCurrentInputState(ref state);

                    //reset the global mouse states
                    if (IsMouseDown == false)
                    {
                        if (IsButtonDown(state[NM.VK_LBUTTON]))
                        {
                            NM.mouse_event(NM.MOUSEEVENTF_LEFTUP, 0, 0, 0, UIntPtr.Zero);
                            doCheck = true;
                        }

                        if (IsButtonDown(state[NM.VK_MBUTTON]))
                        {
                            NM.mouse_event(NM.MOUSEEVENTF_MIDDLEUP, 0, 0, 0, UIntPtr.Zero);
                            doCheck = true;
                        }

                        if (IsButtonDown(state[NM.VK_RBUTTON]))
                        {
                            NM.mouse_event(NM.MOUSEEVENTF_RIGHTUP, 0, 0, 0, UIntPtr.Zero);
                            doCheck = true;
                        }

                        if (IsButtonDown(state[NM.VK_XBUTTON1]))
                        {
                            NM.mouse_event(NM.MOUSEEVENTF_XUP, 0, 0, 0, new UIntPtr(1));
                            doCheck = true;
                        }

                        if (IsButtonDown(state[NM.VK_XBUTTON2]))
                        {
                            NM.mouse_event(NM.MOUSEEVENTF_XUP, 0, 0, 0, new UIntPtr(2));
                            doCheck = true;
                        }
                    }

                    // 3 is VK_CANCEL
                    if (IsButtonDown(state[NM.VK_CANCEL]))
                    {
                        NM.keybd_event(NM.VK_CANCEL, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                        NM.keybd_event(NM.VK_CANCEL, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                        doCheck = true;
                    }

                    // 7+ is non-mouse (apart from 3) and 255 seems to break things so we do till 254
                    for (byte vk = 7; vk < unchecked (255); vk++)
                    {
                        if (IsButtonDown(state[vk]))
                        {
                            NM.keybd_event(vk, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                            NM.keybd_event(vk, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                            doCheck = true;
                        }
                    }

                    //check for toggle keys
                    IsCapsLockOn = IsToggleKeyOn(state[NM.VK_CAPITAL]);
                    if (IsCapsLockOn)
                    {
                        NM.keybd_event(NM.VK_CAPITAL, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                        NM.keybd_event(NM.VK_CAPITAL, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                        doCheck = true;
                    }

                    IsNumLockOn = IsToggleKeyOn(state[NM.VK_NUMLOCK]);
                    if (IsNumLockOn)
                    {
                        NM.keybd_event(NM.VK_NUMLOCK, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                        NM.keybd_event(NM.VK_NUMLOCK, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                        doCheck = true;
                    }

                    IsScrollLockOn = IsToggleKeyOn(state[NM.VK_SCROLL]);
                    if (IsScrollLockOn)
                    {
                        NM.keybd_event(NM.VK_SCROLL, 0, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                        NM.keybd_event(NM.VK_SCROLL, 0, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                        doCheck = true;
                    }

                    if (doCheck)
                    {
                        bool ok = false;
                        while (!ok)
                        {
                            ok = true;
                            GetCurrentInputState(ref state);

                            // Check mouse button state
                            if (!IsMouseDown)
                            {
                                if (IsButtonDown(state[NM.VK_LBUTTON]) || IsButtonDown(state[NM.VK_MBUTTON]) || IsButtonDown(state[NM.VK_RBUTTON]) || IsButtonDown(state[NM.VK_XBUTTON1]) || IsButtonDown(state[NM.VK_XBUTTON2]))
                                {
                                    ok = false;
                                }
                            }

                            // Check cancel
                            if (IsButtonDown(state[NM.VK_CANCEL]))
                            {
                                ok = false;
                            }

                            // Check other keys
                            for (byte vk = 7; vk < unchecked (255); vk++)
                            {
                                if (IsButtonDown(state[vk]))
                                {
                                    ok = false;
                                    break;
                                }
                            }

                            // check toggle keys
                            if (IsToggleKeyOn(state[NM.VK_CAPITAL]) || IsToggleKeyOn(state[NM.VK_NUMLOCK]) || IsToggleKeyOn(state[NM.VK_SCROLL]))
                            {
                                ok = false;
                            }
                        }
                    }
                }
            }

            BlockCount++;
        }