How do I make a button press correspond to a command? - Script Writing - CHDK Forum

How do I make a button press correspond to a command?

  • 6 Replies
  • 1444 Views
How do I make a button press correspond to a command?
« on: 27 / August / 2022, 09:50:04 »
Advertisements
Sorry for all the questions lately, but how do I make a button press execute something on the camera? I.E. pressing a button to zoom into a specific location.
Sent from my Canon PowerShot SX410 IS

*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
All lifetime is a loan from eternity.

Re: How do I make a button press correspond to a command?
« Reply #2 on: 27 / August / 2022, 10:54:15 »
No, I don't think you understand, (well, I guess I don't understand, but whatever) I want to know how pressing a button actually does something, and the wiki doesn't seem to explain very well.
Sent from my Canon PowerShot SX410 IS

*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
Re: How do I make a button press correspond to a command?
« Reply #3 on: 27 / August / 2022, 11:13:45 »
Code: [Select]
function getkey(x,...)
local k=0
local t=1000
console_redraw()
if ...~=nil then print("*<",...,">") end
if x==nil then x=42 end
if x<10 then sleep(33)
   repeat wait_click(9) until is_key "no_key"
   if x<8 then play_sound(x) end
   wait_click(t*t)
   if x~=8 then sleep(123) end end
if x>t then wait_click(x) end
 local ti=get_tick_count()

 while is_pressed "face" do k=1 end
 while is_pressed "up" do k=2 end
 while is_pressed "video" do k=3 end
 while is_pressed "left" do k=4 end
 while is_pressed "set" do k=5 end
 while is_pressed "right" do k=6 end
 while is_pressed "display" do k=7 end
 while is_pressed "down" do k=8 end
 while is_pressed "menu" do k=9 end
 while is_pressed "help" do k=11 end
 while is_pressed "playback" do k=13 end
 while is_pressed "print" do k=16 end
 while is_pressed "zoom_in" do k=22 end
 while is_pressed "zoom_out" do k=24 end
 while is_pressed "shoot_half" do k=29 end

 ti=get_tick_count()-ti
 while x==t do x=0
    k=get_orientation_sensor()
    if go==nil then go=k/90+99 end
    if k==0 then G=go else play_sound(1+k/90) end
    if k==90 then G=G-1 end
    if k==270 then G=G+1 end end
return k,ti
end

if getkey() == x then do_something() end  -- :)
« Last Edit: 27 / August / 2022, 11:19:23 by Caefix »
All lifetime is a loan from eternity.


Re: How do I make a button press correspond to a command?
« Reply #4 on: 27 / August / 2022, 11:26:03 »
Is that LUA or uBasic?
Sent from my Canon PowerShot SX410 IS

*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
Re: How do I make a button press correspond to a command?
« Reply #5 on: 27 / August / 2022, 11:38:10 »
It´s LUA, ubasic has no function(...) nor local variables.
ubasic needed a gosub "##keys" instead, like
Quote
:##keys
if is_pressed "down" then click "down"
if is_pressed "left" then click "left"
if is_pressed "right" then click "right"
if is_pressed "up" then click "up"
if is_pressed "set" then click "set"
if is_pressed "menu" then click "menu"
return
All lifetime is a loan from eternity.

Re: How do I make a button press correspond to a command?
« Reply #6 on: 27 / August / 2022, 11:58:48 »
Thank you!
Sent from my Canon PowerShot SX410 IS

 

Related Topics