コード例 #1
0
        }//END ClickKey

        public static bool ClickOneKey(ushort Key_)
        {
            KEYBDINPUT k;
            INPUT      i;

            INPUT[] inputs;
            int     isize;

            k             = new KEYBDINPUT();
            k.wVk         = 0;
            k.wScan       = Key_;
            k.dwFlags     = KEYEVENTF_UNICODE;
            k.time        = 0;
            k.dwExtraInfo = (IntPtr)0;
            i             = new INPUT();
            i.type        = INPUT_KEYBOARD;
            i.ki          = k;
            inputs        = new INPUT[] { i };
            isize         = Marshal.SizeOf(i);
            SendInput(1, inputs, isize);

            //k = new KEYBDINPUT();
            //k.wVk = 0;
            //k.wScan = Key_;
            //k.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
            //k.time = 0;
            //k.dwExtraInfo = (IntPtr)0;
            //i = new INPUT();
            //i.type = INPUT_KEYBOARD;
            //i.ki = k;
            //inputs = new INPUT[] { i };
            //isize = Marshal.SizeOf(i);
            //SendInput(1, inputs, isize);



            return(true);
        }//END ClickKey
コード例 #2
0
        }//END ClickKey

        public static void GenerateKey(int vk, bool bExtended)
        {
            INPUT[] inputs = new INPUT[1]; inputs[0].type = INPUT_KEYBOARD; KEYBDINPUT kb = new KEYBDINPUT(); //{0};
            // generate down
            if (bExtended)
            {
                kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
            }
            kb.wVk = (ushort)vk; inputs[0].ki = kb;
            SendInput(1, inputs, System.Runtime.InteropServices.Marshal.SizeOf(inputs[0]));

            // generate up
            //ZeroMemory(&kb, sizeof(KEYBDINPUT));
            //ZeroMemory(&inputs,sizeof(inputs)); kb.dwFlags = KEYEVENTF_KEYUP;
            if (bExtended)
            {
                kb.dwFlags |= KEYEVENTF_EXTENDEDKEY;
            }
            kb.wVk = (ushort)vk; inputs[0].type = INPUT_KEYBOARD; inputs[0].ki = kb;
            SendInput(1, inputs, System.Runtime.InteropServices.Marshal.SizeOf(inputs[0]));
        }