Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Send Message function

If you have a question or need help, this is the place to be.
Post Reply
specter333
Experienced User
Posts: 95
Joined: Thu Dec 27, 2007 12:26 am

Send Message function

Post by specter333 »

I'm trying to learn to use the send message function thinking it would be better than emulating a bunch of keyboard strokes from EG.

I have these Auto Hotkey test scripts I'm trying to send to, the actual program I'm wanting to send messages to will also be an Auto Hotkey script.

I'll post the scripts here so you can see what it's sending.

Sender script;

Code: Select all

#SingleInstance, force

Run, %A_AHKPath% "%A_ScriptDir%\receiver.ahk",,,Instance#1_pid
WinWait, ahk_pid %Instance#1_pid%  ; wait for main script window to be created

+F1::
DetectHiddenWindows, On   ; main script window is hidden
WinGet, hwnd#1, ID, ahk_pid %Instance#1_pid%
SendMessage,  6000, , , , ahk_id %hwnd#1%
return
This script opens the receiver script then waits for the hotkey Shift + F1 and sends the message.

Receiver Script;

Code: Select all

#SingleInstance, force

OnMessage(6000, "Test")
return

Test(wparam,lparam, msg)
{
MsgBox, Test works! message number: %msg%
}
This script waits for the message then pops up a message box saying it works. To run these scripts you must first have Auto Hotkeys installed on your system.

While searching for an answer another post led me to Windows Spy. The results I get from monitoring the window messages with it are.
Using the AHK sender script.

Code: Select all

WM_USER + 4976 (0x00001770)
wParam: 0x00000000
lParam: 0x00000000
and trying to send the message with EG.

Code: Select all

WM_APPCOMMAND
wParam: 0x00000000
lParam: 0x00001770[
And of course the message box pops up with the AHK send script but not when sending from EG.

So I'm sure I'm not doing something correctly with Eg. What is the correct way to send the command from EG?
Thank you once gain for your help.
Rich
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Send Message function

Post by Pako »

specter333 wrote: What is the correct way to send the command from EG?
For example this script closes Notepad:

Code: Select all

from eg.WinApi.Dynamic import SendMessage as WinApiSendMessage
WM_SYSCOMMAND = 274
SC_CLOSE      = 61536

FindWin = eg.WindowMatcher(u'NOTEPAD.EXE', None, u'Notepad', None, None, None, False, 0.0, 0)
hwnd = FindWin()
if hwnd:
    mesg = WM_SYSCOMMAND
    wParam = SC_CLOSE
    lParam = 0
    WinApiSendMessage(hwnd[0], mesg, wParam, lParam)
else:
    print "Window not found ..."
Pako
Post Reply