Skip to content

Commit

Permalink
fix send_chr for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandcracker committed Mar 5, 2023
1 parent 321b3f7 commit 849570e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion display_server_interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
OSNotSupportedError as __OSNotSupportedError
)

__version__ = "0.0.dev9"
__version__ = "0.0.dev10"
__author__ = "Commandcracker"

__os_name = __system().lower()
Expand Down
36 changes: 34 additions & 2 deletions display_server_interactions/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"""
SRCCOPY = 0x00CC0020
WM_CHAR = 0x0102

WM_KEYDOWN = 0x0100
WM_KEYUP = 0x0101
# pylint: disable=too-few-public-methods


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

def send_chr(self, character: chr) -> None:
user32.PostMessageW(self.window, WM_CHAR, ord(character), 0)
vk_map = {
"return": 0x0D,
"tab": 0x09,
"shift_l": 0xA0,
"shift_r": 0xA1,
"control_r": 0x11,
"control_r": 0x11,
"alt_l": 0x12,
"alt_r": 0x12,
"pause": 0x13,
"caps_lock": 0x14,
"escape": 0x1B,
"space": 0x20,
"prior": 0x21,
"next": 0x22,
"end": 0x23,
"home": 0x24,
"left": 0x25,
"up": 0x26,
"right": 0x27,
"down": 0x28,
"print": 0x2C,
"insert": 0x2D,
"delete": 0x2E
}

vk = vk_map.get(character.lower())
if vk is None:
user32.PostMessageW(self.window, WM_CHAR, ord(character), 0)
else:
user32.PostMessageW(self.window, WM_KEYDOWN, vk, 0)
user32.PostMessageW(self.window, WM_KEYUP, vk, 0)

def send_str(self, string: str) -> None:
for character in string:
Expand Down

0 comments on commit 849570e

Please sign in to comment.