docs: publish bridge with restructured markdown docs
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
"""Hold Right Alt to record a WeChat voice message while playing a wav."""
|
||||
import ctypes
|
||||
import sys
|
||||
import time
|
||||
from ctypes import wintypes
|
||||
|
||||
import win32gui
|
||||
|
||||
sys.path.insert(0, r"C:\Users\GuoAn\.dsh\wechat-bridge")
|
||||
import wechat_uia as w # noqa: E402
|
||||
import wx_audio # noqa: E402
|
||||
|
||||
user32 = ctypes.WinDLL("user32", use_last_error=True)
|
||||
VK_RMENU = 0xA5
|
||||
KEYEVENTF_KEYUP = 0x0002
|
||||
KEYEVENTF_EXTENDEDKEY = 0x0001
|
||||
|
||||
|
||||
class MOUSEINPUT(ctypes.Structure):
|
||||
_fields_ = [("dx", wintypes.LONG), ("dy", wintypes.LONG), ("mouseData", wintypes.DWORD),
|
||||
("dwFlags", wintypes.DWORD), ("time", wintypes.DWORD),
|
||||
("dwExtraInfo", ctypes.c_void_p)]
|
||||
|
||||
|
||||
class KEYBDINPUT(ctypes.Structure):
|
||||
_fields_ = [("wVk", wintypes.WORD), ("wScan", wintypes.WORD),
|
||||
("dwFlags", wintypes.DWORD), ("time", wintypes.DWORD),
|
||||
("dwExtraInfo", ctypes.c_void_p)]
|
||||
|
||||
|
||||
class _INPUTunion(ctypes.Union):
|
||||
_fields_ = [("ki", KEYBDINPUT), ("mi", MOUSEINPUT)]
|
||||
|
||||
|
||||
class INPUT(ctypes.Structure):
|
||||
_anonymous_ = ("u",)
|
||||
_fields_ = [("type", wintypes.DWORD), ("u", _INPUTunion)]
|
||||
|
||||
|
||||
def key(vk, up=False):
|
||||
inp = INPUT()
|
||||
inp.type = 1 # INPUT_KEYBOARD
|
||||
flags = KEYEVENTF_EXTENDEDKEY | (KEYEVENTF_KEYUP if up else 0)
|
||||
inp.u.ki = KEYBDINPUT(vk, 0, flags, 0, None)
|
||||
return user32.SendInput(1, ctypes.byref(inp), ctypes.sizeof(INPUT))
|
||||
|
||||
|
||||
def grab(path):
|
||||
img = w.capture(w_hwnd)
|
||||
img.save(path)
|
||||
return img
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
w_hwnd = int(sys.argv[1])
|
||||
wav = sys.argv[2]
|
||||
w.focus_window(w_hwnd)
|
||||
# focus the input box so the shortcut lands in the chat
|
||||
w.real_down(w_hwnd, 601, 550)
|
||||
time.sleep(0.06)
|
||||
w.real_up()
|
||||
time.sleep(0.4)
|
||||
print("alt down", key(VK_RMENU))
|
||||
time.sleep(1.0)
|
||||
grab(r"C:\Users\GuoAn\AppData\Local\Temp\alt_mid.png")
|
||||
print("playing", wx_audio.play_wav(wav, None, True))
|
||||
time.sleep(0.5)
|
||||
print("alt up", key(VK_RMENU, up=True))
|
||||
time.sleep(2.0)
|
||||
grab(r"C:\Users\GuoAn\AppData\Local\Temp\alt_end.png")
|
||||
print("done")
|
||||
Reference in New Issue
Block a user