CHDK Wiki
Register
Advertisement

Note: This page is designed to replace Script commands page in future. Currently it is just a stub.

See also the Scripting Cross Reference Page for the complete list of CHDK scripting commands for Lua and uBASIC.

To documentation writers[]

It is well known, that documentation should be clear to prevent confusions and avoid many questions from users. This new version of script commands documentation is designed to provide new, complete informations about commands, their usage and examples of code, where this can be used.

I'm sure, that these commands should be ordered by type, for example: shooting-related, hardware-related, console and drawing related. The next odrer should be alphabetical.

The form[]

Commands should have the form, that is presented below for print command.

print - just an example[]

languages: uBASIC, Lua.

This command provides you a method to display a text on scripting virtual console. Each string will be displayed in new line. Argument may be string or number.

Usage in Lua:

print("Hello World!")

Usage in uBASIC:

print "Hello World!"


Above lines will display following text on virtual console:

Hello World!

Camera operation commands[]

click[]

Languages: uBASIC, Lua.

This command emulates short pressing ot the appropriate button. That means it works as if you press and immediately release the button.

Usage in Lua:

click("button_name")

Usage in uBASIC:

click "button_name"


For example if you want to camera think that you clicked "left" button you should do:

Example in Lua:

click("left")


List of buttons that can be used:

  • shoot_half
  • shoot_full
  • left
  • right
  • up
  • down
  • set
  • zoom_in
  • zoom_out
  • display
  • menu
  • (others?)

Note 1: click command have an impact to the Canon firmware, not CHDK. So if you click "shoot_full" from a script you'll not end the script but take a shoot rather.

Note 2: see also press and release commands.


get_movie_status / set_movie_status[]

Languages: uBASIC, Lua.

get_movie_status[]

Returns status of movie recording. Status is as follows:

  • 0 - means not recording
  • 1 - means recording is paused
  • 4 - recording is in progress
  • 5 - recording is stopped, but camera still writes movie to SD card

set_movie_status[]

Experimental command, it is known, that works on a720 & s3is properly. Using this command you can pause, unpause and stop video recordings. Set to:

  • 1 - causes pause
  • 2 - unpause
  • 3 - stop

This command will not work on all cameras, typically they freeze or shutdown after 2 seconds !

Usage in Lua:

x = get_movie status()
set_movie status(1)


Usage in uBASIC:

get_movie status x
set_movie status 1


get_zoom_steps[]

Languages: uBASIC, Lua.

Returns number of maximum zoomsteps, regardless of camera hardware, this means for example on a620 it will return 8, on s3is it will return 128. this will allow for universal zoom scripts.

Usage in Lua:

​x = get_zoom_steps()

Usage in uBASIC:

get_zoom_steps x


get_shooting[]

Languages: uBASIC, Lua.

Command used to check whether the camera is able to take a shot at the moment and if all pre-shooting processes are complete. For example, when you half press the shutter button, the camera needs to check focus, exposure and other things. If this is the case when the get_shooting command is run, it returns false. If the camera is able to shoot then the command returns true.

Usage in Lua:

​x = get_shooting()

Usage in uBASIC:

get_shooting x

Example of usage (Lua):

​press("shoot_half")
repeat
    sleep(50)
    until get_shooting() == true
click("shoot_full")
release("shoot_half")

The above code emulates half-pressing of shutter button, waits until the camera is able to take a photo, and then just fully presses the shutter button to take the shot. Note that this code works essentially like shoot function.


is_key[]

Languages: uBASIC, Lua.

This command is used to check, whether appropriate key was pressed after wait_click command. In Lua it returns true or false. In uBASIC it returns 1 or 0

Usage in Lua:

x = is_key("button_name")

Usage in uBASIC:

currently there are two ways to use this command in uBASIC. First one:

x = is_key "button_name"

and the second:

is_key x "button_name"

Both uBASIC usages result the same value of x variable.

Example in Lua:

print("Press any key")
wait_click(0)
if is_key("menu") == true then
    print("You've pressed 'menu'!")
else
    print("You haven't press 'menu'")
end


Note: you could also this form:

Example in Lua:

print("Press any key")
wait_click(0)
x = is_key("menu")
if x == true then
    print("You've pressed 'menu'!")
else
    print("You haven't pressed 'menu'")
end


See also: is_pressed, click, press, wait_click.


is_pressed - need to improve[]

Languages: uBASIC, Lua.

Checks wheter specified button is being pressed when the command is called. The main difference between is_pressed and is_key is that is_key requires wait_click command. The is_pressed command allows you to not wait for anything, just check key on-the-fly.

Also - it provides a method to check whether two buttons are pressed at the same time.


Usage in Lua:

x = is_pressed("button_name")

Usage in uBASIC:

x = is_pressed "button_name"


Example in Lua:

print("count until you press 'menu'")

x=0
repeat
    x=x+1
    until is_pressed("menu")

print("I counted for "..x)

press[]

Languages: uBASIC, Lua.

Emulates pressing of appropriate button. That means it works as if you press and hold (not release) the button.Still holding the button is the main difference between press and click command.

Usage in Lua:

press("button_name")

Usage in uBASIC:

press "button_name"


If you want to half-press and hold shoot button (e.g. to get focus) do:

Example in Lua:

press("shoot_half")


Note: do not forget of releasing the button.

See also: click and release commands.


release[]

Languages: uBASIC, Lua.

Emulates releasing of the button which pressing was emulated by press command.

Usage in Lua:

release("button_name")

Usage in uBASIC:

​release "button_name"


Example in Lua:

press("shoot_half")
repeat
    sleep(50)
    until get_shooting() == true
click("shoot_full")
release("shoot_half")


Note 1: without release command camera would 'think' that half-shoot button is still pressed.

Note 2: releasing of shoot_full button is not needed in above code because it wass clicked not pressed.

See also: press and click commands.


shoot[]

Languages: uBASIC, Lua.

This command causes camera to perform whole shooting action: it involves all processess that camera do before shoot (just like half pressing shoot button) and then shoots. For example: if in AUTO, P, Tv, Av, or any SCN modes, using the "shoot" command causes the camera to check focus and exposure for each shot. When "shoot" is used in intervalometer scripts this far surpasses the camera's own built-in intervalometer in that the camera only sets exposure and focus once for the initial exposure, as if it was only using the "click 'shoot_full'" command. This "shoot" command in an intervalometer script allows it to compensate for all the things that can change over the course of many minutes and hours.

Usage in Lua:

​shoot()

Usage in uBASIC:

​shoot

Shoot function takes no arguments.


wait_click[]

Languages: uBASIC, Lua.

Causes script to wait untill any key is pressed or timeout is reached.

Usage in Lua:

wait_click(timeout)

Usage in uBASIC:

wait_click timeout


Timeout is a number of miliseconds that script will be waiting. If timeout=0 then script will be wait for ever for your press;)

Example in Lua:

print("press 'menu' in 3 sec")
wait_click(3000)
if is_key("menu") then
    shoot()
    end


Above script will wait for 3 seconds for pressing "menu" button. If user press this button during this time script will perform a shoot. If user press other key or not press anything within 3 second script will just end.

See also: click, press, release commands.

Advertisement