views:

723

answers:

4

We're building some software for an in-house Kiosk. The software is a basic .net windows form with an embedded browser. The Kiosk is outfitted with a mat that the user steps on. When the user steps on the mat, it sends a key comination through the keyboard. When the user steps off the mat it sends a different key combination.

What we want to do is look for the key combination in our app, and based on if the user steps on or off, cause the browser to go to a different url.

How do you hook the keyboard to accomodate this type of situation?

+1  A: 

Here's a link to an article on keyboard hooking. Maybe that will help.

itsmatt
+1  A: 

I was doing a somewhat similar search just a short while ago regarding USB card readers.

I came across this article on CodeProject for handling raw input of devices.

My main goal was differentiating multiple devices that act as keyboards. Your device may have a different interface. It also may have an SDK and documentation. We don't know.

Joel B Fant
Very interesing, because my next task on this project is interfacing with a CDC card reader which can also act as a keyboard.
Jeremy
+2  A: 

If your window is the active window, then you can simply override the forms ProcessCmdKey as such below.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    const int WM_KEYDOWN = 0x100;
    const int WM_SYSKEYDOWN = 0x104;

    if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
    {
        switch (keyData)
        {
            case Keys.Down:
                this.Text = "Down Arrow Captured";
                break;

            case Keys.Up:
                this.Text = "Up Arrow Captured";
                break;

            case Keys.Tab:
                this.Text = "Tab Key Captured";
                break;

            case Keys.Control | Keys.M:
                this.Text = "<CTRL> + M Captured";
                break;

            case Keys.Alt | Keys.Z:
                this.Text = "<ALT> + Z Captured";
                break;
        }
    }

    return base.ProcessCmdKey(ref msg, keyData);
}
Tom Anderson
A: 

And if your application is NOT the main window, take a look at the RegisterHotkey Win32 API, with some info on p/invoke here.

Martin Plante