Detet keyboard input

Detet keyboard input

stever66
Advisor Advisor
1,695 Views
3 Replies
Message 1 of 4

Detet keyboard input

stever66
Advisor
Advisor

Is it possible to detect text input from the keyboard?  I don't see any revit specific commands related to getting keyboard input, so I'm hoping this is possible with general Windows C# routines.

 

The problem is, most general Windows examples showing key press events assume there is a form being displayed, and the code examples are tied to the form.  I don't want to add a form, I just want to detect key presses from within the revit window so I can expand on the Keyboard Shortcuts Revit includes.


Thanks,

Steve

 

1,696 Views
3 Replies
Replies (3)
Message 2 of 4

stever66
Advisor
Advisor

Any ideas on this?

 

does anyone think it's possible or not possible?

 

it really seems like revit would have an event handler for keyboard input.

 

0 Likes
Message 3 of 4

FAIR59
Advisor
Advisor

I don't think Revit has any Event for keyboard input. You could define your own Listener like this:

class Listener : System.Windows.Forms.NativeWindow
{
            public Listener(IntPtr hWnd)
            {
                // assign the handle and listen to this control's WndProc
                this.AssignHandle(hWnd);
            }

            protected override void WndProc(ref Message m)
            {
                // listen to WndProc here, do things
//                StringBuilder.AppendLine(string.Format("<{0}>,  {1}", m.Msg, m.ToString()));
                base.WndProc(ref m);
            }
        }
//      Process process = Process.GetCurrentProcess();
//      Listener intercept = new Listener(process.MainWindowHandle));
0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

I do not believe that you need a form to detect a key press.

 

I searched the internet for '.net detect key press' and found:

 

https://duckduckgo.com/?q=.net+detect+key+press

 

https://stackoverflow.com/questions/1100285/how-to-detect-the-currently-pressed-key

 

Cheers,

 

Jeremy

 



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

0 Likes