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.

Generate event on key release

If you have a question or need help, this is the place to be.
Post Reply
max
Posts: 8
Joined: Mon Nov 09, 2009 9:20 am

Generate event on key release

Post by max »

I would like to create an event to trigger an action when I press a key on the keyboard, and an other event to trigger another action, when I release the key. First part is straightforward, but the release part seems more tricky, since only keypress events show up in the log window. Does anybody know how to do this in eventghost?
Best Regards

Max
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Generate event on key release

Post by miljbee »

Since the KB Plugin doesn't generate KeyPressed KeyReleased Events, you will have to use a small trick.

The KB plugin generates enduring Events, which allow you to repeat the assigned macro as long as the key is down (using autorepeat action).
So what you need to do is generate an event when the macro ends its repeat.
You will want to use a timer for that.

Each time the macro runs, it will reset the timer.
As long as the macro runs before the timer ends, the timer won't generate any event.
When the repeat stops, the timer will expire and generate its event.

Of course, you will get the event some time after the key is actually released.
This delay depends on how you set up the autorepeat action and the timer.

I have attached a sample Tree. The assigned Key is LShift.
Attachments
keyup.xml
EG Demo to have an event on key release
(918 Bytes) Downloaded 201 times
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Generate event on key release

Post by miljbee »

I realize that my demo tree will only fire Timer.keyUp events. This is not really usefull if you want to do this for several keys.

So if you want to get events that looks like :
Timer.LShift_up (and have LShift automatically replaced by the name of the key that is down)

In the demo tree of my previous post, replace the timer action by this one :

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1610">
    <Action>
        EventGhost.PythonCommand(u'eg.plugins.Timer.TimerAction(u\'KeyUp\', 0, 1, 0.15, eg.event.suffix+"_up", False, True, 1, u\'00:00:00\')')
    </Action>
</EventGhost>
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
max
Posts: 8
Joined: Mon Nov 09, 2009 9:20 am

Re: Generate event on key release

Post by max »

That seems to work really well. That was exactly what I was looking for. In fact I only need for one button at the moment, but it obviously becomes a lot more useful with the suffix after. Thank you very much.
Best Regards

Max
Post Reply