Author Topic: Quick Binding Keys  (Read 3456 times)

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
Quick Binding Keys
« on: September 23, 2009, 10:06:05 AM »
Quick Binding Keys

Command is used to bind word under cursor (if it is a _command) or the current _command procedure
the cursor is in or on to the specified keys.

Usage: Place cursor over a word that is a _command, or within a _command procedure and run macro from a hotkey.
You will be prompted for the number of keystrokes, then you will be asked to press those keystrokes.

Shortcomings: You cannot extend the key tree - ie if you do not have key1,key2,somekey defined, meaning
key2 is undefined or is a leaf on the tree... if you go to define key1,key2,key4 it will fail when you press
key2 even though you specified 3 keys. Extensions to the key tree can be done through normal GUI for keybindings,
then extended once you made key2 a branch.

No warnings are given for stepping on or overwrite of keys.

Code: [Select]
_command is_cmd(...)
{
   p=current_proc(false);
   if (arg()==1) {p=arg(1);}
   return (find_index(p,COMMAND_TYPE)!=0);
}

_command bind_cur_word_alt()
 //bind_cur_word_alt is bound to Ins Space =
 {
    if (command_state()) {return (0);}
    s=cur_word(0);
    if (s==''||!is_cmd(s)) {
       s=current_proc(false);
    }
    if (!is_cmd(s)) {
       _message_box(s' is not a command','Alert',MB_OK|0|MB_ICONINFORMATION);
       return(0);
    }
    sa=letter_prompt('Number of Keys or 0 to Quit','1234567890');
    if (sa==''||sa=='0') {return (0);}
    ss='-'sa' -r 's;
    bind_to_key(ss);
    ss=where_is(s,1);
    message(ss);
 }