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.

Howto implement a macro handling any keystroke?

Questions and comments specific to a particular plugin should go here.
Post Reply
phlox
Plugin Developer
Posts: 90
Joined: Wed Jan 11, 2012 3:49 pm

Howto implement a macro handling any keystroke?

Post 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)
phlox
Plugin Developer
Posts: 90
Joined: Wed Jan 11, 2012 3:49 pm

Re: Howto implement a macro handling any keystroke?

Post 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...?
phlox
Plugin Developer
Posts: 90
Joined: Wed Jan 11, 2012 3:49 pm

Re: Howto implement a macro handling any keystroke?

Post 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":'
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Howto implement a macro handling any keystroke?

Post 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
phlox
Plugin Developer
Posts: 90
Joined: Wed Jan 11, 2012 3:49 pm

Re: Howto implement a macro handling any keystroke?

Post by phlox »

sounds good :)
thanks!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Howto implement a macro handling any keystroke?

Post by Pako »

Very strange problem!
@phlox:
What do you think?
It seems, that you did poorly tested ... :wink:

Pako
Post Reply