![]() |
Forum Index : Microcontroller and PC projects : USB Keyboard - slow response/dropped keypresses
![]() ![]() |
|||||
Author | Message | ||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2530 |
I just tried this big kb to see problem but works fine, I just typeing to mmedit and mmcc. not used mouse yet. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10218 |
Amnesie I'm determined to get to the bottom of this. Please could you run the attached version which has some diagnostic code in it. Please load the software and then using a computer console type OPTION CONSOLE SERIAL This disables the screen as a console device Then using the USB keyboard type the sequence that gives the duplicated characters until you see a sequence which includes a duplicate In the computer console you will see the characters you typed. On the VGA screen you will see some hex codes which are the report sent by the keyboard. On my USB keyboard, I only ever see duplication of the "H" character and when it is duplicated I get the nonsense code A010101010101 on the screen and it is this which causes the duplication. Google does not suggest this is a generic error code but it is definitely the keyboard that is generating it. If your keyboards are doing the same or something similar I can then finally fix the problem. I've disabled the duplicated key timer as this is just masking the problem rather than fixing it. Thanks for your help Peter For reference these are the codes that the keys on a German keyboard should produce. When typing slowly you will see the code as the right most pair of hex digits. If you press two keys simultaneously you will see both codes in the 4 right digits. onst int DEkeyValue[202] = { 0,0,// USB_HID_KEYBOARD_KEYPAD_RESERVED_NO_EVENT_INDICATED = 0x00, 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_ERROR_ROLL_OVER = 0x01, 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_POST_FAIL = 0x02, 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_ERROR_UNDEFINED = 0x03, 97,65,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_A = 0x04, 98,66,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_B = 0x05, 99,67,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_C = 0x06, 100,68,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_D = 0x07, 101,69,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_E = 0x08, 102,70,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F = 0x09, 103,71,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_G = 0x0A, 104,72,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_H = 0x0B, 105,73,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_I = 0x0C, 106,74,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_J = 0x0D, 107,75,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_K = 0x0E, 108,76,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_L = 0x0F, 109,77,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_M = 0x10, 110,78,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_N = 0x11, 111,79,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_O = 0x12, 112,80,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_P = 0x13, 113,81,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_Q = 0x14, 114,82,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_R = 0x15, 115,83,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_S = 0x16, 116,84,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_T = 0x17, 117,85,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_U = 0x18, 118,86,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_V = 0x19, 119,87,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_W = 0x1A, 120,88,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_X = 0x1B, 122,90,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_Y = 0x1C, 121,89,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_Z = 0x1D, 49,33,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_1_AND_EXCLAMATION_POINT = 0x1E, 50,34,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_2_AND_AT = 0x1F, 51,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_3_AND_HASH = 0x20, DE: §=245 52,36,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_4_AND_DOLLAR = 0x21, 53,37,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_5_AND_PERCENT = 0x22, 54,38,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_6_AND_CARROT = 0x23, 55,47,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_7_AND_AMPERSAND = 0x24, 56,40,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_8_AND_ASTERISK = 0x25, 57,41,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_9_AND_OPEN_PARENTHESIS = 0x26, 48,61,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_0_AND_CLOSE_PARENTHESIS = 0x27, 10,10,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_RETURN_ENTER = 0x28, 27,27,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_ESCAPE = 0x29, 8,8,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_DELETE = 0x2A, 9,0x9f,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_TAB = 0x2B, 32,32,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_SPACEBAR = 0x2C, 0,63,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_MINUS_AND_UNDERSCORE = 0x2D, DE: ß=225 0,96,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_EQUAL_AND_PLUS = 0x2E, DE: ´=239 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_OPEN_BRACKET_AND_OPEN_CURLY_BRACE = 0x2F, DE: ü=129,Ü=154 43,42,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_CLOSE_BRACKET_AND_CLOSE_CURLY_BRACE = 0x30, 35,39,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_BACK_SLASH_AND_PIPE = 0x31, 35,39,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_NON_US_HASH_AND_TILDE = 0x32, 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_SEMICOLON_AND_COLON = 0x33, DE: ö=228,Ö=229 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_APOSTROPHE_AND_QUOTE = 0x34, DE: ä=132,Ä=142 94,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_GRAVE_ACCENT_AND_TILDE = 0x35, DE: °=167 44,59,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_COMMA_AND_LESS_THAN = 0x36, 46,58,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_PERIOD_AND_GREATER_THAN = 0x37, 45,95,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_FORWARD_SLASH_AND_QUESTION_MARK = 0x38, 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_CAPS_LOCK = 0x39, 0x91,0xB1,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F1 = 0x3A, 0x92,0xB2,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F2 = 0x3B, 0x93,0xB3,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F3 = 0x3C, 0x94,0xB4,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F4 = 0x3D, 0x95,0xB5,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F5 = 0x3E, 0x96,0xB6,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F6 = 0x3F, 0x97,0xB7,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F7 = 0x40, 0x98,0xB8,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F8 = 0x41, 0x99,0xB9,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F9 = 0x42, 0x9a,0xBa,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F10 = 0x43, 0x9b,0xBb,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F11 = 0x44, 0x9c,0xBc,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_F12 = 0x45, 0x9d,0xBd,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_PRINT_SCREEN = 0x46, 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_SCROLL_LOCK = 0x47, 0x9e,0x9e,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_PAUSE = 0x48, 0x84,0x84,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_INSERT = 0x49, 0x86,0x86,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_HOME = 0x4A, 0x88,0x88,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_PAGE_UP = 0x4B, 0x7f,0xa0,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_DELETE_FORWARD = 0x4C, 0x87,0x87,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_END = 0x4D, 0x89,0x89,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_PAGE_DOWN = 0x4E, 0x83,0xA3,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_RIGHT_ARROW = 0x4F, 0x82,0x82,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_LEFT_ARROW = 0x50, 0x81,0xA1,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_DOWN_ARROW = 0x51, 0x80,0x80,// USB_HID_KEYBOARD_KEYPAD_KEYBOARD_UP_ARROW = 0x52, 0,0,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_NUM_LOCK_AND_CLEAR = 0x53, 47,47,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_BACK_SLASH = 0x54, 42,42,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_ASTERISK = 0x55, 45,45,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_MINUS = 0x56, 43,43,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_PLUS = 0x57, 10,10,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_ENTER = 0x58, 49,0x87,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_1_AND_END = 0x59, 50,0x81,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_2_AND_DOWN_ARROW = 0x5A, 51,0x89,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_3_AND_PAGE_DOWN = 0x5B, 52,0x82,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_4_AND_LEFT_ARROW = 0x5C, 53,53,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_5 = 0x5D, 54,0x83,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_6_AND_RIGHT_ARROW = 0x5E, 55,0x86,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_7_AND_HOME = 0x5F, 56,0x80,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_8_AND_UP_ARROW = 0x60, 57,0x88,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_9_AND_PAGE_UP = 0x61, 48,0x84,// USB_HID_KEYBOARD_KEYPAD_KEYPAD_0_AND_INSERT = 0x62, 46,0x7f, //USB_HID_KEYBOARD_KEYPAD_KEYPAD_PERIOD_AND_DELETE = 0x63, 60,62 //USB_HID_KEYBOARD_KEYPAD_KEYBOARD_NON_US_FORWARD_SLASH_AND_PIPE = 0x64, }; |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 611 |
Hi Peter, of course I'll do my best to help! But there is no attached file. Do you forgot to attach it? Greetings Daniel Edited 2025-07-06 20:20 by Amnesie |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10218 |
Oops PicoMite.zip |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 611 |
I have no idea why, but I wasn't able to get serial console to work. If I type: "option console serial" it only works so long if I'm not hitting the ENTER key. Also right now it seems, that I am to stupid to get my FTDI connector to work (console output on GP8 & GP9) ... maybe this is just me, or is this somehow disable in this version of the firmware? It should be on by default with the USB version. Naaah whaterever, I have a sucess in replicating your "A010101010101" anyways. I know that this gives me dublicates with the "F" SDFG So I pressed those keys and see for yourself (last block of "code"): ![]() So maybe this is enough for you to verify. You said you have dublicate "h" and this code: A010101010101 I have dublicate "f" and get also the same code! Edited 2025-07-06 21:20 by Amnesie |
||||
pointy56 Newbie ![]() Joined: 31/05/2025 Location: United KingdomPosts: 1 |
I've been following this thread with interest. I think that the spurious A010101010101 is reporting USB_HID_KEYBOARD_KEYPAD_KEYBOARD_ERROR_ROLL_OVER as shown in the earlier table from Peter, although why it is repeated in all 6 key positions is beyond me. Other than that the key codes being sent seem reasonable for what Daniel is doing. Martin Edited 2025-07-06 21:35 by pointy56 |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 611 |
Hello Martin, This is a really complex problem, especially since apparently not everyone is affected. Peter was right from the start about the keyboard-related issue. It seems to be a complicated combination of the following: - individual keyboard matrix scanning - polling time as far as I udnerstand it. But if Peter has success in pinning this problem down to its root, I think he can tell us what the real problem was ![]() Greetings Daniel Edited 2025-07-06 21:51 by Amnesie |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10218 |
Please try the attached - I'm hopeful this time ![]() Interestingly my Corsair keyboard NEVER gives this code and never duplicates characters PicoMite.zip Edited 2025-07-06 21:58 by matherp |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 611 |
Peter, I tested three keyboards, none of the gives dublicates anymore! BUT: all keyboards have problems with "4567" there is often a twist: 4576 4567 only one keyboard has problem with: "VBNM" there is a twist also: vbnm vbmn even if I type a little bit slower (but have a rollover) for better understanding I shoot a video of this situation again: Video I feel we are almost there. No dublicates at least! :) |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2431 |
Peter, if a diode was placed in series with every switch in the keyboard matrix, then it would be possible to scan and unambiguously read back the up/down state of every switch irrespective of how many were down at once. this is how keyboards were implemented back in olden times, though the driver electronics back then usually lacked the complexity to handle too many keys down at once. but the practice of 'one diode per key' is incompatible with cheap modern keyboards employing tracks and pads placed on two facing flexible plastic sheets held apart with a thin separator - there is now no sensible place to fit all the individual diodes. it is quite possible that your Corsair keyboard is implemented as individual mechanical switches, each soldered onto a single backing PCB where a diode is located for each of the switches; no doubt expensive modern keyboards still do this today and thus can in theory handled 'unlimited rollover'. cheers, rob :-) Edited 2025-07-06 23:04 by robert.rozee |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10218 |
Can you replicate this on the version with the diagnostics? If so please report the sequence when it happens. I can't see a way for this to happen unless the keyboard itself is reporting in the wrong order depending on how it scans. I certainly can't replicate this with any keyboard I possess |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7843 |
Rob: On USB keyboards n-key rollover is implemented in the HID software as USB serial protocol simply can't do it by itself (six keys maximum). It requires the keyboard to be switched into n-key mode, which not all have. Good keyboards will automatically enable n-key but even the keyboards that have it might turn it off for compatibility reasons even though this isn't part of the spec! The minimum spec is 2-key rollover for a standard keyboard, I believe. Don't you just love standards? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Bleep Guru ![]() Joined: 09/01/2022 Location: United KingdomPosts: 625 |
Hi Peter, Have you tried with your Raspberry Pi keyboard, I have one, and have noticed problems went using muscle memory to type 'option list' quickly, I think it was on a LCD Picomite, keyboard connected directly, no hub, might give you a keyboard which exhibits problems. Unfortunately I'm away so haven't got access to my usual toys, so can't participate. Regards Kevin. |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 611 |
Hi Peter, I am not sure how helpful this is, since my FTDA converter doesn't work with this diagnostic firmware (or I am just too stupid - also possible ![]() But here are two things to keep in mind: 1. this firmware is before the dublicate fix 2. I am not quite sure how to interpret the codes.. some have the real typed letter, some not, but I think I found one sequence which have the twisted chars: ![]() EDIT: maybe it is important: the "mn" (as in orange in the picture) is always in one line like this, so this is reproducible. Also worth to mention: only one keyboard has this spot, other keyboards have others. -Daniel Edited 2025-07-07 03:31 by Amnesie |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10218 |
Thanks - looks like the swap occurs when the report after the error contains two new characters - that gives me something to look at. It will be tomorrow before I post more. Edited 2025-07-07 03:32 by matherp |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 611 |
Good to know, I hoped that you find something useful in it! Of course I will test as long as you want to. But since there are no missing keys anymore, this is such a huge improvement! Dublicates are also fixed... Only those twisted pairs are left :) Take all the time you need. Greetings Daniel |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2431 |
hi Mixtel90, you might have missed the point i was making: without series diodes for every key switch in the matrix, it is pretty much impossible to implement anything more than 2-key rollover that will work with every possible combination of keys. consider a 2x2 keyboard matrix without diodes. with any 3 keys simultaneously pressed, it is impossible to determine which key is not pressed. but if diodes are introduced, you can determine the unpressed key. as you scale up the size of your keyboard there will be some multiple key-down combinations that can be uniquely determined, but others that can not. however, add in the series diodes and the problem disappears. but having a diode in series with every key switch is incompatible with the mechanical construction used in most modern (ie, cheap membrane) keyboards. instead, keyboard manufacturers try to arrange keys within the matrix in such a way that 'common rollover groups' are physically broken apart and spread far apart. Peter: i wonder if the 010101... code you are seeing represents an "i am confused" flag, telling the other end that it should reset and assume that every key has been released? cheers, rob :-) Edited 2025-07-07 11:20 by robert.rozee |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7843 |
Oh yes, I've come across the diode thing before. My point was about the HID spec. The most common rollovers used start at 2 as a minimum, then 6. No more than 6 during boot time usually, and an interrupt is generated on every key change at that time. It's part of the BIOS system, many older systems can't handle more than 6 even if the keyboard can generate n-key. Many true n-key keyboards do include diodes, but no others do. As you say, they aren't simple X-Y matrices and often things like WASD are optimised. That may be part of the problem that we are seeing here, different optimisations have been made on different keyboards. The same test may pass on one and fail on another. PS2 is always n-key capable if the keyboard can generate it. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10218 |
Here is a new update - tests OK for me but.... PicoMiteRP2040VGAUSBV6.00.02.zip If this doesn't solver the ordering issue note Edited 2025-07-08 00:07 by matherp |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 611 |
Hi Peter, I tested all my keyboards and now there is a new problem, see please the image (I changed the keyboard one time, to see if it is still there in the photo, after that I tested all other keyboards) ![]() Greetings Daniel |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |