Page 1 of 1

Howto implement a macro handling any keystroke?

Posted: Wed Jan 11, 2012 4:18 pm
by phlox
Hi

How can I implement an event handler for ANY keystroke?

I thought I just can write a macro like this

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1544">
    <Macro Name="OnKeyStroke" Expanded="True">
        <Event Name="Keyboard.*" />
        <Action>
            EventGhost.PythonCommand(u'print "keystroke"')
        </Action>
    </Macro>
</EventGhost>
But when listening on 'Keyboard.*' the macro is never called

Btw, in the ÔÇÿiMON plugin' (a plugin for Soundgraph iMON remotes) this syntax works expected: I can listen for ÔÇÿiMON.*ÔÇÖ events and the macro is called with every key pressed on the remote.

Is there another way? ...I cannot imagine that this is impossible and I have to list every single character key?!?

(I'm using EG 4.1 latest on W7)

Re: Howto implement a macro handling any keystroke?

Posted: Fri Jan 20, 2012 10:48 am
by phlox
Any ideas? Why is the generic event 'iMON.*' handled by EG but 'Keyboard.*' not?

I think it's the EG framework which decides if a macro shall be executed, not the plugin itself, so I don't understand why it's working in one case but not in the other...?

Re: Howto implement a macro handling any keystroke?

Posted: Tue Feb 07, 2012 1:43 pm
by phlox
In the meanwhile, I had a look into the code.

Module 'EventGhostEvent.py', method 'Execute', line 139:

Code: Select all

        eventHandlerList = []
        eventHandlerList += get(eventString, [])
        if self.prefix != "Keyboard":
            eventHandlerList += get(self.suffix, [])
            key2 = self.suffix.rsplit(".", 1)[-1]
            if self.suffix != key2:
                eventHandlerList += get(key2, [])
            eventHandlerList += get('*', [])
            key1 = eventString.rsplit(".", 1)[0] + '.*'
            eventHandlerList += get(key1, [])
            key2 = eventString.split(".", 1)[0] + '.*'
            if key1 != key2:
                eventHandlerList += get(key2, [])
i.e. the asterisk notation '<eventprefix>.*' works for all plugins except for the 'Keyboard' plugin.

Is this restriction really necessary? I can't find arguments for that so far. I just could imagine that the author expected that there exists a 'Keyboard.*' event (the asterisk key on the keyboard) but the asterisk key is submitted as 'Keyboard.Multiply' event, so there's no name collision.

I've tested in my own installation without this restriction and it works like a charm.
So my suggestion for a future release is to remove condition 'if self.prefix != "Keyboard":'

Re: Howto implement a macro handling any keystroke?

Posted: Tue Feb 14, 2012 11:40 am
by Pako
phlox wrote:So my suggestion for a future release is to remove condition 'if self.prefix != "Keyboard":'
I try to incorporate the proposed modification to the next build.
If by chance there was some complications, I can turn it back to original state.

Pako

Re: Howto implement a macro handling any keystroke?

Posted: Tue Feb 14, 2012 3:42 pm
by phlox
sounds good :)
thanks!

Re: Howto implement a macro handling any keystroke?

Posted: Tue May 07, 2013 5:44 pm
by Pako
Very strange problem!
@phlox:
What do you think?
It seems, that you did poorly tested ... :wink:

Pako