예제 #1
0
        public void SetKeySendInputDX2(ushort keyCode, bool keyDown)
        {
            Keyboard.INPUT AKINPUT = new Keyboard.INPUT();
            AKINPUT.type = (uint)Keyboard.Win32.INPUT_KEYBOARD;

            AKINPUT.ki.wScan = keyCode;// 0;
            AKINPUT.ki.time  = 0;

            if (keyDown)
            {
                AKINPUT.ki.dwFlags = (ushort)Keyboard.dwFlgsSI.KEYDOWN | (ushort)Keyboard.dwFlgsSI.SCANCODE;
            }
            else
            {
                AKINPUT.ki.dwFlags = (ushort)Keyboard.dwFlgsSI.KEYUP | (ushort)Keyboard.dwFlgsSI.SCANCODE;
            }


            AKINPUT.type = 1;// (uint)Keyboard.Win32.INPUT_KEYBOARD;
            //AKINPUT.ki.wVk = (UInt16)keyCode;
            AKINPUT.ki.dwExtraInfo = IntPtr.Zero;
            AKINPUT.ki.time        = 0;


            Keyboard.SendInput(1, ref AKINPUT, Marshal.SizeOf(AKINPUT));
        }
예제 #2
0
        public void SetKeySendInput(ushort keyCode, bool keyDown)
        {
            if (SetKeySendInputDX(keyCode, keyDown))
            {
                return;
            }

            Keyboard.INPUT AKINPUT = new Keyboard.INPUT();
            AKINPUT.type = (uint)Keyboard.Win32.INPUT_KEYBOARD;

            AKINPUT.ki.wScan = 0;
            AKINPUT.ki.time  = 0;
            AKINPUT.ki.wVk   = keyCode;

            if (keyDown)
            {
                AKINPUT.ki.dwFlags = 0;
            }
            else
            {
                AKINPUT.ki.dwFlags = (ushort)Keyboard.dwFlgsSI.KEYUP;
            }


            Keyboard.SendInput(1, ref AKINPUT, Marshal.SizeOf(new Keyboard.INPUT()));
        }
예제 #3
0
        public bool SetKeySendInputDX(ushort keyCode, bool keyDown)
        {
            Keyboard.INPUT AKINPUT = new Keyboard.INPUT();

            AKINPUT.ki.wScan = 0;

            bool succesedSearch = false;

            for (int i = 0; i < AVKCodes.CounterCodes; i++)
            {
                if (ushort.Parse(AVKCodes.Codes[i, 1], NumberStyles.HexNumber) == keyCode)
                {
                    for (int i1 = 0; i1 < AVKCodes.CounterCodesDx; i1++)
                    {
                        if (AVKCodes.Codes[i, 0] == AVKCodes.CodesDx[i1, 0])
                        {
                            AKINPUT.ki.wScan = ushort.Parse(AVKCodes.CodesDx[i1, 1]);
                            succesedSearch   = true;
                            break;
                        }
                    }
                }
            }

            if (succesedSearch)
            {
                if (keyDown)
                {
                    AKINPUT.ki.dwFlags = 0;
                }
                else
                {
                    AKINPUT.ki.dwFlags  = (ushort)Keyboard.dwFlgsSI.SCANCODE;
                    AKINPUT.ki.dwFlags += (ushort)Keyboard.dwFlgsSI.KEYUP;
                }

                AKINPUT.type           = (uint)Keyboard.Win32.INPUT_KEYBOARD;
                AKINPUT.ki.wVk         = (UInt16)keyCode;
                AKINPUT.ki.dwExtraInfo = IntPtr.Zero;
                AKINPUT.ki.time        = 0;


                Keyboard.SendInput(1, ref AKINPUT, Marshal.SizeOf(new Keyboard.INPUT()));

                return(true);
            }
            else
            {
            } return(false);
        }