Page 1 of 1

Scripting remote control from Python with WM_COPYDATA

Posted: 21 Jun 2022 14:06
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)
        

Re: Scripting remote control from Python with WM_COPYDATA

Posted: 21 Jun 2022 17:21
by Horst
And what is the real message behind that post ?
Do you expect that someone tries it without understanding what you mean.

Re: Scripting remote control from Python with WM_COPYDATA

Posted: 22 Jun 2022 00:35
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 ::).