112 CHAPTER 5 Scripting
5.5 CHDK commands
In sections 5.3 and 5.4, we looked at the language features of uBasic and
Lua. None of these language features are able to invoke specific camera
functions. For that purpose, the CHDK implementations of uBasic and Lua
provide extra commands enriching both languages. The names of the com-
mands are the same in both languages. The main difference is that in Lua,
parameters are enclosed in parentheses and separated by commas,
whereas the CHDK command is implemented as a function. In uBasic, the
parameters are simply listed behind the command name and separated by
blanks. While values can be returned through parameters in uBasic, Lua
only allows returning values as a function result. For example:
is_key r "right" uBasic
r = is_key("right") Lua
Some commands return Boolean values (true or false). Unlike Lua, uBasic
does not have a Boolean datatype. Those values are therefore returned to
uBasic as 0 (false) or 1 (true).
5.5.1 Button-related commands:
press "button-name" uBasic
press("button-name") Lua
A button is pressed and held down. Normally, this command is followed later by a
release command for the same button name.
release "button-name" uBasic
release("button-name") Lua
A button is released. If the button was not pressed, the command does not have any
effect.
click "button-name" uBasic
click("button-name") Lua
A button is pressed and immediately released.
shoot uBasic
shoot() Lua
Similar to click "shoot_full". In contrast to the click command, the shoot com-
mand will, however, perform all the automatic actions such as focusing, exposure
control, and flash setup before releasing the shutter.