Skip to content

Commit a17b570

Browse files
authored
Merge pull request #134 from Integration-Automation/dev
Add post and send message to window
2 parents d67677f + 8369e58 commit a17b570

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

.idea/workspace.xml

Lines changed: 5 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

je_auto_control/windows/core/utils/win32_keypress_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
def check_key_is_press(keycode: [int, str]) -> bool:
1313
if isinstance(keycode, int):
14-
temp: int = ctypes.windll.user32.GetKeyState(keycode)
14+
temp: int = ctypes.windll.user32.GetAsyncKeyState(keycode)
1515
else:
16-
temp = ctypes.windll.user32.GetKeyState(ord(keycode))
16+
temp = ctypes.windll.user32.GetAsyncKeyState(ord(keycode))
1717
if temp > 1:
1818
return True
1919
return False

je_auto_control/windows/window/__init__.py

Whitespace-only changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from ctypes import WINFUNCTYPE, c_bool, c_int, POINTER, create_unicode_buffer
2+
from typing import Union
3+
4+
from je_auto_control.windows.core.utils.win32_ctype_input import user32
5+
from je_auto_control.windows.keyboard.win32_ctype_keyboard_control import press_key
6+
7+
EnumWindows = user32.EnumWindows
8+
EnumWindowsProc = WINFUNCTYPE(c_bool, POINTER(c_int), POINTER(c_int))
9+
GetWindowText = user32.GetWindowTextW
10+
GetWindowTextLength = user32.GetWindowTextLengthW
11+
IsWindowVisible = user32.IsWindowVisible
12+
FindWindowW = user32.FindWindowW
13+
PostMessageW = user32.PostMessageW
14+
SendMessageW = user32.SendMessageW
15+
16+
17+
def get_all_window_hwnd():
18+
window_info = []
19+
20+
def _foreach_window(hwnd, l_param):
21+
if IsWindowVisible(hwnd):
22+
length = GetWindowTextLength(hwnd)
23+
buff = create_unicode_buffer(length + 1)
24+
GetWindowText(hwnd, buff, length + 1)
25+
window_info.append((hwnd, buff.value))
26+
return True
27+
28+
EnumWindows(EnumWindowsProc(_foreach_window), 0)
29+
return window_info
30+
31+
32+
def get_one_window_hwnd(window_class: Union[None, str], window_name: Union[None, str]):
33+
return FindWindowW(window_class, window_name)
34+
35+
36+
def send_key_to_window(window_name: str, action_message: int,
37+
key_code_1: int, key_code_2: int):
38+
_hwnd = FindWindowW(window_name)
39+
post_status = SendMessageW(_hwnd, action_message, key_code_1, key_code_2)
40+
return _hwnd, post_status
41+
42+
43+
def post_key_to_window(window_name: str, action_message: int,
44+
key_code_1: int, key_code_2: int):
45+
_hwnd = FindWindowW(window_name)
46+
post_status = PostMessageW(_hwnd, action_message, key_code_1, key_code_2)
47+
return _hwnd, post_status

0 commit comments

Comments
 (0)