Inventor .NET Addin Wizard (InventorNetAddinWizard) provides kinds of Event Handler Wizards to help automatically and intelligently generate start code for even handlers and register them in a chosen Inventor addin server class when applicable.
The Inventor .NET Keyboard Events wizard is one of them. After a source file name is given and the Add button pressed, the event wizard Welcome page, Event Chosen page, Naming Convention and Addin Server chosen page, and Summary page will show up one after another.
If all events are chosen and other settings are like above, the even handler class will look like this:
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using Inventor;
namespace InventorNetAddinCS
{
public class KeyboardEventHanlder1
{
private KeyboardEvents mEventsObj;
public KeyboardEventHanlder1(KeyboardEvents obj)
{
mEventsObj = obj;
}
public void Register()
{
mEventsObj.OnKeyUp += KeyboardEvents_OnKeyUp_Handler;
mEventsObj.OnKeyPress += KeyboardEvents_OnKeyPress_Handler;
mEventsObj.OnKeyDown += KeyboardEvents_OnKeyDown_Handler;
}
public void UnRegister()
{
mEventsObj.OnKeyUp -= KeyboardEvents_OnKeyUp_Handler;
mEventsObj.OnKeyPress -= KeyboardEvents_OnKeyPress_Handler;
mEventsObj.OnKeyDown -= KeyboardEvents_OnKeyDown_Handler;
}
public void KeyboardEvents_OnKeyDown_Handler(int Key, ShiftStateEnum ShiftKeys)
{
MessageBox.Show("OnKeyDown");
}
public void KeyboardEvents_OnKeyPress_Handler(int KeyASCII)
{
MessageBox.Show("OnKeyPress");
}
public void KeyboardEvents_OnKeyUp_Handler(int Key, ShiftStateEnum ShiftKeys)
{
MessageBox.Show("OnKeyUp");
}
}
}
The leading edge Inventor .NET Addin Wizard (InventorNetAddinWizard) can be found and downloaded from the A Wizard for Inventor .NET Addin page.
Posted by: |