ATGTestInput.Input.SendKeyboardInput C# (CSharp) Метод

SendKeyboardInput() публичный статический Метод

Inject keyboard input into the system
public static SendKeyboardInput ( Key key, bool press ) : void
key Key indicates the key pressed or released. Can be one of the constants defined in the Key enum
press bool true to inject a key press, false to inject a key release
Результат void
        public static void SendKeyboardInput( Key key, bool press )
        {
            //CASRemoval:AutomationPermission.Demand( AutomationPermissionFlag.Input );

            UnsafeNativeMethods.INPUT ki = new UnsafeNativeMethods.INPUT();
            ki.type = UnsafeNativeMethods.INPUT_KEYBOARD;
            ki.union.keyboardInput.wVk = (short) KeyInterop.VirtualKeyFromKey( key );
            ki.union.keyboardInput.wScan = (short) UnsafeNativeMethods.MapVirtualKey( ki.union.keyboardInput.wVk, 0 );
            int dwFlags = 0;
            if( ki.union.keyboardInput.wScan > 0 )
                dwFlags |= UnsafeNativeMethods.KEYEVENTF_SCANCODE;
            if( !press )
                dwFlags |= UnsafeNativeMethods.KEYEVENTF_KEYUP;
            ki.union.keyboardInput.dwFlags = dwFlags;
            if( IsExtendedKey( key ) )
            {
                ki.union.keyboardInput.dwFlags |= UnsafeNativeMethods.KEYEVENTF_EXTENDEDKEY;
            }
            ki.union.keyboardInput.time = 0;
            ki.union.keyboardInput.dwExtraInfo = new IntPtr( 0 );
            if( UnsafeNativeMethods.SendInput( 1, ref ki, Marshal.SizeOf(ki) ) == 0 )
                throw new Win32Exception(Marshal.GetLastWin32Error());
        }

Same methods

Input::SendKeyboardInput ( Key key ) : void
Input::SendKeyboardInput ( Key key, int millisecondDelay ) : void
Input::SendKeyboardInput ( string keyCombination ) : void
Input::SendKeyboardInput ( string keyCombination, int millisecondDelay ) : void