How does multi-key keyboard works?

Status
Not open for further replies.

Martin

Member
My first post. Lately in 07/12 Mark Stanley make multikeypress by default in 'keypad.h' library but as far as I understand that code (my understanding is very limit) I wonder how to translate it into the Teensy scenario "Normal Keys", where it's said that:

Keyboard.set_key1(KEY_A);
Keyboard.set_key2(KEY_B);
Keyboard.set_key3(KEY_C);
Keyboard.set_key4(KEY_D);
Keyboard.set_key5(KEY_E);
Keyboard.set_key6(KEY_F);

Because the limit was (still?) six push at the same time. Now my question, can I use keyN until the whole pins? or what is the new limit?. Please show me the way guys.
 
The USB Keyboard limit is 6 simultaneous keys pressed.

If is possible, but not easy, to increase the 6 key limit. To change the limit, you must edit the USB code. I could write a lengthy message about how to edit that code... but first I do not fully understand your question. If you really want to edit the USB code (which is not easy), just ask. Also, you didn't mention if you're using Teensy 2.0 or 3.0. They have different USB code, so the description about how to edit is similar but different in some important ways from 2.0 to 3.0.
 
Thank you Paul. I'm using Teensy 2.0... my pourpose is to create an arcade project using keyboard usb type fo 22 buttons and I need it to be able to push at least 10 keys at the same time (the more, the better). I can do that easy using Teensy as a joystick usb type but my point is to set it as keyboard with default keys config that MAME emulator has. I was thinking this feature (more than 6 keys) was already working due to an improvement of the arduino 'keypad.h' library recently added in july 2012 for multikey-press support, but you're saying is about to USB code. I just want it to work :D
 
The Keypad library is a 3rd party library. It's not developed by PJRC... but I did personally test the older version, and testing the new one and updating that page is on my to-do list. Still, the software development of Keypad is separate from PJRC's development of the USB code and other core library functions.

The normal USB keyboard protocol can communicate 6 normal keys and 8 modifier keys. If you can use those 8 modifiers, which are left & right of shift, control, alt, and "gui" (the windows key or apple's cmd key), you can get 14 total with the normal protocol.

If you want more, it is possible, but involves hacking the USB code.
 
Paul , it would be nice if you can increase the keys number by hacking the USB code as you say :D. You'll see, before I know about teensy I was watching 2 projects that involves arcade functions. One of these is the I-PAC project , whose sell it sefl like this:

I-PAC is the ONLY keyboard encoder which emulates a USB keyboard (and PS/2) and yet breaks through the USB simultaneously-pressed-switch limit of 6 switches (plus ctrl,alt,shift) which afflicts all USB keyboard devices. This is beacuse it has inbuilt full native USB support, and does not rely on an add-on adaptor.

The other one is a kickstarter project named KADE. They have default MAME config within, which is what I want to do in order to put it easy to average people. Not being able to push more than 6 butttons entails problems in gameplay, it's annoying when someone goes crazy and push almost all of the buttons at the same time, specially in fighting games. Moreover, some games need to do charge command by pushing 3 buttons at the same time, if 2 players do that, there gone the six keys and they can not move while charging.
 
Hey Paul, would it be possible to have once teensy act like a defined number of HID gamepads? or even multiple keyboards? Another way of thinking about it is if you had 2 keyboards plugged into a usb hub, would they both get 6keys 8 modifiers each? I think you currently can be one of each, so a fall back would be one players game pad be a keyboard, and another's be a joystick.

This might be a good way to get around the input issue if it is possible.

Martin, an alternative would be doing what the iCade did: http://www.thinkgeek.com/files/iCADE/iCade_Dev_Resource_v1_3.pdf

they map a button down and button up to 2 keys. For example keypress 'y' triggers a button down state, and keypress 't' triggers the same button's up state. Some mobile versions of emulators already come mapped with this functionality. You might have to write middle man app to get this behavior recognized by the non moblie emulator.
 
Last edited:
Hey Paul, would it be possible to have once teensy act like a defined number of HID gamepads? or even multiple keyboards? Another way of thinking about it is if you had 2 keyboards plugged into a usb hub, would they both get 6keys 8 modifiers each? I think you currently can be one of each, so a fall back would be one players game pad be a keyboard, and another's be a joystick.

This might be a good way to get around the input issue if it is possible.

Yes, that is also possible. However, it also involves editing the USB code in pretty significant ways. If you're going to edit the USB code, you might as well just make a keyboard that sends more than 6 keys.

Well, unless you used 2 Teensy boards and a USB hub, where each Teensy runs the unmodified (6 key) Keyboard code. The 1st Teensy reading the keypad would send data (perhaps with Serial at a fast baud rate) to the other Teensy when its 6 keys are all in use.

For example keypress 'y' triggers a button down state, and keypress 't' triggers the same button's up state. Some mobile versions of emulators already come mapped with this functionality. You might have to write middle man app to get this behavior recognized by the non moblie emulator.

That's another way to do it, involving more software, but at least not the USB device level code.
 
I-PAC is the ONLY keyboard encoder which emulates a USB keyboard (and PS/2) and yet breaks through the USB simultaneously-pressed-switch limit of 6 switches (plus ctrl,alt,shift) which afflicts all USB keyboard devices. This is beacuse it has inbuilt full native USB support, and does not rely on an add-on adaptor.

This isn't quite true. There are other controllers on the market which bypass the key limit. GGG sells some also:
http://groovygamegear.com/webstore/index.php?main_page=index&cPath=76_81

The BYOAC forum has much more info on topics like this, if you haven't been there yet:
http://forum.arcadecontrols.com/

A MAME cab has been on my to-do list forever now...
 
The input issue is because of the way that USB keyboard protocol is defined. A really interesting summary can be read here: https://github.com/tmk/tmk_keyboard/blob/master/doc/USB_NKRO.txt

By default, the USB keyboard sends an 8-byte communication ("report") to the computer. The first byte contains a bitmap of the modifier keys (hence 8 modifier keys are possible). The second byte is typically either used as an id code or for some media keys or simply ignored, and the remaining 6 bytes are used to send the key code for any currently-pressed keys (one byte each). The keyboard needs to be on the first endpoint for use in BIOS. This is where the limit of "6 keys pressed" comes from for USB keyboards. When you release a key, the keyboard sends an update with the new list of pressed keys. If more than 6 keys are held, the keyboard is supposed to send a series of over-run bytes instead of the keys.

BIOS expects to receive USB keyboard reports in exactly this format. It doesn't normally load a full USB processing stack, so it can't ask the keyboard how it'll report pressed keys, and thus it has no way to identify/use any alternative report formats. Any keyboard that expects to be usable in the BIOS therefore needs to report it's keypresses in this format *when in boot mode*. Most USB keyboards therefore only ever use this mode of reporting - I suspect so that they have the maximum amount of compatibility with various computers with often buggy bios code.

Computer OS's however do usually load a full USB processing stack, and there are a few alternative USB keyboard report modes that are part of the normal USB HID protocol (and thus don't need any special/additional drivers on the computer's side) - a few extended byte reports (which Windows has some bugs with - see the summary link above) and the option of bitmap reports (each bit in the report represents one specific key). There's some projects using teensy 2/2++ chips that have implemented full N-Key reports using a bitmap report mode instead - TMK's keyboard adapter here and Soarer's adapter at GeekHack here. It's from their code/discussion (and then integrating it into what I needed) that I learned about how that stuff all worked - and I freely admit I learned only *just* enough about it to integrate it into my Teensy2++ gaming keypad (as an additional endpoint so that the original boot one was unchanged and wouldn't cause issues).

I would be keen to get some instructions on how to correctly update the USB endpoints for the Teensy3 to add the additional NKRO keyboard report for that, as I'm in the process of upgrading/migrating my gaming keypad (where I need more than 6-kro) from a Teensy2++ to a Teensy3. :)
 
Last edited:
Status
Not open for further replies.
Back
Top