Hello,
How to set focus to the right field to send emulate keystroke to the right field of the form ?
The "find windows" action can return a handle on a specific child of a form, a text field for example but after, how to set focus to this field ?
Thanks.
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.
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.
How to set focus to the right field to send Emulate keystrok
Re: How to set focus to the right field to send Emulate keystrok
Here are some examples from my config. As you can see I have used them to automate a TS cutting program, I have set up EG to enter my cut points automatically.. one less laborious task for me!
Sets focus by sending WM_LBUTTONDN and then WM_LBUTTONUP messages (same as clicking the field would do)
This one is focused in a button and sends BM_CLICK which causes the button to trigger.
-jinxdone
Sets focus by sending WM_LBUTTONDN and then WM_LBUTTONUP messages (same as clicking the field would do)
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="851">
<Macro Name="Find Window: TS Packet Editor.exe" Expanded="True">
<Event Name="Main.TSPE.InsertCurrent" />
<Action>
EventGhost.Wait(0.10000000000000001)
</Action>
<Action>
EventGhost.ShowOSD(u'{eg.event.payload}', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, False)
</Action>
<Action>
Window.FindWindow(u'TS Packet Editor.exe', u'TSPE - Transport Stream Packet Editor Ver. 0.755 Licensed to: BetaTest', u'WindowsForms10.Window.8.app.0.2004eee', u'0', u'WindowsForms10.EDIT.app.0.2004eee', 5, False, 0.0, 0)
</Action>
<Action>
Window.SendMessage(513, 0, 0, 0)
</Action>
<Action>
Window.SendMessage(514, 0, 0, 0)
</Action>
<Action>
Window.SendKeys(u'{Home}{Shift+End}{Delete}{eg.event.payload}{Enter}', True)
</Action>
<Action>
EventGhost.Wait(0.10000000000000001)
</Action>
</Macro>
</EventGhost>Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="851">
<Macro Name="Add EDL Marker" Expanded="True">
<Event Name="Main.TSPE.AddEDL" />
<Action>
Window.FindWindow(u'TS Packet Editor.exe', u'TSPE - Transport Stream Packet Editor Ver. 0.755 Licensed to: BetaTest', u'WindowsForms10.Window.8.app.0.2004eee', u'&Add', u'WindowsForms10.BUTTON.app.0.2004eee', 1, False, 0.0, 0)
</Action>
<Action>
Window.SendMessage(245, 0, 0, 0)
</Action>
<Action>
EventGhost.Wait(0.10000000000000001)
</Action>
</Macro>
</EventGhost>
Re: How to set focus to the right field to send Emulate keystrok
Thanks,
works perfectly
just another question, how to find a tag of a button like in your example :
"WindowsForms10.BUTTON.app.0.2004eee"
The integrated tool of EG just return tag of fields, not buttons
I want click on the "directory up" button of the "quick open" box of media player classic
The buttons are inside a "ToolbarWindow32". I try to give focus to it and then use "Emulate keystroke" but
dont give the focus to it. "ToolbarWindow32" seems not a clickable object.
Thanks again
works perfectly
just another question, how to find a tag of a button like in your example :
"WindowsForms10.BUTTON.app.0.2004eee"
The integrated tool of EG just return tag of fields, not buttons
I want click on the "directory up" button of the "quick open" box of media player classic
The buttons are inside a "ToolbarWindow32". I try to give focus to it and then use "Emulate keystroke" but
Code: Select all
<Action Name="Find Window: mplayerc.exe (Dialog: ToolbarWindow32)">
Window.FindWindow(u'mplayerc.exe', None, u'#32770', u'', u'ToolbarWindow32', 1, False, 0.0, 0)
</Action>
<Action>
Window.SendMessage(513, 0, 0, 0)
</Action>
<Action>
Window.SendMessage(514, 0, 0, 0)
</Action>
Thanks again
Re: How to set focus to the right field to send Emulate keystrok
The best windows messages to use are the WM_COMMAND, WM_SYSCOMMAND and WM_APPCOMMAND. Those messages are usually sent by Windows itself when an action was performed on a window and they notifiy the program to do something accordingly. Finding out the correct wParam and iParam values for these messages to trigger a certain action in the program is the hard part but usually it's not too difficult, it just might take a while of your time..
Here is how you trigger the 'directory up' action in MPC quick open window:
I looked for the parameters for the WM_COMMAND message using a windows message tool called winspector to monitor the messages going from/to the quick open window. Simply look for the most likely candidate for a correct message and once you find it the values in winspector are shown in HEX so you need to convert them to decimal before using in EG.
In my earlier example I had simply dragged the 'find window' action onto TSPE, it found the right button, then i just sent BM_CLICK. So in that case I didn't bother to look any deeper since it was already doing what I wanted just fine. Whether this sort of thing works on a given application is completely dependant on how that app was programmed.
Hope this helped!
-jinxdone
Here is how you trigger the 'directory up' action in MPC quick open window:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="851">
<Macro Name="MPC: Up Directory" Expanded="True">
<Action>
Window.FindWindow(u'mplayerc.exe', u'Open', u'#32770', None, None, None, False, 0.0, 0)
</Action>
<Action>
Window.SendMessage(273, 40961, 11013674, 0)
</Action>
</Macro>
</EventGhost>In my earlier example I had simply dragged the 'find window' action onto TSPE, it found the right button, then i just sent BM_CLICK. So in that case I didn't bother to look any deeper since it was already doing what I wanted just fine. Whether this sort of thing works on a given application is completely dependant on how that app was programmed.
Hope this helped!
-jinxdone
Re: How to set focus to the right field to send Emulate keystrok
Thanks it's help a lot.
I was already in the way to play with Winspector but I was unsure it's the right way. I need 2 hour to understand why I don't have the same value than you, in fact in this case LParam have no meaning, only WParam have meaning and I have different value for LParam.
Now I try to put the focus in the file list of "Quick Open" I hope I will success (Send message 513/514 give strange results, works if the mouse is inside the dialog box, block after 513 if the mouse is outside)
Thanks,
Thierry.
I was already in the way to play with Winspector but I was unsure it's the right way. I need 2 hour to understand why I don't have the same value than you, in fact in this case LParam have no meaning, only WParam have meaning and I have different value for LParam.
Now I try to put the focus in the file list of "Quick Open" I hope I will success (Send message 513/514 give strange results, works if the mouse is inside the dialog box, block after 513 if the mouse is outside)
Thanks,
Thierry.
Re: How to set focus to the right field to send Emulate keystrok
Well, the messages 513 (0x201) and 514 (0x202) are WM_LBUTTONDOWN and WM_LBUTTONUP, respectively. If you only send a button down event then it's the same thing as if you push your mouse button down and hold it down. An emulated click obiviously consists of both button down and then button up events. This gets problematic as sometimes you have to take into account what x y cordinate the mouse is in etc..
As I mentioned the better way is to use the WM_COMMAND, WM_SYSCOMMAND and WM_APPCOMMAND messages. According to MSDN the WM_COMMAND lParam in this case is a "Handle to the control window", so it changes each time you open the quick open window... (And yes I think you can leave it to 0, I just simply copied the values from an actual click of the button from winspector.)
In short how this is usually done: start winspector, do the action you want to emulate in a program (go and click a button for example), go back to winspector and see what actually happened when you clicked the button. After you know the control id's and what message was used etc. then you can make the same thing to happen yourself from EG.
There are lots and lots of reading to do on this subject if you really want to get into it. The msdn is a good place to check what the commands really mean.
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library/ms646275.aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
-jinxdone
As I mentioned the better way is to use the WM_COMMAND, WM_SYSCOMMAND and WM_APPCOMMAND messages. According to MSDN the WM_COMMAND lParam in this case is a "Handle to the control window", so it changes each time you open the quick open window... (And yes I think you can leave it to 0, I just simply copied the values from an actual click of the button from winspector.)
In short how this is usually done: start winspector, do the action you want to emulate in a program (go and click a button for example), go back to winspector and see what actually happened when you clicked the button. After you know the control id's and what message was used etc. then you can make the same thing to happen yourself from EG.
There are lots and lots of reading to do on this subject if you really want to get into it. The msdn is a good place to check what the commands really mean.
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library/ms646275.aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
-jinxdone