State Logic. A too complicated solution?

If you have a question or need help, this is the place to be.
Post Reply
cvben
Posts: 38
Joined: Wed Jun 07, 2017 8:30 pm

State Logic. A too complicated solution?

Post by cvben » Sun Jul 08, 2018 3:41 am

All,

I am wondering about an implemented solution to a problem I had.

So I am using the Microsoft MCE Remote (Vista+) to read an ir-transceiver usb dongle and an old ir remote I had lying around. With this I thought that it would be nice to have a set of things that my remote did like launch programs, shortcuts, call websites, play music, turn off/on lights/plugins at the house, plus control my soundbar and tv by blasting ir signals through the transceiver. All this was easy enough, but I had a bit of an issue, I needed context. I mean that if I had kodi open the controls needed would be better off remapped in many cases, if I had youtube.com/tv open I needed a slightly different key to search for instance, or maybe a program had a nice user control system, but it required different keys too. Hell if I got crazy enough I could automate programs with no interface/api via good old mouse navigation and clicks (although I am unaware of any program lacking simple keyboard shortcuts of some kind).

The point is that I needed situational awareness. If x program or window is open :: let keys equal y. Again context. What I came up with is the tree below:

Part one...

Image

Part two... Alpha folder

Image

And the tree for any interested:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc4">
    <Folder Name="switches" XML_Guid="{CB347555-72BF-4B6A-8034-C6292DCF7487}" Expanded="True">
        <Folder Name="modes" XML_Guid="{7A0592F7-D595-4024-ADE6-6FC2B2BA7684}">
            <Macro Name="Listen_Up button action" XML_Guid="{F4AC0B89-DAB4-47DF-A270-B978C5716E3B}" Expanded="True">
                <Event Name="Keyboard.Ctrl+Space" XML_Guid="{509AB468-3AC9-426C-8C68-5BF996F2265D}" />
                <Action XML_Guid="{C5047E65-C362-488A-A18D-09A4ADEBC90B}">
                    EventGhost.EnableItem(XmlIdLink(19))
                </Action>
                <Action XML_Guid="{C5047E65-C362-488A-A18D-09A4ADEBC90B}">
                    EventGhost.EnableItem(XmlIdLink(25))
                </Action>
                <Action XML_Guid="{C5047E65-C362-488A-A18D-09A4ADEBC90B}">
                    EventGhost.EnableItem(XmlIdLink(31))
                </Action>
            </Macro>
        </Folder>
        <Macro Name="state = a" id="19" Enabled="False" XML_Guid="{5ABB6182-6BAF-4E29-B53F-3C8A06279683}">
            <Event Name="Keyboard.1" XML_Guid="{E43AB673-C517-41AF-90BA-523958B3E835}" />
            <Action Name="buttons = state a" XML_Guid="{FF23F788-FB11-48D1-A02B-84D256DBFD76}">
                EventGhost.Comment()
            </Action>
            <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                EventGhost.DisableItem(XmlIdLink(25))
            </Action>
            <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                EventGhost.DisableItem(XmlIdLink(31))
            </Action>
            <Action XML_Guid="{17E825F9-348E-41BB-AD8E-DA449855D3BC}">
                EventGhost.TriggerEvent(u'State_A', 0.0)
            </Action>
        </Macro>
        <Macro Name="state = b" id="25" Enabled="False" XML_Guid="{2403E9F8-E1F5-43CD-B12A-B0828D2293F7}">
            <Event Name="Keyboard.2" XML_Guid="{B4538A13-1566-406A-AB7D-F53D11EB76B1}" />
            <Action Name="buttons = state b" XML_Guid="{FF23F788-FB11-48D1-A02B-84D256DBFD76}">
                EventGhost.Comment()
            </Action>
            <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                EventGhost.DisableItem(XmlIdLink(19))
            </Action>
            <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                EventGhost.DisableItem(XmlIdLink(31))
            </Action>
            <Action XML_Guid="{17E825F9-348E-41BB-AD8E-DA449855D3BC}">
                EventGhost.TriggerEvent(u'State_B', 0.0)
            </Action>
        </Macro>
        <Macro Name="state = c" id="31" Enabled="False" XML_Guid="{96CAB14D-4E58-40FB-8ABC-776A10304BA8}">
            <Event Name="Keyboard.3" XML_Guid="{3DD0E389-8788-4784-B609-EE19718811D4}" />
            <Action Name="buttons = state c" XML_Guid="{FF23F788-FB11-48D1-A02B-84D256DBFD76}">
                EventGhost.Comment()
            </Action>
            <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                EventGhost.DisableItem(XmlIdLink(19))
            </Action>
            <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                EventGhost.DisableItem(XmlIdLink(25))
            </Action>
            <Action XML_Guid="{17E825F9-348E-41BB-AD8E-DA449855D3BC}">
                EventGhost.TriggerEvent(u'State_C', 0.0)
            </Action>
        </Macro>
        <Folder Name="Alpha" XML_Guid="{A657611B-A31A-4EE0-829F-928A6F99EA7F}">
            <Macro Name="A" XML_Guid="{15F8CE85-C55C-4304-B454-7BC11614B401}" Expanded="True">
                <Event Name="Main.State_A" XML_Guid="{80F7AAA4-2971-4FE3-8994-E4387092C2D8}" />
                <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                    EventGhost.DisableItem(XmlIdLink(19))
                </Action>
                <Action XML_Guid="{F736EE13-4D5B-4CCF-93A4-005066B8C5BC}">
                    System.Execute(u'', u'', 0, False, 2, u'', False, False, u'', False, False, False, False)
                </Action>
                <Action Name="Enable/Disable Further Macros/Events, set controls" XML_Guid="{FF23F788-FB11-48D1-A02B-84D256DBFD76}">
                    EventGhost.Comment()
                </Action>
            </Macro>
            <Macro Name="B" XML_Guid="{AAD3443F-8D96-42A7-BA63-7107F5F2856F}" Expanded="True">
                <Event Name="Main.State_B" XML_Guid="{97D45EB2-2E53-4961-BFBE-3ED2DC9C4F86}" />
                <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                    EventGhost.DisableItem(XmlIdLink(25))
                </Action>
                <Action XML_Guid="{F736EE13-4D5B-4CCF-93A4-005066B8C5BC}">
                    System.Execute(u'', u'', 0, False, 2, u'', False, False, u'', False, False, False, False)
                </Action>
                <Action Name="Enable/Disable Further Macros/Events, set controls" XML_Guid="{FF23F788-FB11-48D1-A02B-84D256DBFD76}">
                    EventGhost.Comment()
                </Action>
            </Macro>
            <Macro Name="C" XML_Guid="{B60E8B4E-E232-45A3-9A67-F2D2971B06F0}" Expanded="True">
                <Event Name="Main.State_C" XML_Guid="{5BC2A139-5A87-42E6-8304-BF5675796F01}" />
                <Action XML_Guid="{F736EE13-4D5B-4CCF-93A4-005066B8C5BC}">
                    System.Execute(u'', u'', 0, False, 2, u'', False, False, u'', False, False, False, False)
                </Action>
                <Action XML_Guid="{E4110300-10E1-4271-ADD3-2988A0216057}">
                    EventGhost.DisableItem(XmlIdLink(31))
                </Action>
                <Action Name="Enable/Disable Further Macros/Events, set controls" XML_Guid="{FF23F788-FB11-48D1-A02B-84D256DBFD76}">
                    EventGhost.Comment()
                </Action>
            </Macro>
        </Folder>
    </Folder>
</EventGhost>

cvben
Posts: 38
Joined: Wed Jun 07, 2017 8:30 pm

Re: State Logic. A too complicated solution?

Post by cvben » Sun Jul 08, 2018 3:52 am

What you are looking at here is the setup, but with temporary values placed in the macros where ir codes would be.

What happens:

I press the "Listeners" enable key
it enables any concerning listeners
if a key is pressed, then all other modes are disabled
that mode triggers an event
upon event a new macro triggers
this disables the listener which was enabled
it launches an associated file/website, et al if needed
then it could enable or disable any other macros or commands needed.

This works. However I wonder if I missed some way to make this more efficient, or a plain out better implementation or solution. Thoughts?

Also if anyone needs a similar process use that tree and save yourself a few minutes.

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

Re: State Logic. A too complicated solution?

Post by kgschlosser » Mon Jul 09, 2018 5:43 am

It looks as though you are using keyboard shortcuts in order to change different remote mappings.


We can make this a fully automated setup that is program aware.

This is how you would set up the tree.

Create a folder for say Kodi and another folder for YouTube.

Map keys to kodi actions and put the macros in the Kodi folder. Do likewise for YouTube.

Now you only have to disable and enable the folders. This will automatically block events for the macros in a disabled folder and allow for the folder that is not disabled.

Install the task monitor plus plugin. This plugin will generate events when a specific application is activated or created.

Create a macro for a created/activated for YouTube and for Kodi. The cool thing about that plugin is it is going to generate events for a title change of a window. What this means is YouTube is running in a browser. So the only way to identify if you are watching YouTube is by the caption bar text for the browser. When you change tabs the caption changes.

In the macros for the 2 different applications we create a disable and an enable action. Kodi macro will enable the kodi key mappings and disable the YouTube key mappings. And vice versa for the YouTube macro.


You set a key mapping that is outside of those mapping folders one that you can cycle through your applications.
If you like the work I have been doing then feel free to Image

Post Reply