AddShortcut() [SOLVED]



  • On 02/06/2015 at 07:34, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R13.061  
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi there,

    the problem:

    Our plugin needs access to the CTRL+"C",  CTRL+"V" and CTRL+"X" keyboard shortcuts. Meaning, the plugin must be started when the modeler uses these shortcuts in the scenegraph window.

    I experimented with the api and found the following issues:

    1.) adding the shortcut via  AddShortcut() does not work. AddShortcut()  returns True, but probably the shortcut is overwritten by a previous set shortcut?
    Here is the code i use:

      
      BaseContainer bc;  
          bc.SetLong(SHORTCUT_PLUGINID, PID_CMD_AMT_COPY);   
          bc.SetLong(SHORTCUT_ADDRESS, 0);   
          bc.SetLong(SHORTCUT_OPTIONMODE, 0);   
      
          bc.SetLong(0, 2);   
          bc.SetLong(1, 67);   
          Bool res= AddShortcut(bc);   
    

    2.) Finding other shortcuts which use the same keys, removing them and then adding the shortcut does not work. Here is the code:

      
      
          BaseContainer bc;  
          bc.SetLong(SHORTCUT_PLUGINID, PID_CMD_AMT_COPY);   
          bc.SetLong(SHORTCUT_ADDRESS, 0);   
          bc.SetLong(SHORTCUT_OPTIONMODE, 0);   
      
          bc.SetLong(0, 2);   
          bc.SetLong(1, 67);   
      
      
          LONG nr= FindShortcuts(bc, shortCuts, sizeof(shortCuts)/sizeof(LONG));   
      
          for (int i=0; i< nr; i++)  
          {  
              Bool ok= RemoveShortcut(shortCuts[i]);        // failes   
          }  
      
          Bool res= AddShortcut(bc); // succeeds, but does not work  
    

    FindShortcuts() in the code above finds 2 shortcuts (indizes are: 13543,  12107), trying to remove them fails. LONG im= GetShortcutCount(); gives 319, so both these indizes are out of range.

    3.) The only way to assign the shortcut correctly is via  LoadShortcutSet(Filename("AMTShortcuts.txt"), FALSE); but this deletes all registered shortcuts, making it impossible for the modeler to set her own shortcuts. Using  LoadShortcutSet(Filename("AMTShortcuts.txt"), TRUE);  does not work.

    So how can I get these three shortcuts to work?

    Thanks in advance.



  • On 03/06/2015 at 02:28, xxxxxxxx wrote:

    Just fyi, found a way how  to do it. Don't use FindShortcuts(), instead search all shortcuts manually, Remove() them and add your shortcut.

      
      // remove all global ctrl+c  
          LONG im= GetShortcutCount();   
          for (int i=0; i< im; i++)  
          {  
              BaseContainer bc= GetShortcut(i);   
      
              LONG commandID= bc.GetLong(SHORTCUT_PLUGINID);            // e.g: PID_CMD_AMT_COPY  
              LONG shortcutAdress= bc.GetLong(SHORTCUT_ADDRESS);        // 0  
              Bool shortcutOptionMode= bc.GetBool(SHORTCUT_OPTIONMODE); // 0  
                
              LONG shortcutQualifier= bc.GetLong(0);    // =2, probably ctrl  
              LONG shortcutKey= bc.GetLong(1);        // =67,  == ascii 'C'  
                
              if (shortcutAdress ==0 && shortcutOptionMode==0 && shortcutQualifier==2 && shortcutKey==67)  
              {  
                  // found global CTRL+C  
                  RemoveShortcut(i);           
                  i--;  
              }  
          }  
      
          // add ctrl+c:  
          BaseContainer bc;  
          bc.SetLong(SHORTCUT_PLUGINID, PID_CMD_AMT_COPY);   
          bc.SetLong(SHORTCUT_ADDRESS, 0);   
          bc.SetLong(SHORTCUT_OPTIONMODE, 0);   
      
          bc.SetLong(0, 2);   
          bc.SetLong(1, 67);   
          Bool res= AddShortcut(bc);   
      
    

Log in to reply