Skip to content

Commit 849570e

Browse files
fix send_chr for windows
1 parent 321b3f7 commit 849570e

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

display_server_interactions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
OSNotSupportedError as __OSNotSupportedError
1515
)
1616

17-
__version__ = "0.0.dev9"
17+
__version__ = "0.0.dev10"
1818
__author__ = "Commandcracker"
1919

2020
__os_name = __system().lower()

display_server_interactions/windows.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"""
4343
SRCCOPY = 0x00CC0020
4444
WM_CHAR = 0x0102
45-
45+
WM_KEYDOWN = 0x0100
46+
WM_KEYUP = 0x0101
4647
# pylint: disable=too-few-public-methods
4748

4849

@@ -149,7 +150,38 @@ def get_image(self, geometry: Optional[Box] = None):
149150
return img
150151

151152
def send_chr(self, character: chr) -> None:
152-
user32.PostMessageW(self.window, WM_CHAR, ord(character), 0)
153+
vk_map = {
154+
"return": 0x0D,
155+
"tab": 0x09,
156+
"shift_l": 0xA0,
157+
"shift_r": 0xA1,
158+
"control_r": 0x11,
159+
"control_r": 0x11,
160+
"alt_l": 0x12,
161+
"alt_r": 0x12,
162+
"pause": 0x13,
163+
"caps_lock": 0x14,
164+
"escape": 0x1B,
165+
"space": 0x20,
166+
"prior": 0x21,
167+
"next": 0x22,
168+
"end": 0x23,
169+
"home": 0x24,
170+
"left": 0x25,
171+
"up": 0x26,
172+
"right": 0x27,
173+
"down": 0x28,
174+
"print": 0x2C,
175+
"insert": 0x2D,
176+
"delete": 0x2E
177+
}
178+
179+
vk = vk_map.get(character.lower())
180+
if vk is None:
181+
user32.PostMessageW(self.window, WM_CHAR, ord(character), 0)
182+
else:
183+
user32.PostMessageW(self.window, WM_KEYDOWN, vk, 0)
184+
user32.PostMessageW(self.window, WM_KEYUP, vk, 0)
153185

154186
def send_str(self, string: str) -> None:
155187
for character in string:

0 commit comments

Comments
 (0)