0

I want to call the Switch language options on Windows, basically pressing the key ALT + SHIFT from C#. I read the answer from here How to start windows "run" dialog from C#

This is what I have tried so far

//KeyboardSend.KeyDown(Keys.Alt);
//KeyboardSend.KeyDown(Keys.LShiftKey);
//KeyboardSend.KeyDown(Keys.Alt);
//KeyboardSend.KeyDown(Keys.LShiftKey);

Also

SendKeys.Send("%+")

If you press ALT + SHIFT you will understand what I'm trying to achive

Rand Random
  • 7,300
  • 10
  • 40
  • 88

1 Answers1

1

This is how I solve this issue, following the link on my question

static class KeyboardSend
{
   [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 KeyDown(Keys vKey)
   {
       keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY, 0);
   }

   public static void KeyUp(Keys vKey)
   {
       keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
   }
}

Then calling like this:

KeyboardSend.KeyDown(Keys.LWin);
KeyboardSend.KeyDown(Keys.R);
KeyboardSend.KeyUp(Keys.R);
KeyboardSend.KeyUp(Keys.LWin);
Vinod Srivastav
  • 3,644
  • 1
  • 27
  • 40