PDA

View Full Version : HID Keyboard Example


apitaru
- 3rd December 2005, 17:08
Hi everybody,

I am attempting to extend the USBMOUSE example (provided with PBP under /usb18 folder), so the target device (18F2550 or 18F4550) would be recognized by WinXP/OsX as both an HID Mouse and Keyboard. I'm not clear on how to use the USB desc files and would appreciate any examples and advise. If anyone has an example for just a Keyboard, that would also be of great help.

Cheers
Amit Pitaru

Brooklyn, NY

Merfy
- 9th June 2006, 00:09
To implement a usb keyboard it is just a matter of setting up the descriptors properly. The hid documentation has a good example of the keyboard descriptor. http://www.usb.org/developers/devclass_docs/HID1_11.pdf

Here is the mouse example descriptor that has been modified to work as a keyboard. To send a key stroke to the PC is as simple as (similar to mouse example included with PBP):

USBOut 1, buffer, 8, endgame

after initializing the device
where buffer is 8x8bytes
1st byte = modifier keys (i.e. ctrl, alt, shift)
2nd byte = reserved
3-8 = keys pressed ( 0x04 = a, 0x05 = b, ...)

I don't know how to combine both a keyboard and a mouse together in one device but I have heard of making a composite device being one possible way. But as of yet, I have not got anything working.

I understand this is a late reply but hopefully someone else might get something from it.

Kamikaze47
- 12th June 2007, 18:27
Hi,
I realize I am resurrecting an old thread here, but I'm trying to get an 18F4550 to act as a "virtual keyboard". I've used Merfy's KBDDESC.ASM (above) and i've managed to get the PC to detect it as a keyboard, and can send keystrokes, however when I do, it seems to send the keystroke over and over and over until I send another one.

If I do this for example (and keep in mind this line is only run once):

USBOut 1, buffer, 8, endgame

where buffer=[0,0,$14,0,0,0,0,0] ' ($14=q)

the pc types "qqqqqqqqqqqqqqqqqqqqqq....." and on forever.

any suggestions?

skimask
- 12th June 2007, 18:54
Hi,
I realize I am resurrecting an old thread here, but I'm trying to get an 18F4550 to act as a "virtual keyboard". I've used Merfy's KBDDESC.ASM (above) and i've managed to get the PC to detect it as a keyboard, and can send keystrokes, however when I do, it seems to send the keystroke over and over and over until I send another one.
If I do this for example (and keep in mind this line is only run once):
USBOut 1, buffer, 8, endgame
where buffer=[0,0,$14,0,0,0,0,0] ' ($14=q)
the pc types "qqqqqqqqqqqqqqqqqqqqqq....." and on forever.
any suggestions?
Not really sure if this has anything to do with your problem...
http://www.beyondlogic.org/keyboard/keybrd.htm

Looks to me like you you're on the right track...just not all the way there yet.
You've told the PC that you've pressed the 'q' key, but you haven't told the PC that you've released it, therefore, it repeats.
The first paragraph of the link above has some good info in it on the whole keyboard theory...should give you all the answers you need.