[Haskell-cafe] ANNOUNCE: usb-0.3

Roel van Dijk vandijk.roel at gmail.com
Wed Dec 9 10:50:08 EST 2009

On Wed, Dec 9, 2009 at 4:20 PM, stefan kersten <sk at k-hornz.de> wrote:
> looks great, thanks! do you happen to have some example code for working with
> HID devices (mice, keyboards, etc.)?

The usb package does not support the various device classes directly.
You won't find a function like "isKeyPressed ∷ Device → KeyCode → IO
Bool". But you could write it based solely on functions from the usb
package. Enumerate the devices connected to your system, find your HID
device, open a handle (or enter a safe region), choose an interface
and an alternative and finally send some sort of control request
encoded in a ByteString. The actual bytes you need to send in order to
discover if some key on your USB keyboard is pressed is defined
somewhere in the USB HID device class specification.

If you really need that kind of functionality then you could create a
package "usb-hid" that offers an abstraction over the HID device
class. But if you just want to know if some key is pressed then a much
simpler solution would be to use a library like SDL or GLUT.

Keep in mind that all functions in the usb package run in *client
side*. To actually use a device (communication) you need the proper
permissions, which in practice implies super-user privileges.
Libraries like SDL interface with the kernel drivers and do not need
such permissions (correct me if I'm wrong).


More information about the Haskell-Cafe mailing list