Using is_key properly in a loop? - Script Writing - CHDK Forum  

Using is_key properly in a loop?

  • 1 Replies
  • 1659 Views
Using is_key properly in a loop?
« on: 11 / August / 2023, 21:15:49 »
Advertisements
Hello, I have a question about using is_key in conjunction with a loop, I'll show an example

Code: [Select]
:loopfull
if is_key "left" then set_focus a and sleep 500
if is_key "right" then set_focus b and sleep 500
if is_key "set" then shoot_full
if is_key "down" then end
goto "loopfull"

When I press set to shoot, every time the loop repeats, it takes a shot, even long after I have let go of the button. Is there a solution/workaround available? Thanks!
Sent from my Canon PowerShot SX410 IS

*

Offline reyalp

  • ******
  • 14082
Re: Using is_key properly in a loop?
« Reply #1 on: 11 / August / 2023, 22:32:32 »
If you use is_key, you should use wait_click at the start of your loop, see https://chdk.fandom.com/wiki/CHDK_scripting#is_key
is_key returns whether the key was clicked, and that state isn't reset until you call wait_click again.

You can use is_pressed to determine if a key is currently pressed (without needing wait_click), but wait_click + is_key probably makes more sense for your script.
Don't forget what the H stands for.

 

Related Topics