Raising keyboard events through an interface in WPF

I am trying to create an application in WPF where I want to handle inputs (KeyPress events) from multiple keyboards connected to the same computer. So, I have one class where I redefine the WndProc () method and can receive data from different keyboard devices. In doing so, I register this class with the MainWindow descriptor, and therefore the window can receive CLR keyboard events. But it's not a problem.

The problem is that I am now developing UserControlin WPF, which can also respond to these events with multiple keyboards. These UserControlswill be created in one window, but I was thinking of sending events (especially how RoutedEvents) via the interface. So my user class, UserControl, just implements the interface, and I'm good to go.

You guys know how to do this, I'm really new to WPF, so I'm having some difficulties.

Thanks in advance!

0
source share
1 answer

, , . BIFUserControl, , , . IMultiKeyboardEvents. , BIFKeyboardDevice.

, , , BIFKeyboardDevice. , CLR BIFKeyboardManager, , .

IMultiKeyboardEvents, :

public interface IMultiKeyboardEvents  
{
    event MultiKeyEventHandler MultiKeyDown;
    event MultiKeyEventHandler MultiKeyUp;

    void OnMultiKeyDown(MultiKeyEventArgs);
    void OnMultiKeyDown(MultiKeyEventArgs);
}

, WndProc(), , , :

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;
        }
    }
}

OnMultiKeyDown UserControl, . , ( ), , , , , .

0

All Articles