Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Detect a long button press

  1. #1
    Join Date
    Dec 2001
    Posts
    11,560

    Default Detect a long button press

    Code:
    --[[
    
    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

  2. #2
    Join Date
    May 2004
    Posts
    2,577

    Default Keyboard buffer problem

    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).

  3. #3
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    You want to have this script in a single command and then have the triggerevent call your multigroup - is that what you were doing?

  4. #4
    Join Date
    May 2004
    Posts
    2,577

    Default

    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.

  5. #5
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    Hm,

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

  6. #6
    Join Date
    May 2004
    Posts
    2,577

    Default

    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

  7. #7
    Join Date
    Jul 2004
    Posts
    78

    Default

    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.

  8. #8
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    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.

  9. #9
    Join Date
    Aug 2004
    Posts
    4

    Default

    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.

  10. #10
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •