PDA

View Full Version : Detect a long button press



Promixis
June 23rd, 2004, 06:49 PM
--[[

Simple Lua script to detect when a key or remote button (that repeats) has been held down for > x seconds.

The key must repeat at least every 500 milliseconds or the code will assume the key was released and then start over.

Replace the 4 in the script below to any time period desired.

by Michael Cumming
--]]



t = clock ()
KeyDown = KeyDown or t
KeyLastEvent = KeyLastEvent or KeyDown

if t - KeyLastEvent > 0.5 then
KeyDown = t
end

KeyLastEvent = t

if t - KeyDown > 4 then
TriggerEvent ("KeyHeld4Sec",18)
KeyDown = nil
end

quixote
June 23rd, 2004, 07:09 PM
That's a really cool trick, but it seems that when I try to use that in a multi command to mute the sound and turn off the monitor, the monitor turns on again right away. I am guessing that there are still keypresses stored in the buffer that trigger this. Does anyone know of a work-around? I did a search for keyboard buffer flush, but it is impossible (probably especially since I have a wireless).

Promixis
June 23rd, 2004, 07:48 PM
You want to have this script in a single command and then have the triggerevent call your multigroup - is that what you were doing?

quixote
June 23rd, 2004, 08:08 PM
Yes, I have one command called SleepMode Trigger, which is the script, and a separate multigroup command that has the various commands (mute, monitor off, say plugin), triggered by the girderevent "sleepmode". It works perfectly until the monitor turns back on right away. I have tested the monitor off command to see if there was another issue involved, but it works fine when triggered alone.

Promixis
June 23rd, 2004, 09:07 PM
Hm,

Give this a try with just one simple event from your remote...and see if the multigroup works...

quixote
June 23rd, 2004, 09:26 PM
It works perfectly. Are you suggesting that I use the remote instead? I guess I could do that. I was hoping to stick to a certain structure. ie.-
1 press on a key combo = mode change
2nd press (state setting) = back to keyboard mode
press & hold for 3 seconds = Sleep mode

noodleNT
July 23rd, 2004, 10:32 PM
noobie here... Be kind.

How do I use this?

I am seting up my IR remote to control Beyond TV. I would like the events to only triger on first press and not repeat when held down.

Promixis
July 24th, 2004, 05:13 AM
noodle,

The first thinig you may want to look at is the antirepeat setting to slow down key repeats. If you definitely do not want a repreat events, get the buttonmode plugin from the plugins area.

nemon
August 23rd, 2004, 07:08 PM
Hi

Now I'm using Girder 3.3.1 and I never use Lua scripting but I need something like Mike C post.
At this time when I modify the volume level with my remote, I need to push a several times to level up or down the volume, I want something smooth, like a large pulse to modify smoothly the volume level.

I need something as following:

- Girder must press Ctrl+Alt+a keys (only one time) if receives a short button press from the ir remote.

- But if Girder receives a Large button press keep pressed the keyboard Ctrl+Alt+a keys during the irremote button press.

I'm controlling the volume with Global Audio Control and it has key shortcuts. I have Ctrl+Alt+a for level up and Ctrl+Alt+b for level down.
I try to keeping Ctrl+Alt+a in my keyboard and Global Audio Control level up the volume smoothly. I want to do this with Girder and my remote.

Thanks a lot.


Sorry about my english, I'm spanish.

Promixis
August 23rd, 2004, 08:49 PM
Hi,

I think what would work better for you is the button press plugin which can generate repeat events from your remote. Girder cannot hold down keys, only repeat them...

Can't you change the volume using the standard volume controls?

nemon
August 23rd, 2004, 11:39 PM
Thanks for your help, I didn't see the ButtonMode pluggin...

Well, I take a look the plugin and is perfect, but I think that I can't do what I want because my IR Receiver is the Universal InfraRed (UIR) that I made 4 years ago...
Girder doesn't detects when I hold down a button in my remote.
Exists some driver or configuration for UIR that works fine with held down?

I try the pluggin and does not detects when I keep pressed the button, only detects the "first press" but not "While held down".

I really don't need Girder held down a keyboard keys...with a repeat of keys is OK the really important thing is the held down buttons in my remote that Girder doesn't recognize.

Sorry about my english, if you don't understand something I will try to explain again in other words.

Thanks a lot.

nemon
August 24th, 2004, 12:26 AM
I have an idea:

If I press a button one time in my remote, Girder sends the keys ctrl+Alt+a only one time. But if I press two times the button Girder repeats the keys ctrl+alt+a until I press another button. Like the car windows

I'm finding a solution, because now it is very difficult for me to press so many times the same key to level up the volume.

Thanks a lot

Promixis
August 24th, 2004, 10:31 AM
Hi,

Just so I understand, your receiver only generates one event even if you hold the button down?

nemon
August 24th, 2004, 02:57 PM
Well, I think yes, my receiver only generate one event when I held down...because girder icon only "flash" one time when I held down...and the plugin ButtonMode only says "First Button Press" and never says "Held Down"

But now I'm using other Remote Control, that when I held button down repeats continuosly the event. My old Remote Control only generates the pulse one time.

If I have enought time I will do this:

- With an Oscilloscope and a simple IR Transistor receiver I check how sends the pulses every remote control I got. Because I dont now if my remote control only sends one time the pulse _| \_ or keep up the pulse while held down _|--------------------|_

My new remote control I think sends the same pulse as repeats when you held down...
something as following: _/\_/\_/\_/\_

Now I dont now if the problem is the Remote COntrol or the receiver... I think is the receiver...But if I have time I'll do the tests with my remote controls.

Thanks a lot for your help
What do you think about this?

Promixis
August 24th, 2004, 04:30 PM
I would use the remote that generates multiple events when held down and the button mode plugin. It sounds like your receiver is fine.

Wagner
October 5th, 2004, 10:51 AM
It works perfectly. Are you suggesting that I use the remote instead? I guess I could do that. I was hoping to stick to a certain structure. ie.-
1 press on a key combo = mode change
2nd press (state setting) = back to keyboard mode
press & hold for 3 seconds = Sleep mode

I had this problem earlier making a command to turn the monitors off on all my computers. The other computers would shut off, but the one I issued the command on would shut off and then turn back on. You have to put a wait in there to prevent it from immediately shutting off the monitor.

navigatorXL
May 19th, 2005, 04:47 AM
Another smart way is to use a timer (alarm timer plugin).

This works, if Girder can distinguish between Button Down and Button Up events of the button you want to use (and if repeated commands, i.e. button hold down, are not interpreted as new Button Down).

Create a timer with desired timeout (e.g. 4000 for 4s Delay) and learn to start this timer by Button Down. In properties under On End select the event you want to be executed by long button press. (In addition you can select under On Cancel the event to be triggered by short button press.)

Create another timer WITH SAME TIMER ID ant timeout 0, this timer cancels the other one. Assign the Button Up event with it.

Thats it.

If you press now the button, the timer starts. If it comes to it's "natural" end after 4 seconds, the long button press event is executed. If you release the button within this 4 sec, the timer is cancelled and the long button press event is not executed (instead, if given the short button press event is executed).

Works,
nXL

Promixis
May 19th, 2005, 06:04 AM
ands its simpler ;)

koekoek
June 7th, 2005, 07:42 AM
Hi, can somebody please describe for a noobie like me how to get this working?

I would appreciate it very much!!

Promixis
June 7th, 2005, 07:58 AM
Hi, can somebody please describe for a noobie like me how to get this working?

I would appreciate it very much!!

What remote/receiver are you using?

koekoek
June 7th, 2005, 08:03 AM
I'm using WinLIRC

Promixis
June 7th, 2005, 08:07 AM
Are you getting repeat events when you press your remote down?

koekoek
June 7th, 2005, 08:26 AM
If I push long on my buttons, I always get the same event, yes...

Promixis
June 7th, 2005, 08:31 AM
first download the buttommode plugin and enable it. if you can get it to generate up down repeat events for your remote.

koekoek
June 7th, 2005, 08:42 AM
Ok, it's working now

HUGE THANK YOU!!!!

Promixis
June 7th, 2005, 08:48 AM
Great :D

t-bear
August 10th, 2005, 05:26 AM
Does the buttonmode plugin work for girder 4?

Promixis
August 10th, 2005, 07:52 AM
Does the buttonmode plugin work for girder 4?

its built in.

t-bear
August 10th, 2005, 09:34 AM
I take it that you mean the event mapping editor. It generates down/repeat/up events for all my winlirc commands (cool!).

But is there a way (with lua, states or some other thing) to filter the down/repeat/up events so if i get a repeat event, i will not get the up event?

My up event triggers the next song, and the repeat triggers fast forward. (and first skipping fast forward and then changing to the next song doesn't make much sense)

Best regards
T-Bear

edit:
nevermind... i figured out a solution using two lua scripts. One triggers on the repeat event and increments a value the other on the up event. That way i can measure the time the button was held down, or just pressed (the value stays to 0)

Promixis
August 10th, 2005, 10:43 AM
I take it that you mean the event mapping editor. It generates down/repeat/up events for all my winlirc commands (cool!).

But is there a way (with lua, states or some other thing) to filter the down/repeat/up events so if i get a repeat event, i will not get the up event?

My up event triggers the next song, and the repeat triggers fast forward. (and first skipping fast forward and then changing to the next song doesn't make much sense)

Best regards
T-Bear

edit:
nevermind... i figured out a solution using two lua scripts. One triggers on the repeat event and increments a value the other on the up event. That way i can measure the time the button was held down, or just pressed (the value stays to 0)

cool, please post your code in the g4 forum.

t-bear
August 10th, 2005, 05:58 PM
Link to the requested post here :D
http://www.promixis.com/phpBB2/viewtopic.php?t=12312