Magic Lantern Forum

Developing Magic Lantern => Scripting Corner => Topic started by: garry23 on January 05, 2017, 09:27:39 PM

Title: Simulated Q Button for EOSM
Post by: garry23 on January 05, 2017, 09:27:39 PM
Although the EOSM is rather limited in the number of buttons, many say this is made up for via the touch screen.

Maybe: but if you have 'fat fingers' or just like using buttons (like me), you may like to try this small helper script.

All it does is convert one of the EOSM buttons into a Q button: I use [INFO].

To use, simply put in the script folder, make sure Lua module is running and the script is in autorun mode.

The [INFO] is only switched to be a simulated [Q] when the ML menu is active: at all other times [INFO] acts like [INFO].

You can easily change KEY.INFO to, say, KEY.PLAY if you wish - your choice :)

With the script running, it is very easy to move through the ML menu on the EOSM simply using the main wheel and the [INFO/Q] button.

Usual caveats: works for me and I provide no guarantees  ;)

Cheers

Garry

Code: [Select]
q_pressed = false

function sim(arg)
if q_pressed == true and menu.visible then
key.press(KEY.Q)
q_pressed = false
return false
else
return true
end
end

function test4Q(key)
    if key == KEY.INFO and menu.visible then
q_pressed = true
return false
else
return true
end
end

event.keypress = test4Q
event.shoot_task = sim
Title: Re: Simulated Q Button for EOSM
Post by: DeafEyeJedi on January 05, 2017, 10:16:39 PM
Hell yeah @garry23 this one is smoking hot!
Title: Re: Simulated Q Button for EOSM
Post by: Licaon_Kter on January 05, 2017, 11:04:29 PM
I find Q ok, but nice LUA script reference. Thanks
Title: Re: Simulated Q Button for EOSM
Post by: garry23 on January 06, 2017, 08:37:37 AM
@Licaon_Kter

I agree the EOSM [Q] button gets you into the ML menus OK, but because on the EOSM the [Q] is also the [SET], you can't use that button to go backwards/out of the ML menus.

By simulating the Q on, say, the [INFO], you can go in/out of the ML menus.

The 'beauty' of the script is that this functionality only works when you need it, ie at all other times you have [INFO] or another button to sim [Q], operating as normal.

I must say, being able to move around the ML menu with the simulated [Q] greatly speeds up my access/control of the ML menus on the EOSM. Previously I found I was often missing the touch-Q, eg fat/cold fingers.

Cheers

Garry
Title: Re: Simulated Q Button for EOSM
Post by: a1ex on January 13, 2017, 09:43:59 AM
Reformatted the script a bit:

Code: [Select]
-- Open ML submenus with INFO
-- This script remaps the INFO button to [Q] when ML menu is active.

function remap_info_to_q(key)
  if key == KEY.INFO and menu.visible then
    key.press(KEY.Q)
    return false
  else
    return true
  end
end

event.keypress = remap_info_to_q

Changes:
- first comment line is what appears in menu
- second line appears in menu as help text (description)
- use spaces for indentation (tabs width may be different in other editors)
- renamed the event handler
- removed the shoot_task hook (discussed here (http://www.magiclantern.fm/forum/index.php?topic=18661))

Title: Re: Simulated Q Button for EOSM
Post by: garry23 on January 13, 2017, 09:59:44 AM
@A1ex

Once again: many thanks for your time.

I had noticed the indent 'problem' and will use spaces in future if I can. I'm currently using Visual Studio Code as my editor.

Now I know I can use key.press inside an event.keypress function (up until now I thought I couldn't as I thought it might create a 'recursive' situation), I will fix that in my other scripts.

Bottom line: I really appreciate you and others spending time mentoring/coaching us 'newbies'.
Title: Re: Simulated Q Button for EOSM
Post by: a1ex on January 13, 2017, 10:09:11 AM
Now I know I can use key.press inside an event.keypress function (up until now I thought I couldn't as I thought it might create a 'recursive' situation), I will fix that in my other scripts.

Canon's GUI code (where this event is placed) uses a message queue. Calling key.press will put a new message (a key event) in the queue, so the keypress hook will be called again, after the first one exits.
Title: Re: Simulated Q Button for EOSM
Post by: FGP on February 23, 2018, 02:37:20 PM
Hello guys, I tried to use this script but it does not seem to work with the last build :/
I tried both versions, the second versions is bring an error in LUA script.

Also, using the LUA script makes it a bit slower to start the EOS-M, so I think I will finally pass on that.
Too bad this is not implemented in the build fore EOS-M though.

Just reporting ;)
Title: Re: Simulated Q Button for EOSM
Post by: a1ex on February 24, 2018, 12:08:11 PM
Too bad this is not implemented in the build for EOS-M though.

Please try the experimental lua_fix build (it uses a long SET/Q press (https://bitbucket.org/hudson/magic-lantern/pull-requests/722/eos-m-long-press-set-q-to-open-submenus/diff) to open submenus), and report back if you want this feature in mainline (since I need to know how well it works in order to include it).
Title: Re: Simulated Q Button for EOSM
Post by: garry23 on February 24, 2018, 12:14:20 PM
@FPG

As @a1ex says, try the latest experimental build, the long press works well  :)

Also, the original script was written for the EOSM back then and did work, but the Lua module evolves and scripts can become ‘broken’.

I have suggested that there be a Lua version data field, that script writers can access, ie to ensure older builds are not used. But with all the other development needs, this is hardly a priority item for the developers.

Title: Re: Simulated Q Button for EOSM
Post by: Jip-Hop on July 05, 2019, 01:28:38 PM
I was wondering about the Q button and if there's still the need for this script in Dannes builds for the EOS M.
But it's a bit tricky searching the thread for Q button when "Each word must be at least two characters long".
With the play button I can enter and exit submenu's in ML menu.
Title: Re: Simulated Q Button for EOSM
Post by: Walter Schulz on July 05, 2019, 07:33:56 PM
Enter this in google:
Code: [Select]
"eos m" "q button" site:magiclantern.fm/forum"" = match string
site: = restrict to given location (and sub URLs)
Title: Re: Simulated Q Button for EOSM
Post by: Jip-Hop on July 05, 2019, 08:12:24 PM
Clever!
Found this thread https://www.magiclantern.fm/forum/index.php?topic=15681.new#new

I understand now where my confusion comes from. I kept seeing the Q button (which is also the SET button) in the ML interface but now I understand it's remapped to the play button while in ML menu.
Title: Re: Simulated Q Button for EOSM
Post by: a1ex on July 05, 2019, 09:06:01 PM
Indeed, the EOS M could use a different icon, as PLAY is now the primary way of opening submenus on this camera. See e.g. here (https://www.magiclantern.fm/forum/index.php?topic=17056) for how it was done on other models without a Q button.

This change (PLAY button for submenus (https://www.magiclantern.fm/forum/index.php?topic=4386.msg198777#msg198777)) was done with EOS M in mind, but it was applied to all models (alongside the real Q button, where present).
Title: Re: Simulated Q Button for EOSM
Post by: Jip-Hop on July 05, 2019, 09:30:11 PM
Interesting, thanks a1ex!
Title: Re: Simulated Q Button for EOSM
Post by: ichthys on January 28, 2021, 03:41:03 PM
Reformatted the script a bit:

Code: [Select]
-- Open ML submenus with INFO
-- This script remaps the INFO button to [Q] when ML menu is active.

function remap_info_to_q(key)
  if key == KEY.INFO and menu.visible then
    key.press(KEY.Q)
    return false
  else
    return true
  end
end

event.keypress = remap_info_to_q

Changes:
- first comment line is what appears in menu
- second line appears in menu as help text (description)
- use spaces for indentation (tabs width may be different in other editors)
- renamed the event handler
- removed the shoot_task hook (discussed here (http://www.magiclantern.fm/forum/index.php?topic=18661))

Fixed a bug with your code. You are using 'key' as the function parameter to remap_info_to_q which overloads the global 'key' module.

Code: [Select]
-- Open ML submenus with INFO
-- This script remaps the INFO button to [Q] when ML menu is active.

function remap_info_to_q(pressed_key)
  if pressed_key == KEY.INFO and menu.visible then
    key.press(KEY.Q)
    return false
  else
    return true
  end
end

event.keypress = remap_info_to_q
Title: Re: Simulated Q Button for EOSM
Post by: garry23 on January 28, 2021, 06:54:10 PM
@ichthys

As that post was originated by me, but tweaked by @a1ex I’ll restrict my comment to within my ignorance.

I thought variables listed in a function call were defined as local.

But, I’m most probably wrong, as my ignorance continues to grow as a learn more about Lua 😀
Title: Re: Simulated Q Button for EOSM
Post by: ichthys on January 29, 2021, 10:18:41 AM
@garry23

Variables are local. The problem is that by defining a local variable/parameter 'key' you then cannot refer to the global 'key' to do: key.press(KEY.Q).

By doing key.press(KEY.Q) you are trying to refer to the local variable 'key' and call the method .press() which doesn't exist for that local parameter.
Title: Re: Simulated Q Button for EOSM
Post by: garry23 on January 29, 2021, 11:35:09 AM
@ichthys

I think I see what you are saying and, of course, that post is old.

I personally would now not call key.press inside the key event handler.

Instead I would set a flag and call key.press in, say, the shoot_task event handler, as I do in my MUSIC script, https://gist.github.com/pigeonhill/7b02d3dcadddbc703940778d74cd7af2?ts=4