I am trying to clarify win32api. And I just made a simple example. Get the Notepad window, move the mouse to a position, click and write a string. But it does not work. What's the problem?
And could anybody clarify for me what the lParam parameter is?
What does it do, What type is it and How should it look?
import win32api, win32con, win32gui, win32ui, win32service, os, time
def f_click(pycwnd):
x=300
y=300
lParam = y <<15 | x
pycwnd.SendMessage(win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam);
pycwnd.SendMessage(win32con.WM_LBUTTONUP, 0, lParam);
def get_whndl():
whndl = win32gui.FindWindowEx(0, 0, None, 'NB.txt - Notepad')
return whndl
def make_pycwnd(hwnd):
PyCWnd = win32ui.CreateWindowFromHandle(hwnd)
return PyCWnd
def send_input_hax(pycwnd, msg):
f_click(pycwnd)
for c in msg:
if c == "\n":
pycwnd.SendMessage(win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
pycwnd.SendMessage(win32con.WM_KEYUP, win32con.VK_RETURN, 0)
else:
pycwnd.SendMessage(win32con.WM_CHAR, ord(c), 0)
pycwnd.UpdateWindow()
whndl = get_whndl()
pycwnd = make_pycwnd(whndl)
msg = "It works !\n"
send_input_hax(pycwnd,msg)