Magic Lantern Forum

Developing Magic Lantern => Scripting Corner => Scripting Q&A => Topic started by: garry23 on October 31, 2016, 12:19:45 PM

Title: Long key press emulation problems
Post by: garry23 on October 31, 2016, 12:19:45 PM
I hope one of the Lua experts can help me out as I struggle to get a long key press working with the SET button.

Here is the test code:

function hfd_test(key)
if keymenu.submenu["Turn On/Off"].value == "Off" then
return true -- key works as normal
elseif key == KEY.SET and lv.enabled then -- user may be asking for an HFD move, so register dryos time
timer = dryos.ms_clock
return true
    elseif key == KEY.UNPRESS_SET and lv.enabled then -- test is HFD move requested
if dryos.ms_clock - timer > 3000 then
move()
return true
else
return true
end
end
end

event.keypress = hfd_test


If I'm in the ML menu and press SET, then SET seems to work as expected, ie if I hold SET for longer than 3000 ms, them my move function works, ie moving the lens. Also less than 3000ms SET works as normal, ie changing ML menu items.

If I leave the ML menu and go to LV, I seem to lose the 3000ms functionality, ie the long key press emulation.

Can some kind soul point out what I'm doing wrong?

Cheers

Garry
Title: Re: Long key press emulation problems
Post by: a1ex on October 31, 2016, 01:01:32 PM
In LiveView, SET does not always send unpress events (IIRC the exact behavior is model-dependent).

Similar to http://www.magiclantern.fm/forum/index.php?topic=17616.0
Title: Re: Long key press emulation problems
Post by: garry23 on October 31, 2016, 01:24:32 PM
@A1ex

Thanks for the reminder  ;D

Is there anyway, in Lua, coding a key to function normally, if pressed 'quickly', and be programmable for a long press.

I've looked at various options and can't find a way round this.

It would be a great 'feature' in Lua, ie long press functionality, ie greatly extending the use of the keys/buttons.

Cheers

Garry
Title: Re: Long key press emulation problems
Post by: a1ex on October 31, 2016, 01:28:43 PM
That's a good idea. There are some long-press implementations for getting into ML menu on some models, but nothing generic yet.
Title: Re: Long key press emulation problems
Post by: garry23 on October 31, 2016, 01:39:59 PM
@A1ex

Good ideas are easy :-)

Coding them in C++ is beyond me  >:(

Cheers

Garry