문제

can any body help me ? when i use the follow function to send a lower char, a to z, to a window, it work well. However, I don't know how to send a upper char, A to Z, or number char 0 to 9. I have test it many times.

def post_keys(hwnd, i):
    win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, i, 0)
    win32api.SendMessage(hwnd, win32con.WM_KEYUP, i, 0)

thans very much.

올바른 솔루션이 없습니다

다른 팁

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top