While key down? - Script Writing - CHDK Forum

While key down?

  • 1 Replies
  • 2891 Views
While key down?
« on: 06 / June / 2009, 20:05:10 »
Advertisements
I own a A950IS and I wanted it to loop a function when the key is hold down, such as UP.  I think in normal programming world, it would be something like...

:loop
if <UP is pressed> then goto "loopdown"
goto "loop"

:loopdown
<do this>
if <UP is pressed> then goto "loopdown" else goto "loop"

-----------------------------------------------

So yeah.  I want something to loop while the UP key is down.

Also, Could someone point me to a list of funcitons and keys?  Because I'm looking at other codes but I want to know all the functions.  Such as key_in...What others? Thanks!

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: While key down?
« Reply #1 on: 07 / June / 2009, 11:26:44 »
after some quick grepping on the source:

Code: [Select]
./core/luascript.c-static int luaCB_is_pressed( lua_State* L )
./core/luascript.c-{
./core/luascript.c:  lua_pushboolean( L, ubasic_camera_is_pressed(luaL_checkstring( L, 1 )));
./core/luascript.c-  return 1;
./core/luascript.c-}

Code: [Select]
./core/kbd.c:int ubasic_camera_is_pressed(const char *s)
./core/kbd.c-{
./core/kbd.c-    long k = keyid_by_name(s);
./core/kbd.c-    if (k==0xFF) return get_usb_power(1);
./core/kbd.c- if (k > 0) {
./core/kbd.c-        return (kbd_is_key_pressed(k));
./core/kbd.c-    } else {
./core/kbd.c- ubasic_error = 3;
./core/kbd.c-    }
./core/kbd.c-    return 0;
./core/kbd.c-}

Code: [Select]
./core/kbd.c:} keynames[] = {
./core/kbd.c-    { KEY_UP,           "up"         },
./core/kbd.c-    { KEY_DOWN,         "down"       },
./core/kbd.c-    { KEY_LEFT,         "left"       },
./core/kbd.c-    { KEY_RIGHT,        "right"      },
./core/kbd.c-    { KEY_SET,          "set"        },
./core/kbd.c-    { KEY_SHOOT_HALF,   "shoot_half" },
./core/kbd.c-    { KEY_SHOOT_FULL,   "shoot_full" },
./core/kbd.c-    { KEY_ZOOM_IN,      "zoom_in"    },
./core/kbd.c-    { KEY_ZOOM_OUT,     "zoom_out"   },
./core/kbd.c-    { KEY_MENU,         "menu"       },
./core/kbd.c-    { KEY_DISPLAY,      "display"    },
./core/kbd.c-    { KEY_PRINT,        "print"      },
./core/kbd.c-    { KEY_ERASE,        "erase"      },
./core/kbd.c-    { KEY_ISO,          "iso"        },
./core/kbd.c-    { KEY_FLASH,        "flash"      },
./core/kbd.c-    { KEY_MF,           "mf"         },
./core/kbd.c-    { KEY_MACRO,        "macro"      },
./core/kbd.c-    { KEY_VIDEO,        "video"      },
./core/kbd.c-    { KEY_TIMER,        "timer"      },
./core/kbd.c-    { KEY_EXPO_CORR,    "expo_corr"  },
./core/kbd.c-    { KEY_MICROPHONE,   "fe"         },
./core/kbd.c-    { 0xFF,             "remote"     },
./core/kbd.c- { 0xFFFF,           "no_key"     },
./core/kbd.c-};

The keylist should also be in wiki.

Take a look at the example scripts.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal