简体   繁体   中英

How to press Alt+Tab programmatically in C# in win 8

I use this code in VS 2013 in win8 for simulate press Alt+Tab, but nothing happen. i test it in win 7 and VS 2012 it's work fine.

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

private const byte VK_MENU = 0x12;
private const byte VK_TAB = 0x09;
private const int KEYEVENTF_EXTENDEDKEY = 0x01;
private const int KEYEVENTF_KEYUP = 0x02;

keybd_event(VK_MENU, 0xb8, 0, 0); //Alt Press 
keybd_event(VK_TAB, 0x8f, 0, 0); // Tab Press 
System.Threading.Thread.Sleep(70);
keybd_event(VK_TAB, 0x8f, KEYEVENTF_KEYUP, 0); // Tab Release 
keybd_event(VK_MENU, 0xb8, KEYEVENTF_KEYUP, 0); // Alt Releas

How can i solve this problem in win8? thanks

may be its too late to answer but an answered question may help other in future. Try to send key combination using SendKeys it may work for you.

SendKeys.Send("%+{TAB}");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM