How to use laptop keyboard as input

jmasis's Avatar

jmasis

21 Mar, 2017 09:22 PM

Hi there,

I'm interested in prototyping a protocol on humans before running it with animals and being able to run it on a laptop where the subject can respond with the keyboard would be very helpful. I read something about a "USB HID" device but I'm not exactly sure how to set this up.

Thank you!

Javier

  1. Support Staff 1 Posted by Christopher Sta... on 22 Mar, 2017 02:45 PM

    Christopher Stawarz's Avatar

    Hi Javier,

    Yes, a USB HID device is what you need. I've attached a simple example experiment that reports the state of the spacebar.

    The only trick with USB HID devices is figuring out the correct usage page and usage values for the input you want to monitor. With a keyboard, the easiest way to do it is to set the device's log_all_input_values parameter to YES, press and release the desired key, and then check the output in MWServer's console window. In my tests, every key press or release generates four HID input values. You want the usage-page/usage pair whose value goes to 1 when the key is pressed and changes to 0 when it's released.

    For example, pressing and releasing the "A" key generates the following output in the server console:

    00:09:21:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      4294967295  (0xFFFFFFFF)
        Value:      4
    00:09:21:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      1   (0x01)
        Value:      0
    00:09:21:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      4   (0x04)
        Value:      1
    00:09:21:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      4294967295  (0xFFFFFFFF)
        Value:      4
    00:09:22:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      4294967295  (0xFFFFFFFF)
        Value:      0
    00:09:22:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      1   (0x01)
        Value:      0
    00:09:22:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      4   (0x04)
        Value:      0
    00:09:22:  HID input on device "keyboard":
        Usage page: 7   (0x07)
        Usage:      4294967295  (0xFFFFFFFF)
        Value:      0
    

    In this case, usage page 7, usage 4 has a value that's first 1 and then 0, so that's the pair you need.

    If you need further assistance, please let me know.

    Chris Stawarz

  2. 2 Posted by jmasis on 24 Mar, 2017 07:34 PM

    jmasis's Avatar

    Hey Chris,

    Thanks for the reply. I will look into this and get back to you!

    Best,

    Javier

  3. Christopher Stawarz closed this discussion on 28 Apr, 2017 01:52 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac