Author Topic: Modifying Keys/Buttons  (Read 2002 times)


  • Contributor
  • Hero Member
  • *****
  • Posts: 1989
Modifying Keys/Buttons
« on: November 01, 2016, 11:39:19 PM »
For some time I have been trying to extend the functionality of the Canon keys in Lua scripting. In other words trying to get more out of a key, which could be useful to those with cameras with limited key access.

The idea I am sharing is as follows:
 - Select a key to have a modified role, ie KEY.RATE in the demo script below
 - Choose a second key to act as a modifier, ie KEY.PLAY in the demo below
 - Insert the Lua modified code, ie move the lens to the HFD point in the demo below
 - To use simply press any key as normal
 - Press KEY.RATE twice to use KEY.RATE in normal mode
 - Press KEY.RATE followed by KEY.PLAY to use the KEY.RATE button in modified mode

The script could be refined further, and I may well do that ;-)

Also the script is easy to extend, eg add other modified buttons.

As usual I welcome feedback of any kind.

Code: [Select]
Script to illustrate the use of key modification
Version 0.3 (should work on all ML enabled cameras with the Lua module)
Shows the use of a modified key approach using an AF lens auto positioned to the HFD
Garry George Oct 2016
For rhe HFD functionality must be in LV and in AF mode, and lens must report distance
Also make sure ML DoF set up as you require it, eg diffraction on
Also for the fastest move position lens at infinity end, ie macro end moves are slower
This version of the script does no error checking ;-)

-- Declare globals

mod_button_1 = KEY.RATE -- key to modify
mod_button_2 = KEY.PLAY -- key to indicate mod mode requested
last_key_pressed = 999 -- used to reset mod_button pairing

-- Choose buttons of your choice, eg KEY.RATE, KEY.UP, KEY.INFO or KEY.PLAY.
-- See for key constants

function move()
if lens.focus_distance < lens.hyperfocal then
until lens.focus_distance >= lens.hyperfocal
until lens.focus_distance <= lens.hyperfocal
repeat -- ensures lens is positioned with a bias towards INF
until lens.focus_distance >= lens.hyperfocal

function test4mod(key)
if keymenu.submenu["Turn On/Off"].value == "Off" then
return true -- all keys work as normal
elseif key == mod_button_1 and last_key_pressed == mod_button_1 then -- use moded key as normal
last_key_pressed = 999 -- reset
return true
    elseif key == mod_button_2 and last_key_pressed == mod_button_1 then -- use moded key in modified way
-- ****************** Place modified code here ************
last_key_pressed = 999 -- reset
move() -- to HFD position
-- ****************** Place modified code here ************
return false -- steal key press
elseif key == mod_button_1 then -- first press of modified key in new sequence
last_key_pressed = mod_button_1
return false -- steal key press
return true -- use all non-moded buttons in an unmodified way

event.keypress = test4mod

keymenu =
parent = "Shoot",
name = "HFD",
help = "Moves lens to HFD focus distance",
submenu =
name = "Turn On/Off",
help = "Switches the script on/off",
choices = {"On","Off"},