detect key release



  • On 05/07/2018 at 21:59, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R19 
    Platform:   Windows  ;   Mac OSX  ; 
    Language(s) :     C++  ;   PYTHON  ;

    ---------
    Hello,

    In continuation to the shortcut-key topic and the sticky-key bug, I was looking for a way to detect a key release.
    Let's say I have a SceneHook, in its KeyboardInput I can detect a key being pressed.
    This method is being called when the user presses a key, or when the key is kept pressed down.
    Is there any way to detect the key being released?

    Note, we're in a SceneHook, performing a while loop to check for the release of the key is thus not an option. Moving all the logic into a ToolData is not an option either.



  • On 09/07/2018 at 02:26, xxxxxxxx wrote:

    Hi C4DS, thanks for writing us and sorry for coming back late.

    With regard to your question, being looking into ToolData out of discussion as you stated above, a plausible, but non-official, way to be informed about the key release could be represented by the next sub-optimal worrkaround.

    The idea is to store the key press state in a member variable of your SceneHookData plugin and at the SceneHookData::Execute() call time compare the stored value with the current one to detect a change in the state.

    Could it be worthy to give it a try? Maybe there could be some lag between the key release and the Execute() method execution but maybe it's something you could live with.

    Best, Riccardo



  • On 09/07/2018 at 03:08, xxxxxxxx wrote:

    Cannot get the Execute to work in the SceneHook.
    I mean, Execute isn't performed when I press a key, it only is called when I click the mouse button, which then leads to "Cinema 4D has triggered a breakpoint".

    I am capturing the pressed key in KeyboardInput and check in Execute as follows

    Bool WOTSceneHook::KeyboardInput(BaseSceneHook* node, BaseDocument* doc, BaseDraw* bd, EditorWindow* win, const BaseContainer& msg)  
    {
        Int32 key = msg.GetData(BFM_INPUT_CHANNEL).GetInt32();  
      mKeyPressed = key;  
      GePrint(String::IntToString(mKeyPressed));  
      
      return SUPER::KeyboardInput(node, doc, bd, win, msg);  
    }  
      
    EXECUTIONRESULT WOTSceneHook::Execute(BaseSceneHook *node, BaseDocument *doc, BaseThread *bt, Int32 priority, EXECUTIONFLAGS flags)  
    {  
      if (mKeyPressed)  
      {  
          BaseContainer bc;  
          if (GetInputState(BFM_INPUT_KEYBOARD, mKeyPressed, bc))  
          {  
              GePrint("mKeyPressed");  
          }  
      }  
      return  EXECUTIONRESULT_OK;  
    }  
      
    
    

    From the moment I pressed a key (with cursor in the viewport), I always get a "Cinema 4D has triggered a breakpoint" whenever the mouse leaves the viewport.

    I must be missing something.


Log in to reply