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

detect key release

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


Joined: 2015 Dec 01
Online Status: Offline
Posts: 233
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Topic: detect key release
    Posted: 2018 Jul 05 at 9:59pm

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.
Back to Top
knickknack View Drop Down
Forum Moderator
Forum Moderator


Joined: 2016 Jul 01
Location: Italy
Online Status: Offline
Posts: 249
Post Options Post Options   Quote knickknack Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Jul 09 at 2:26am
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
MAXON Computer GmbH
SDK Support Team
Back to Top
C4DS View Drop Down
Member
Member


Joined: 2015 Dec 01
Online Status: Offline
Posts: 233
Post Options Post Options   Quote C4DS Quote  Post ReplyReply Direct Link To This Post Posted: 2018 Jul 09 at 3:08am
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.
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.109 seconds.