-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from Integration-Automation/dev
Add post and send message to window
- Loading branch information
Showing
4 changed files
with
54 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from ctypes import WINFUNCTYPE, c_bool, c_int, POINTER, create_unicode_buffer | ||
from typing import Union | ||
|
||
from je_auto_control.windows.core.utils.win32_ctype_input import user32 | ||
from je_auto_control.windows.keyboard.win32_ctype_keyboard_control import press_key | ||
|
||
EnumWindows = user32.EnumWindows | ||
EnumWindowsProc = WINFUNCTYPE(c_bool, POINTER(c_int), POINTER(c_int)) | ||
GetWindowText = user32.GetWindowTextW | ||
GetWindowTextLength = user32.GetWindowTextLengthW | ||
IsWindowVisible = user32.IsWindowVisible | ||
FindWindowW = user32.FindWindowW | ||
PostMessageW = user32.PostMessageW | ||
SendMessageW = user32.SendMessageW | ||
|
||
|
||
def get_all_window_hwnd(): | ||
window_info = [] | ||
|
||
def _foreach_window(hwnd, l_param): | ||
if IsWindowVisible(hwnd): | ||
length = GetWindowTextLength(hwnd) | ||
buff = create_unicode_buffer(length + 1) | ||
GetWindowText(hwnd, buff, length + 1) | ||
window_info.append((hwnd, buff.value)) | ||
return True | ||
|
||
EnumWindows(EnumWindowsProc(_foreach_window), 0) | ||
return window_info | ||
|
||
|
||
def get_one_window_hwnd(window_class: Union[None, str], window_name: Union[None, str]): | ||
return FindWindowW(window_class, window_name) | ||
|
||
|
||
def send_key_to_window(window_name: str, action_message: int, | ||
key_code_1: int, key_code_2: int): | ||
_hwnd = FindWindowW(window_name) | ||
post_status = SendMessageW(_hwnd, action_message, key_code_1, key_code_2) | ||
return _hwnd, post_status | ||
|
||
|
||
def post_key_to_window(window_name: str, action_message: int, | ||
key_code_1: int, key_code_2: int): | ||
_hwnd = FindWindowW(window_name) | ||
post_status = PostMessageW(_hwnd, action_message, key_code_1, key_code_2) | ||
return _hwnd, post_status |