-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_command.py
79 lines (60 loc) · 2.72 KB
/
get_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import time, win32con, win32api, win32gui, ctypes
from pywinauto import clipboard # 채팅창내용 가져오기 위해
PBYTE256 = ctypes.c_ubyte * 256
_user32 = ctypes.WinDLL("user32")
GetKeyboardState = _user32.GetKeyboardState
SetKeyboardState = _user32.SetKeyboardState
PostMessage = win32api.PostMessage
SendMessage = win32gui.SendMessage
FindWindow = win32gui.FindWindow
IsWindow = win32gui.IsWindow
GetCurrentThreadId = win32api.GetCurrentThreadId
GetWindowThreadProcessId = _user32.GetWindowThreadProcessId
AttachThreadInput = _user32.AttachThreadInput
MapVirtualKeyA = _user32.MapVirtualKeyA
MapVirtualKeyW = _user32.MapVirtualKeyW
MakeLong = win32api.MAKELONG
w = win32con
# 조합키 쓰기 위해
def PostKeyEx(hwnd, key, shift, specialkey):
if IsWindow(hwnd):
ThreadId = GetWindowThreadProcessId(hwnd, None)
lparam = MakeLong(0, MapVirtualKeyA(key, 0))
msg_down = w.WM_KEYDOWN
msg_up = w.WM_KEYUP
if specialkey:
lparam = lparam | 0x1000000
if len(shift) > 0: # Если есть модификаторы - используем PostMessage и AttachThreadInput
pKeyBuffers = PBYTE256()
pKeyBuffers_old = PBYTE256()
SendMessage(hwnd, w.WM_ACTIVATE, w.WA_ACTIVE, 0)
AttachThreadInput(GetCurrentThreadId(), ThreadId, True)
GetKeyboardState(ctypes.byref(pKeyBuffers_old))
for modkey in shift:
if modkey == w.VK_MENU:
lparam = lparam | 0x20000000
msg_down = w.WM_SYSKEYDOWN
msg_up = w.WM_SYSKEYUP
pKeyBuffers[modkey] |= 128
SetKeyboardState(ctypes.byref(pKeyBuffers))
time.sleep(0.01)
PostMessage(hwnd, msg_down, key, lparam)
time.sleep(0.01)
PostMessage(hwnd, msg_up, key, lparam | 0xC0000000)
time.sleep(0.01)
SetKeyboardState(ctypes.byref(pKeyBuffers_old))
time.sleep(0.01)
AttachThreadInput(GetCurrentThreadId(), ThreadId, False)
else: # Если нету модификаторов - используем SendMessage
SendMessage(hwnd, msg_down, key, lparam)
SendMessage(hwnd, msg_up, key, lparam | 0xC0000000)
def copy_chatroom(chatroom_name):
# # 핸들 _ 채팅방
hwndMain = win32gui.FindWindow( None, chatroom_name)
hwndListControl = win32gui.FindWindowEx(hwndMain, None, "EVA_VH_ListControl_Dblclk", None)
# #조합키, 본문을 클립보드에 복사 ( ctl + A , C )
PostKeyEx(hwndListControl, ord('A'), [w.VK_CONTROL], False)
time.sleep(1)
PostKeyEx(hwndListControl, ord('C'), [w.VK_CONTROL], False)
ctext = clipboard.GetData()
return ctext