I'm trying to send uppercase letters or symbols (!@# etc), using the PostMessage() function:
[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
I tried sending both shift and the letter I want to send in upper case but it doesn't seem to work:
public const uint WM_KEYUP = 0x0101;
public const uint WM_KEYDOWN = 0x100;
void function()
{
Keys key = Keys.A;
Keys shift = Keys.ShiftKey;
PostMessage(process.MainWindowHandle, WM_KEYDOWN, (IntPtr)shift, IntPtr.Zero);
PostMessage(process.MainWindowHandle, WM_KEYDOWN, (IntPtr)key, IntPtr.Zero);
PostMessage(process.MainWindowHandle, WM_KEYUP, (IntPtr)shift, IntPtr.Zero);
PostMessage(process.MainWindowHandle, WM_KEYUP, (IntPtr)key, IntPtr.Zero);
}
Edit: for those wondering: I ended up using SendInput() to send the shift key press, because apparently many games don't detect the shift key press the same way they detect other key presses that's why it didn't detect the shift key press when I tried sending it with PostMessage(), you can also use keybd_event() and SendKeys(). Note: that these methods don't send the keys to a specific process.