Need Help: RawInput Question Pls

67 views
Skip to first unread message

kcpj...@gmail.com

unread,
Dec 4, 2013, 1:24:31 PM12/4/13
to slimdx...@googlegroups.com
Hello,
 
Firstly, thank you for all the great efforts on SlimDX. First time user.
 
I am creating a super simple example.
 
  • Language VB.NET 2012
  • Windows Forms
  • Single Text Box
  • Desire: Capture RawInput messages
Steps Taken:
  • Created Form
  • Added Text Box
  • Registered Device (have a question on this)
  • Added Handlers (RawInput and Keyboard which I'll explain in a second)
  • Ran the Application
  • After playing with the parameters a bit, I get Keyboard Events (InputSink being used)
Problem:
  • I want to specifically get the RawInput message, not a keyboard event. I actually want the true original rawinput message, which appears you can get if you use the RawInput event
  • The RawInput event never fires though
  • The keyboard event fires whether the app is in the foreground or not (which is what I want)
Questions:
  1. I am a little confused on the registerdevice. It appears that you specify the type, not the actual devices (as if I created my own array and passed it in C++ to the registerrawinputdevice). Originally I was looping through all devices, finding the keyboards and went to register just that keyboard but I don't see how. Is there a way?
  2. I am trying to use RawInput specifically, but as you can see (the commented out multiple different attempts at getting it to work), yet the best I can do is get the KeyboardInput Handler to get trigger. How do you specifically get RawInput events to work?
  3. My goal is to leverage RawInput, not Keyboard Events but I cannot find an example and while the code seems like it should work, I can only get it to do anything, if I use a "Generic UsagePage", not a "Keyboard" setting, which doesn't make sense. Also my keyboards are keyboard1 (according to the device), but if I set the UsageId to keyboard1 versus keyboard it doesn't work
  4. Can you please point me to an example to make RawInput work directly please
 
 
Code:

Imports SlimDX.RawInput
Imports System.Collections
Imports System.Collections.Generic

Public Class Form1
    Dim m_Devices As IReadOnlyList(Of DeviceInfo)
    Dim m_KeyboardInfos As Dictionary(Of String, KeyboardInfo) = New Dictionary(Of String, KeyboardInfo)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            'Get the Devices
            m_Devices = SlimDX.RawInput.Device.GetDevices()

            'Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Keyboard, SlimDX.Multimedia.UsageId.Keyboard1, DeviceFlags.InputSink, Me.Handle)
            'Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Keyboard, SlimDX.Multimedia.UsageId.Keyboard1, DeviceFlags.InputSink, txtWindow.Handle)

            'Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Keyboard, SlimDX.Multimedia.UsageId.Keyboard, DeviceFlags.None, Me.Handle)
            'Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Keyboard, SlimDX.Multimedia.UsageId.Keyboard, DeviceFlags.None, txtWindow.Handle)

            'Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, DeviceFlags.None, Me.Handle)
            'Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, DeviceFlags.None, txtWindow.Handle)

            Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, DeviceFlags.InputSink, Me.Handle)
            Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, DeviceFlags.InputSink, Me.Handle)

            'Add our handlers
            AddHandler Device.KeyboardInput, AddressOf KeyboardInputSub
            AddHandler Device.RawInput, AddressOf RawInputSub

        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub

    Public Sub RawInputSub(sender As Object, rawinput As RawInputEventArgs)
        Try

            System.Diagnostics.Debug.WriteLine("")
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub

    Public Sub KeyboardInputSub(sender As Object, keyboardinput As KeyboardInputEventArgs)
        Try

            System.Diagnostics.Debug.WriteLine(keyboardinput.Key.ToString() + " has been " + keyboardinput.State.ToString())
            txtWindow.Text += vbCrLf + (keyboardinput.Key.ToString() + " has been " + keyboardinput.State.ToString()) + vbCrLf

        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub
End Class

 

Reply all
Reply to author
Forward
0 new messages