Type a single unicode char. char: str, len(char) must equal to 1. charMode: bool, if False, the char typied is depend on the input method if a input method is on. Return int, the number of events that it successfully inserted into the keyboard or mouse input stream.
(char: str, charMode: bool = True)
| 2571 | |
| 2572 | |
| 2573 | def SendUnicodeChar(char: str, charMode: bool = True) -> int: |
| 2574 | """ |
| 2575 | Type a single unicode char. |
| 2576 | char: str, len(char) must equal to 1. |
| 2577 | charMode: bool, if False, the char typied is depend on the input method if a input method is on. |
| 2578 | Return int, the number of events that it successfully inserted into the keyboard or mouse input stream. |
| 2579 | If the function returns zero, the input was already blocked by another thread. |
| 2580 | """ |
| 2581 | if charMode: |
| 2582 | vk = 0 |
| 2583 | scan = ord(char) |
| 2584 | flag = KeyboardEventFlag.KeyUnicode |
| 2585 | else: |
| 2586 | res = ctypes.windll.user32.VkKeyScanW(ctypes.wintypes.WCHAR(char)) |
| 2587 | if (res >> 8) & 0xFF == 0: |
| 2588 | vk = res & 0xFF |
| 2589 | scan = 0 |
| 2590 | flag = 0 |
| 2591 | else: |
| 2592 | vk = 0 |
| 2593 | scan = ord(char) |
| 2594 | flag = KeyboardEventFlag.KeyUnicode |
| 2595 | return SendInput(KeyboardInput(vk, scan, flag | KeyboardEventFlag.KeyDown), |
| 2596 | KeyboardInput(vk, scan, flag | KeyboardEventFlag.KeyUp)) |
| 2597 | |
| 2598 | |
| 2599 | _SCKeys = { |
no test coverage detected