What happen when you push two buttons of a PC keyboard?

Status
Not open for further replies.

mcoster

Member level 2
Joined
Jan 26, 2004
Messages
51
Helped
7
Reputation
14
Reaction score
1
Trophy points
1,288
Activity points
633
PC Keyboard question

Hi all,

I want to simulate a PC keyboard using a 8051 micro.
I have searched through a lot of texts but i couldn't find one that answered my question.

What does the keyboard controller sends to the PC when you press two keys at the same time ?

Does it send alternatly both key codes and break codes ? or what ?

Thank you very much

mcoster
:?:
 

Re: PC Keyboard question

Check this link:


from what's in this page, apparently the controller will send to the host (your PC) the scan code for each key alternatively, because no matter what you will have pressed one of the keys before the other, and as long as you are holding the keys their scan codes will keep being sent to the host.

When you release either of them an F0 will be sent to the host, and the scan code for the key still pressed will still keep being sent. It's up to you to check which key is still pressed to know the order of key release, when you release the other key another F0 will be sent.

Hope this helps
 

Re: PC Keyboard question

The PC keyboard uses make/break or up/down codes. Each key has a unique scan code. When any key is pressed, the controller sends its scan code as a make- or down-code, and when the key is released the controller sends 0xf0 followed the same scan code as a two-byte break- or up-code.
If the A key has code 0x1f and B has code 0x32, and A is pressed, B pressed, A released, B released, the following sequence is sent:
0x1f A pressed
0x32 B pressed
0xf0 A released
0x1f
0xf0 B released
0x32
Notice that this description only mentions time in relation to when keys are pressed and released. The codes are sent when the controller detects the press and when the controller detects the release of each key individually.
When you press/release two (or more) keys near-simultaneously, the controller sends the codes in whatever order it wants (if you want them in a certain order then don't press them simultaneously!) but in reality it will send them in the order it scans the keys. Autorepeat will only happen on the key pressed 'last', i.e. the last key-down code sent will be repeated after the initial delay and then after the repeat delay, until that key is released or another key is pressed.
The shift, control, alt, etc. keys are treated identically to all the other keys, so they also generate auto-repeat codes, but of course you don't see that as a user because the repeat doesn't affect anything you see. Just like the other keys, pressing shift/control/alt/etc. also stops any existing autorepeat (e.g. press and hold A so it repeats then press shift, the repeat stops).
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…