How to prevent keys being discarded by eventghost?

If you have a question or need help, this is the place to be.
Post Reply
milmike
Posts: 2
Joined: Wed Aug 09, 2017 10:37 am

How to prevent keys being discarded by eventghost?

Post by milmike » Wed Aug 09, 2017 11:16 am

Hi, I have a simple macro where it reacts when a key was pressed, eg: CTRL+SPACE. -> show OSD.

It works fine, but then in other applications the key combinations doesn't work any more.
I guess because EventGhost doesn't forward the keys to the window message queue after it was processed.

Is there a way I can react on keys but still be able to use these keys in other applications?

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: How to prevent keys being discarded by eventghost?

Post by yokel22 » Wed Aug 09, 2017 6:42 pm

Have you tried the "Find Window" combined with "Bring to Front" actions before sending your key command? If not, give these a shot.


For Notepad: Notice i added edit mode in the find window config, this was needed.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc2">
    <Macro Name="Send Keystrokes: Notepad" XML_Guid="{EA1C8924-9DC0-448B-9D26-1BEAB5E2E7BA}" Expanded="True">
        <Event Name="Keyboard.Ctrl+Space" XML_Guid="{7FBCD19B-D15F-4009-BCA9-51268625C91F}" />
        <Action XML_Guid="{EAD707CD-585D-4A85-B43B-A41B7992FB46}">
            EventGhost.ShowOSD(u'Spacebar pressed!', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 128, 0), (0, 0, 0), 4, (0, 0), 0, 3.0, None)
        </Action>
        <Action XML_Guid="{5BEB880B-FF4E-48F7-BDDF-9F71021EC674}">
            Window.FindWindow(u'notepad.exe', None, u'Notepad', u'', u'Edit', 1, False, 0.5, 2)
        </Action>
        <Action XML_Guid="{2A88F830-1CDA-4C3C-96F0-AAB3E896E378}">
            Window.BringToFront()
        </Action>
        <Action XML_Guid="{7AC23566-45A9-486E-982A-BE65414662C6}">
            Window.SendKeys(u'Test text.', False, 2)
        </Action>
    </Macro>
</EventGhost>
Or for Kodi:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc2">
    <Macro Name="Send Keystrokes: Kodi" XML_Guid="{C1FA79EA-8C72-40CA-81AF-0D18AC963F3B}" Expanded="True">
        <Event Name="Keyboard.Space" XML_Guid="{8FE5DD36-8F4C-4A1F-87B8-4A17954369B8}" />
        <Action XML_Guid="{5BEB880B-FF4E-48F7-BDDF-9F71021EC674}">
            Window.FindWindow(u'kodi.exe', None, None, None, None, None, False, 0.5, 2)
        </Action>
        <Action XML_Guid="{2A88F830-1CDA-4C3C-96F0-AAB3E896E378}">
            Window.BringToFront()
        </Action>
        <Action XML_Guid="{57403CBA-4946-48D7-8465-06C3A8C968D9}">
            Window.SendKeys(u'{Down}', False, 2)
        </Action>
        <Action XML_Guid="{E7F733A3-EB9C-4E34-8B82-7975A7DEEBA5}">
            Window.SendKeys(u'{Down}', False, 2)
        </Action>
        <Action XML_Guid="{7AC23566-45A9-486E-982A-BE65414662C6}">
            Window.SendKeys(u'{Down}', False, 2)
        </Action>
    </Macro>
</EventGhost>
Last edited by yokel22 on Wed Aug 09, 2017 7:04 pm, edited 2 times in total.

loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: How to prevent keys being discarded by eventghost?

Post by loveleejohn » Wed Aug 09, 2017 6:43 pm

Hey there milmike. Here's the description from the keyboard plugin that sounds like a textbook description of the issue you might be facing.

"If such a keyboard event is assigned to a macro, the plugin will block the key, so Windows or another application will not see it anymore. This is needed to permit remapping of keys as otherwise the old key would reach the target in conjunction of another action you might want to do and this is mostly not what you intend. But this blocking only happens, if a macro would actually execute in succession of the event. So if the macro or any of its parents is disabled, the keypress will pass through."

There are a couple options that come to mind to get around this. You might want to reconsider using such a widely used key combination for your macro as CTRL+SPACE. Why not use something that starts with the tilda key instead or one of the Function keys to avoid duplication with other shortcuts that might already exist on your computer?
Another trick is to limit the OSD macro to only function within a limited context such as to only let it run if another window is opened or perhaps in your case to disable it if a certain window is opened. And since we are actually guessing at your particular applciation, if you happen to be using a remote control with your macro, you could even link the combination to a button press on the remote instead of the key combination if that would work for your purposes. Hope that helps a bit.

loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: How to prevent keys being discarded by eventghost?

Post by loveleejohn » Wed Aug 09, 2017 6:45 pm

Hahaha. Beat to the punch by yokel! I'll step aside since I see you're now in good hands milmike. Good luck on your project! :D

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: How to prevent keys being discarded by eventghost?

Post by kgschlosser » Wed Aug 09, 2017 7:02 pm

ok so this is what you would want to do


add a python command action to your macro. and in that command put

Code: Select all

del eg.lastFoundWindows[:]
then after that add the send keystrokes action with

Code: Select all

{Ctrl+Space}
This does not cause a loop and what it does is it will send those same keystrokes to whatever window is in focus. the del eg.lastFoundWindows[:] makes sure that there are no windows that have been found recently via the find window action as the send keystrokes will use this in place of the window in focus if it is populated. so we want to make sure it is empty.
If you like the work I have been doing then feel free to Image

milmike
Posts: 2
Joined: Wed Aug 09, 2017 10:37 am

Re: How to prevent keys being discarded by eventghost?

Post by milmike » Fri Aug 11, 2017 7:02 am

just wanted to say thanks!! EG community seems to be awesome. :)

Post Reply