Getting keyboard keys from MessageData plugins



  • On 29/12/2013 at 14:04, xxxxxxxx wrote:

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

    ---------
    Hi,
    I'm having a very frustrating time getting the keyboard keys to return from a MessageData plugin.
    I've been able to get the key being pressed just fine in GeDialog and Tool plugins. But I can't seem to get it to work when using a MessageData plugin.
    All I can get working is the qualifier keys. Like when you press the Ctrl key for example.
    But no matter what I do. I can't get any of the the other keys, like the period key, to return when pressed.

    Bool MyMessage::CoreMessage(LONG id, const BaseContainer &bc)  
    {  
      //This code works just fine in my GeDialog plugins when used in the Message() method  
      //But it doesn't work here in the CoreMessage() method in my message plugin!!??  
      switch(bc.GetId())  
      {  
          case BFM_INPUT:  
          {  
            if(bc.GetLong(BFM_INPUT_DEVICE) == BFM_INPUT_KEYBOARD) //If the input is from the keyboard  
            {  
                String input = bc.GetString(BFM_INPUT_ASC);         //Create a string type variable...   
                if(input == ".")   
                {  
                   GePrint("You pushed the period key");      //<---Does not print!!  
                }  
           }  
           break;  
      }  
       
      }//End the key pressed case loop /////////////////////////      
        
        
        
        
    ///Trying to get the keys a different way  
    ///I can only get a qualifier to work...But not the individual keys like the period key >:(  
        
      BaseContainer state;  
      
      //This qualifier code works fine  
      GetInputState(BFM_INPUT_KEYBOARD, BFM_INPUT_CHANNEL, state);  
      if(state.GetLong(BFM_INPUT_QUALIFIER) & QCTRL)  
      {  
          GePrint("You pushed the ctrl key");     //<--- Yup...prints when the Ctrl key is pressed  
      }  
      
      
      //Why doesn't this work!!??  
      GetInputState(BFM_INPUT_KEYBOARD, BFM_INPUT_CHANNEL, state);  
      if(state.GetString(BFM_INPUT_ASC) == ".")  
      {  
          GePrint("You pushed the period key");    //<--- Nope...Nothing!!?  
      }  
      
      return TRUE;  
    }
    

    What am I doing wrong?

    -ScottA



  • On 29/12/2013 at 17:18, xxxxxxxx wrote:

    Well...I found another way to do it using a SceneHook plugin instead of a MessageData plugin.
    I had to override the KeyboardInput() method and check the key presses inside of there to make it work.

    Bool MySceneHook::KeyboardInput(BaseSceneHook* node, BaseDocument* doc, BaseDraw* bd, EditorWindow* win, const BaseContainer& msg)  
    {  
      LONG key = msg.GetLong(BFM_INPUT_CHANNEL);  
      
      String cstr = msg.GetString(BFM_INPUT_ASC);  
      if( cstr == ".")   
      {  
          GePrint("period");  
      }  
      
      return TRUE;  
    }
    

    The same code doesn't work in a MessageData plugin though.
    Why can't we get key presses in MessageData plugins?

    -ScottA

    *Edit -- Unfortunately it seems that checking for key presses like this in a SceneHook plugin makes all the shortcuts stop working while the editor window is currently selected. 😠



  • On 30/12/2013 at 04:23, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Edit -- Unfortunately it seems that checking for key presses like this in a SceneHook plugin makes all the shortcuts stop working while the editor window is currently selected. 😠

    From the SDK:

    Return   
        Bool   
            TRUE if the keyboard event was used, FALSE if it should be passed along.   
            Note: Always returning TRUE here will block all keyboard use.
    

    So... have you tried returning FALSE?



  • On 30/12/2013 at 07:37, xxxxxxxx wrote:

    Thanks for pointing that out Steve. I totally missed that one.
    Using FALSE solves the problem. Thumbs Up

    I'm still curious why MessagePlugins don't allow for checking key presses though.
    I'm wondering if it's a known limitation, a bug, or if I'm just missing something?

    -ScottA



  • On 30/12/2013 at 08:21, xxxxxxxx wrote:

    None of those things as far as I can see. MessageData plugins simply receive core messages and can take action depending on that message. If you look at core messages in the SDK, they are sent when something changes in the scene, which doesn't include a key press or mouse click, so there will be no message.



  • On 30/12/2013 at 10:36, xxxxxxxx wrote:

    But it does return key presses.
    Only for some strange reason. It only works when using the qualifier code (see my example).
    That's what's so puzzling to me.

    -ScottA



  • On 31/12/2013 at 06:05, xxxxxxxx wrote:

    Howdy,

    Well, it could be that some of the Cinema 4D core events may need to react to qualifier keys, I don't know for sure, but it sounds reasonable since qualifier keys are usually pressed and held, and don't normally invoke a repeat after a certain amount of time held, like the character keys do.

    Adios,
    Cactus Dan


Log in to reply