You can use an existing system DLL:
#constant WM_CLOSE 0x0010
` This is here to give me time to switch focus to another app ;)
sleep 5000
` Open up the required dll
load dll "user32.dll",1
` Get the handle for the currently focused window
Window=call dll(1, "GetForegroundWindow")
` Tell it to close - warning, if this program has the focus it will be closed!
call dll 1, "PostMessageA", Window, WM_CLOSE, 0, 0
` Close the dll
delete dll 1
wait key
end
The hard bit (I hope what MrTAToad is working on) is to send meaningful messages for keypresses, mouse movements, and mouse clicks.
Because of the way windows has evolved, sending detailed messages is not easy. Everything except the message type is encoded within a total of 6 bytes.