Skip to content

Commit

Permalink
Merge pull request #134 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Add post and send message to window
  • Loading branch information
JE-Chen authored Dec 20, 2023
2 parents d67677f + 8369e58 commit a17b570
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
20 changes: 5 additions & 15 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions je_auto_control/windows/core/utils/win32_keypress_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

def check_key_is_press(keycode: [int, str]) -> bool:
if isinstance(keycode, int):
temp: int = ctypes.windll.user32.GetKeyState(keycode)
temp: int = ctypes.windll.user32.GetAsyncKeyState(keycode)
else:
temp = ctypes.windll.user32.GetKeyState(ord(keycode))
temp = ctypes.windll.user32.GetAsyncKeyState(ord(keycode))
if temp > 1:
return True
return False
Empty file.
47 changes: 47 additions & 0 deletions je_auto_control/windows/window/window_hwnd.py
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

0 comments on commit a17b570

Please sign in to comment.