Hi @Pixel-ink ,Welcome to Microsoft Q&A.
You can use the functions in the user32.dll library to simulate keyboard presses.
The sample code is:
using System;
using System.Runtime.InteropServices;
namespace _6_21_x
{
internal class Program
{
[DllImport("user32.dll")]
public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
const int KEYEVENTF_EXTENDEDKEY = 0x0001;
const int KEYEVENTF_KEYUP = 0x0002;
const byte VK_LWIN = 0x5B;
const byte VK_D = 0x44;
static void Main(string[] args)
{
SendWinKeyD();
Console.ReadLine();
}
static void SendWinKeyD()
{
keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); // Press Win key
keybd_event(VK_D, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); // Press D key
keybd_event(VK_D, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); // Release D key
keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); // Release Win key
}
}
}
If there is a problem with computer performance, you can try to add Thread.Sleep(100);
between keybd_event.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.