Scripting remote control from Python with WM_COPYDATA

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Yogui
Posts: 18
Joined: 21 Jul 2011 14:44

Scripting remote control from Python with WM_COPYDATA

Post by Yogui »

In case it helps, or I got a bug :-)

Scripting remote control from Python with WM_COPYDATA

Code: Select all

	# Python Code Tested OK in v3.9
	# Needs packages installed
	
	script_text = '::msg "Hello world!";'
	
        import array
        import struct
        import win32gui
        from win32con import WM_COPYDATA as WM_COPYDATA     # int 74
        
        DW_DATA = 4194305
        WIN_CLASS = "ThunderRT6FormDC"

        hwnd = win32gui.FindWindow(WIN_CLASS, None)
        buffer = array.array('u', script_text)
        buffer_address, buffer_length = buffer.buffer_info()
        copy_struct = struct.pack('PLP', DW_DATA, buffer_length*buffer.itemsize, buffer_address)
        win32gui.SendMessage(hwnd, WM_COPYDATA, 0, copy_struct)
        
Thanks, Yogui

Online
Horst
Posts: 1085
Joined: 24 Jan 2021 12:27
Location: Germany

Re: Scripting remote control from Python with WM_COPYDATA

Post by Horst »

And what is the real message behind that post ?
Do you expect that someone tries it without understanding what you mean.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
Portable XYplorer (actual version, including betas)
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69

Yogui
Posts: 18
Joined: 21 Jul 2011 14:44

Re: Scripting remote control from Python with WM_COPYDATA

Post by Yogui »

Thanks for the reply Horst

Feel free to use or comment the code is already tested and working

Code: Select all

Python Code Tested OK in v3.9
From the XYplorer Help Scripting section
Remote Control

*** For software developers only ***

You can run an XYplorer script from an external program using the WM_COPYDATA command with XYplorer's hWnd. This means if you are a programmer you can fully remote control XYplorer.

· cds.dwData: 4194305 (0x00400001)

· cds.lpData: The syntax is identical to the one of the command line switch /script=<script resource>, so you can either pass the path to a script file (commonly called *.xys), or pass the script directly (must be preceded by ::).
Thanks, Yogui

Post Reply