Key interaction - Script Writing - CHDK Forum

Key interaction

  • 8 Replies
  • 891 Views
Key interaction
« on: 30 / April / 2022, 04:29:20 »
Advertisements
Looking at the Lua key functions, I can’t see how to use wait_click and is_key to do the following.

1. Wait for a key press
2. Capture the name of the key press, ie that I put in a variable, say, KeyName
3. Use KeyName to do my stuff
4. If my stuff not needed, pass through the KeyName to the Canon side for normal Canon action

As I say, looking at the available Lua calls, I don’t think I can achieve the above.

But someone else may see a Lua solution ;-)
« Last Edit: 30 / April / 2022, 05:01:46 by pigeonhill »

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Key interaction
« Reply #1 on: 30 / April / 2022, 05:02:58 »
For 1, 2 & 3 you can look at the EDI.ua code (CHDK/SCRIPTS/EDITOR) - check the 'get_input' function.


I don't believe 4 is possible - button presses are blocked from the Canon UI when a script is running.
Reyalp may have more ideas on this.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: Key interaction
« Reply #2 on: 30 / April / 2022, 05:09:07 »
@philmoz

Thanks for the hint.

Having difficultly finding your example ;-)

Can you insert the URL?

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Key interaction
« Reply #3 on: 30 / April / 2022, 05:11:52 »
It's part of the standard CHDK installation - check the CHDK/SCRIPTS/EDITOR folder on the SD card.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)


Re: Key interaction
« Reply #4 on: 30 / April / 2022, 05:34:08 »
Got it  :)

*

Offline Caefix

  • *****
  • 947
  • Sorry, busy deleting test shots...
Re: Key interaction
« Reply #5 on: 30 / April / 2022, 08:01:41 »
A bit too ubasic  ;),... but easy to adapt...
Code: [Select]
:##keys
set_lcd_display 1
playsound 2
do
 k=0
 wait_click 50
 if is_pressed "zoom_in" then k=22
 if is_pressed "zoom_out" then k=24
 if is_pressed "shoot_half" then k=29
 if is_pressed "face" then k=1
 if is_pressed "up" then k=2
 if is_pressed "video" then k=3
 if is_pressed "left" then k=4
 if is_pressed "set" then k=5
 if is_pressed "right" then k=6
 if is_pressed "display" then k=7
 if is_pressed "down" then k=8
 if is_pressed "menu" then k=9
 if is_pressed "help" then k=11
 if is_pressed "wifi" then k=12
 if is_pressed "playback" then k=13
 if is_pressed "print" then k=16
rem some cams NEED is_key (Sx200), &Touchscreen?
 if k*(A=1) then gosub "##log"
 sleep 50
until E>2
return

:##log
playsound 4
if (K*k=5)+(Q=1) then return
k=k+Q*t
select k
  case 22,24; gosub "##zoom"
  case 1; click "face"
  case 2; click "up"
  case 3; gosub "##time2"
  case 4; click "left"
  case 5; click "set"
  case 6; click "right"
  case 8; click "down"
  case 9; click "menu"
  case 12; print "  click 'wifi'"
  case 13; exit_alt
  case 29; E=E+1
  case_else gosub "##fun"
end_select
sleep 99
select k
  case 1; print "  click 'face'"
  case 2; print "  click 'up'"
  case 4; print "  click 'left'"
  case 5; print "  click 'set'"
  case 6; print "  click 'right'"
  case 8; print "  click 'down'"
  case 9; print "  click 'menu'"
  case 12; print "  click 'wifi'"
  case 13; sleep t
  case 29; gosub "##baustelle"
  case_else print "sleep 999"
end_select
print "   sleep 99"
return
All lifetime is a loan from eternity.

Re: Key interaction
« Reply #6 on: 30 / April / 2022, 08:08:20 »
@Caefix

Thanks. I already use a similar approach, ie I’m not looking at how to use the current functionality, but looking to see if I was missing a trick  ;)

Cheers

Garry

*

Offline reyalp

  • ******
  • 14117
Re: Key interaction
« Reply #7 on: 30 / April / 2022, 17:15:00 »
Looking at the Lua key functions, I can’t see how to use wait_click and is_key to do the following.

1. Wait for a key press
2. Capture the name of the key press, ie that I put in a variable, say, KeyName
3. Use KeyName to do my stuff
4. If my stuff not needed, pass through the KeyName to the Canon side for normal Canon action

As I say, looking at the available Lua calls, I don’t think I can achieve the above.

But someone else may see a Lua solution ;-)
FWIW, the keyboard module in my contae.lua script (current source here https://github.com/reyalpchdk/chdkscripts/tree/main/src/contae) does something very much like this.
Don't forget what the H stands for.


Re: Key interaction
« Reply #8 on: 30 / April / 2022, 17:28:26 »
@reyalp

Many thanks, I’ll have a look.

Cheers

Garry

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal