winapi - Python win32api SendMesage -
trying clarify win32api me. , made simple example. notepad window, move mouse position click , write string. not work. what's problem? , clarify me lparam parameter? doing it? type ? how looks ? :) in advance.
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') homecoming whndl def make_pycwnd(hwnd): pycwnd = win32ui.createwindowfromhandle(hwnd) homecoming pycwnd def send_input_hax(pycwnd, msg): f_click(pycwnd) 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)
there window within notepad's main one, need send messages it. can see 'hidden' window microsoft spy++ tool or can kid windows so:
def callback(hwnd, hwnds): if win32gui.iswindowvisible(hwnd) , win32gui.iswindowenabled(hwnd): hwnds[win32gui.getclassname(hwnd)] = hwnd homecoming true hwnds = {} win32gui.enumchildwindows(whndl, callback, hwnds)
window looking has 'edit' class name , enabled , visible kid window notepad. code work way:
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') homecoming whndl def make_pycwnd(hwnd): pycwnd = win32ui.createwindowfromhandle(hwnd) homecoming pycwnd def send_input_hax(pycwnd, msg): f_click(pycwnd) 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() def callback(hwnd, hwnds): if win32gui.iswindowvisible(hwnd) , win32gui.iswindowenabled(hwnd): hwnds[win32gui.getclassname(hwnd)] = hwnd homecoming true hwnds = {} win32gui.enumchildwindows(whndl, callback, hwnds) whndl = hwnds['edit'] pycwnd = make_pycwnd(whndl) msg = "it works !\n" send_input_hax(pycwnd,msg)
lparam int , see here trick allows pass more 1 value through single argument. let's need pass 2 digits function takes 1 argument. can send them double digit number , split within function. same way bitwise shift (<<) , bitwise or (|) operations reversable in case:
>>> x = 300 >>> y = 300 >>> lparam = y << 15 | x >>> lparam & 0x7fff # x 0: 300 >>> lparam >> 15 # y 1: 300
you can read more bitwise operations in wikipedia , python wiki.
python winapi sendmessage
No comments:
Post a Comment