Disabling Type-o-matic on PS/2

Thomas Henry

New Member
Hi all,

I've just concluded a fascinating five days of experimenting with the PS/2 keyboard-to-Picaxe 18x connection. The Keyin command is very cool and easy to use.

What isn't so easy is implementing the Caps Lock and/or shift keys to get shifted characters from the keyboard. I've managed the Caps Lock with some rather ghastly coding, but it does work. The shift key is quite a bit harder to get behavior consistent with how most keyboards behave.

The problem, of course, is the make/break business of how the keyboard and Keyin work.

This would be a piece of cake IF it weren't for that blasted type-o-matic (repeating keystrokes when a key is held down).

My question for the gurus, then, is: would there be a suitable POKE to a countdown register somewhere in the 18X to defeat the type-o-matic business?

Any opinions?

Thomas Henry
 

westaust55

Moderator
I do not think that it will be possible to detect/avoid the Typematic Repeat from a computer keyboard

The PICAXE keyin command (and the kbin for the X1 and X2 parts) only provides a single scan code for each key press.
The way the PC keyboards in fact work is that they send out an initial scan code which after an initial delay is repeated until the key is released. When the key is released a break scan code is issued. The key release/break scan code just adds another byte of data ($F0) to the information sent by the keyboard.
So for the letter A, the pressed/make scan code is $1C and this code is then repeated if the key is held down. When the key is released, two bytes are sent being $F0 and then $1C.
Likewise for the digit 0 key, the make scan code is $45 and then break code is $F0, $45.
Even the other keys work in a similar manner. The right “Ctrl” key has a make scan code of $E0, $14 and the corresponding breakcode is of $E0, $F0, $14

This scheme in fact allows for the data for a new key to be sent while another key remains pressed. In the case where more than one key is held down, only the last key pressed becomes typematic.

But the PICAXE keyboard entry commands removes some of the added bytes of data such as the $E) for some special keys) as mentioned in the PICAXE manual removes for the kbin and keyin commands.
Otherwise it would be simple to just look for the $F0 byte to see when a key was released before accepting that key again.

The PICAXE only allows sending of a few commands back to the keyboard to control the three LEDs.
If we had more control of the PS/2 interface then you could change the typematic rate and delay using the "Set Typematic Rate/Delay" ($F3) command. The next byte of data to the keyboard sets the repeat rate and the initial delay.

If we could send the byte value $FC we could disable the typematic repeat – BUT this apparently only works with Scan code set 3 whereas keyboards start up with scancode set 2.


The PS/2 protocol is too fast for the PICAXE BASIC to use whereas the raw PIC is fast enough so a PICAXE with the inbuilt commands is able to communicate with PS2 keyboards but not the BASIC programs we write.

For the actual keyboards, at power-on or software reset, the keyboard performs a diagnostic self-test referred to as BAT (Basic Assurance Test) and loads the following default values:
• Typematic delay 500 ms.
• Typematic rate 10.9 cps.
• Scan code set 2.
• Set all keys typematic/make/break.



I have recently done some research into the PS2 protocol with a view to connecting a touchpad.
One alternative option if you want more keyboard control would be to investigate a chip produced by AWCE.

Their PAK-VI chip can be used with serial comms to control and read either a PS2 keyboard or a PS/2 mouse including reading/writing raw codes to the PS/2 devices. http://www.awce.com/pak6.htm

I would buy a PAK-XI chip for my project, but at this moment the cost of the postage is a bit off-putting so considering what other options may let me achieve my goals.
 

Thomas Henry

New Member
Whoa! Am I red-faced!

I obviously had jumped to the conclusion that the typematic behavior was coming from the Picaxe. It never dawned on me that it was in fact being generated by the PS/2 keyboard itself. I wasn't aware that these keyboards were so intelligent.

Anyway, thanks to both of you guys for the feedback. The listed article was great reading---this was my first attempt at using such a keyboard and the article really filled in some gaps for me.

It seems, then, that the Keyin command is limited to fairly primitive keyboard activity. In particular, we can:

1. read each of the keys (which is still pretty good)
2. but can't distinguish between break and make
3. can't change typematic settings
4. and can't have very good control over multiple key activity (shifted characters, control, alt, etc.)
5. and can't use keys which generate multi-byte control sequences

Like I say, it's still pretty good being able to use a 100+ key keyboard, but wouldn't it be neat to use all of its features!

Thanks again for the input,

Thomas Henry
 
Top