Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, I figured out how to do this. I have a class called <code>BIFUserControl</code> which implements the interface I have created to handle events from multiple keyboards attached to the same computer. The interface is called <code>IMultiKeyboardEvents</code>. I also have a read-only collection which stores the current state of each keyboard device as instances of <code>BIFKeyboardDevice</code> class.</p> <p>So, basically I know what is the input focus for each keyboard device, which is represented as a property in the <code>BIFKeyboardDevice</code> class. So when raising a CLR event from Keyboard manager class <code>BIFKeyboardManager</code> I can actually call the interface method implementation in the exact class which has the input focus to a specific control.</p> <p>Here is the code for the interface <code>IMultiKeyboardEvents</code> which is implemented by the custom user control class:</p> <pre><code>public interface IMultiKeyboardEvents { event MultiKeyEventHandler MultiKeyDown; event MultiKeyEventHandler MultiKeyUp; void OnMultiKeyDown(MultiKeyEventArgs); void OnMultiKeyDown(MultiKeyEventArgs); } </code></pre> <p>And in the keyboard manager class which overrides the <strong>WndProc()</strong> method, I have a method which processes the input events which is as follows :</p> <pre><code>void ProcessInput(Message message) { // Code sample which raises just the key down event switch (rawInput.keyboard.Message) { case (uint) BIFWin32.WindowMessage.WM_KEYDOWN: { if (BIFDeviceCollections.MouseCollection[ID].MouseFocusElement is IMultiKeyboardEvents) { IMultiKeyboardEvents widget = (IMultiKeyboardEvent)BIFDeviceCollections.MouseCollection[ID].MouseFocusedElement; widget.OnMultiKeyDown(eventArgs); } break; } case (uint) BIFWin32.WindowMessage.WM_KEYUP: { if (BIFDeviceCollections.MouseCollection[ID].MouseFocusElement is IMultiKeyboardEvents) { IMultiKeyboardEvents widget = (IMultiKeyboardEvent)BIFDeviceCollections.MouseCollection[ID].MouseFocusedElement; widget.OnMultiKeyUp(eventArgs); } break; } } } </code></pre> <p>This simply calls the implementation of OnMultiKeyDown method in my <strong>UserControl</strong> class and I don't have to use use the keyboard manager instance in the user control class and hook up the events to listen to them. Also, as I have already a collection of all the device objects (mice and keyboards) and they maintain a field saying what is the current focus element for each device and also I have paired each mouse and keyboard device, so I can directly use this information to raise the events. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload