I realized that AutoIT has the functions I need, so I looked at the source file sendKeys.cpp and found the following C ++ code fragment for this function, it will be quite easy to translate it into C #:
scan = MapVirtualKey(vk, 0);
lparam = 0x00000001 | (LPARAM)(scan << 16);
if (bForceExtended == true || IsVKExtended(vk) == true)
lparam = lparam | 0x01000000;
if ( (m_nKeyMod & ALTMOD) && !(m_nKeyMod & CTRLMOD) )
PostMessage(m_hWnd, WM_SYSKEYDOWN, vk, lparam | 0x20000000);
else
PostMessage(m_hWnd, WM_KEYDOWN, vk, lparam);
MapVirtualKey
# :
public static void sendKey(IntPtr hwnd, VKeys keyCode, bool extended)
{
uint scanCode = MapVirtualKey((uint)keyCode, 0);
uint lParam;
lParam = (0x00000001 | (scanCode << 16));
if (extended)
{
lParam |= 0x01000000;
}
PostMessage(hwnd, (UInt32)WMessages.WM_KEYDOWN, (IntPtr)keyCode, (IntPtr)lParam);
lParam |= 0xC0000000;
PostMessage(hwnd, WMessages.WM_KEYUP, (uint)keyCode, lParam);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern uint MapVirtualKey(uint uCode, uint uMapType);