Author Topic: Long key press emulation problems  (Read 1871 times)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1707
Long key press emulation problems
« 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:

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

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12183
  • Maintenance mode
Re: Long key press emulation problems
« Reply #1 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

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1707
Re: Long key press emulation problems
« Reply #2 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

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12183
  • Maintenance mode
Re: Long key press emulation problems
« Reply #3 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.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1707
Re: Long key press emulation problems
« Reply #4 on: October 31, 2016, 01:39:59 PM »
@A1ex

Good ideas are easy :-)

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

Cheers

Garry