Virtual-key code 0x41
represents the "A" key itself, not a specific case of the letter "A". If the Shift key is not currently pressed, it corresponds to lowercase "a". If the Shift key is pressed, it corresponds to uppercase "A".
For a letter to appear as uppercase, you have to send a first WM_KEYDOWN
message with virtual-key code VK_SHIFT
, then send another WM_KEYDOWN
message with the letter's virtual-key code.
So, your code should look like this:
def post_keys(hwnd, i):
win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, wincon.VK_SHIFT, 0)
win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, i, 0)
win32api.SendMessage(hwnd, win32con.WM_KEYUP, i, 0)
win32api.SendMessage(hwnd, win32con.WM_KEYUP, wincon.VK_SHIFT, 0)
The full list of Virtual-key codes can be found at this MSDN page.
Remember they represent physical keyboard keys, so when you are unsure which code to send, just look at your keyboard to see how you would type a specific character. Keep in mind that the actual characters the keycodes are translated to will vary based on your selected keyboard layout.
For example, with the EN_US keyboard layout, to send "%", you would first send VK_SHIFT
, then 0x35
(the "5" key).