Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Getting keyboard keys from MessageData plugins

 Post Reply Post Reply
Author
Message
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Topic: Getting keyboard keys from MessageData plugins
    Posted: 2013 Dec 29 at 2:04pm

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
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2013 Dec 29 at 5:18pm
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. Ouch


Edited by ScottA - 2013 Dec 29 at 5:36pm
Back to Top
spedler View Drop Down
Member
Member


Joined: 2008 Apr 19
Location: United Kingdom
Online Status: Offline
Posts: 673
Post Options Post Options   Quote spedler Quote  Post ReplyReply Direct Link To This Post Posted: 2013 Dec 30 at 4:23am
Originally posted by 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. Ouch


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?
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2013 Dec 30 at 7:37am
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
Back to Top
spedler View Drop Down
Member
Member


Joined: 2008 Apr 19
Location: United Kingdom
Online Status: Offline
Posts: 673
Post Options Post Options   Quote spedler Quote  Post ReplyReply Direct Link To This Post Posted: 2013 Dec 30 at 8:21am
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.


Edited by spedler - 2013 Dec 30 at 8:21am
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2013 Dec 30 at 10:36am
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
Back to Top
Cactus Dan View Drop Down
Member
Member
Avatar

Joined: 2003 Apr 18
Location: United States
Online Status: Offline
Posts: 1053
Post Options Post Options   Quote Cactus Dan Quote  Post ReplyReply Direct Link To This Post Posted: 2013 Dec 31 at 6:05am
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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.