Detect key press

Detect key press

AGGilliam
Collaborator Collaborator
2,582 Views
3 Replies
Message 1 of 4

Detect key press

AGGilliam
Collaborator
Collaborator

This is something that's come up a few times with my coworkers, that it would be nice to be able to place an element then press a key to rotate it so many degrees. After looking into it, it seems you can detect keys through a form or with some sort of hook but I was wondering if it were possible to attach this to Revit somehow.

 

I started trying to test this by grabbing the UIApplication.MainWindowHandle and using the user32.dll method to register a hotkey and overriding WndProc to perform a command, which was based on an example I found for doing this through Forms. I was able to register the key (as it stopped functioning until I closed Revit) but it still didn't seem to be able to detect it. I assume the WndProc method isn't going to work with anything other than a Form, but is there any other way to go about doing this within the Revit api?

0 Likes
Accepted solutions (1)
2,583 Views
3 Replies
  • API
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk
Accepted solution

The Revit API provides no support for keypress detection, so you will have to use the Windows API or .NET libraries for that:

 

https://duckduckgo.com/?q=.net+keypress+event

 

Furthermore, if you do detect a key press, you may not be within a valid Revit API context to be able to interact with the Revit API.

 

If you are within a modal dialogue launched by an external command, you may have a valid Revit API context. 

 

If not, please refer to external events and co.:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28

 



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

Message 3 of 4

AGGilliam
Collaborator
Collaborator

It seemed like I was so close, but it's starting to look like this is a bit beyond my skill level. Thanks for the help!

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

Yup, sorry, not quite so trivial... The Revit API is designed that way. There are reasons, mainly the paramount importance of the BIM integrity. Thank you for your appreciation.

   



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