F1 Help for addin only

F1 Help for addin only

Dale.Bartlett
Collaborator Collaborator
3,234 Views
8 Replies
Message 1 of 9

F1 Help for addin only

Dale.Bartlett
Collaborator
Collaborator

I am adding Help to my addin and want the F1 key to call my help file (CHM) for the whole form, not just for the control that has focus. I am using the following code which is working fine. My problem is that F1 triggers Revit's online help after calling mine. Is there a way to prevent this keystroke going on to Revit? Many thanks. Dale   

 

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            // F1 for help on any control
            if (keyData == (Keys.F1))
            {
                HelpClick();

                // This keystroke was handled, don't pass to the control with the focus
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

 




______________
Yes, I'm Satoshi.
0 Likes
3,235 Views
8 Replies
Replies (8)
Message 2 of 9

RPTHOMAS108
Mentor
Mentor

If you were using KeyDown event then you could try setting e.Handled = True.

 

KeyDown also has KeyData to check for F1.

 

There is also a HelpRequested event which I'm not familiar with but again could try setting e.Handled = True. I presume it responds to F1 but the order in the call chain for this may be too late to prrvent subsequent event handlers.

 

I had a modeless form the other day and was pressing delete to delete something in the text box but the x icon in Revit was appearing to delete an element from the model. That was fixed by setting the parent, although I knew of the parent setting thing I wasn't that concerned about it for the form in question.

 

 

 

0 Likes
Message 3 of 9

Dale.Bartlett
Collaborator
Collaborator

Apologies for the double post. The alternative is to "set the form's KeyPreview to true. This will make sure the form get the keypress messages first and if you handle it, you can set e.Handled = true so it doesn't passed down to the controls." There is a bit of online discussion and dispute as to the correct method. Dale




______________
Yes, I'm Satoshi.
0 Likes
Message 4 of 9

Dale.Bartlett
Collaborator
Collaborator

My original need was to ensure F1 was context-sensitive to the host form rather than the control-with-focus. I now find  that in all addins that I test, F1 is either disabled, or calls Autodesk's online help default page. Autodesk's own addins have their pages in the on-line help, so they behave as expected. The code I provided initially is working perfectly with the exception that after calling my addin context help, it continues to open Autodesk's default page. I now realise that 3rd party addins should have some method to call their own F1 context-sensitive help independent of Autodesk's. Surely this has been addressed previously? Any advice very much appreciated. Regards, Dale 




______________
Yes, I'm Satoshi.
0 Likes
Message 5 of 9

Dale.Bartlett
Collaborator
Collaborator

This was in the duplicate post (cancelled)

 

hi, 

 

We can use Revit UI API and autodesk AdWindows assembly to control the contextual help for ribbon item;  please refer to code below FYI.

 

        /// <summary>
        /// Update ribbon item with given help uri, title, description, etc.
        /// </summary>
        private void UpdateRibbonContexualHelp(RibbonItem item, string helpUri, 
            string title, string description, string expandDescription, Uri expandVideo)
        {
            Type itemType = item.GetType();

            var mi = itemType.GetMethod("getRibbonItem",
              BindingFlags.NonPublic | BindingFlags.Instance);

            var windowRibbonItem = mi.Invoke(item, null);
            Autodesk.Windows.RibbonItem wndRibbonItem = windowRibbonItem as Autodesk.Windows.RibbonItem;
            item.SetContextualHelp(new ContextualHelp(ContextualHelpType.Url, helpUri));

            wndRibbonItem.ToolTip = new Autodesk.Windows.RibbonToolTip()
            {
                Title = title,
                Content = description,
                ExpandedContent = expandDescription,
                ExpandedVideo = expandVideo,
            };
        }

 I haven't tried this, but does it mean that while the Ribbon item addin form is active, F1 will call the specified helpURL? Dale




______________
Yes, I'm Satoshi.
0 Likes
Message 6 of 9

jeremytammik
Autodesk
Autodesk

Dear Dale,

 

Thank you for your query.

 

I used the contextual help functionality a couple of times in the past and never encountered the behaviour you describe:

 

 

Unfortunately, all of these date rather far back, so I cannot guarantee that they behave as expected nowadays.

 

If you are setting up and calling the contextual help properly, I would not expect the Autodesk help to pop up, or pop up as well, or afterwards, or at all.

 

You might want to submit a minimal reproducible case to demonstrate that, so we can ask the development team what they think about it, and whether that behaviour is intentional:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 9

Dale.Bartlett
Collaborator
Collaborator

Thanks Jeremy, I will put together a sample for the team's testing. Dale




______________
Yes, I'm Satoshi.
0 Likes
Message 8 of 9

jeremytammik
Autodesk
Autodesk

Following up on this issue in a new thread:

 

https://forums.autodesk.com/t5/revit-api-forum/contextual-help-not-working-from-within-a-command/m-p...

 

Best regards,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 9

jeremytammik
Autodesk
Autodesk

Solved in the follow-up thread and preserved for posterity by The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2018/03/contextual-help-best-practice.html

 

Many thanks to Dragos for solving and explaining this there.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes