Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

keyboard

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

like image 354
Mohsen Avatar asked Oct 31 '22 06:10

Mohsen


1 Answers

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}");
like image 66
maulik kansara Avatar answered Nov 15 '22 06:11

maulik kansara