I am trying to send a "TAB" key press, wait 2 secs, then send an "ENTER" key press, but it is not working.
Here is what I tried.
Add-Type -ReferencedAssemblies System.Windows.Forms -UsingNamespace System.Windows.Forms -Namespace demo -Name SendKeyExt -MemberDefinition @'
[DllImport("user32.dll")]
private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
private const int KEYEVENTF_EXTENDEDKEY = 1;
private const int KEYEVENTF_KEYUP = 2;
public static void SendKeysWithWinKey(string keys = null) {
keybd_event((byte) Keys.LWin, 0, KEYEVENTF_EXTENDEDKEY, 0);
if (!String.IsNullOrEmpty(keys)) { SendKeys.SendWait(keys.ToLowerInvariant()); }
keybd_event((byte) Keys.LWin, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
'@
[demo.SendKeyExt]::SendKeysWithWinKey('{TAB}')
sleep -Seconds 2
[demo.SendKeyExt]::SendKeysWithWinKey('ENTER')
CodePudding user response:
Does this work for you?
$vb = New-Object -ComObject wscript.Shell
$vb.SendKeys('{TAB}')
Start-Sleep -Seconds 2
$vb.SendKeys('~')