Next Previous Contents

11. Keyboard commands

One can not only talk to the keyboard controller (by writing to port 0x64), but also to the keyboard (by writing to port 0x60).

In order to avoid interference between scancode sequences or mouse packets and the reponses given to commands, the keyboard or mouse should always be disabled before giving a command that requires a response, and probably enabled afterwards. Some keyboards or mice do the disable automatically in this situation, but still require an explicit enable afterwards.

Each command (other than 0xfe) is ACKed by 0xfa. Each unknown command is NACKed by 0xfe. Some mice expect a corrected byte as reply to the 0xfe, and will double-NACK with 0xfc when also that is wrong.

Here a list with the common commands.

0xed Write LEDs
0xee Diagnostic echo
0xf0 Set/Get scancode set
0xf2 Read keyboard ID
0xf3 Set repeat rate and delay
0xf4 Keyboard enable
0xf5 Set defaults and disable keyboard
0xf6 Set defaults
0xf7 Set all keys to repeat
0xf8 Set all keys to give make/break codes
0xf9 Set all keys to give make codes only
0xfa Set all keys to repeat and give make/break codes
0xfb Set a single key to repeat
0xfc Set a single key to give make/break codes
0xfd Set a single key to give make codes only
0xfe Resend
0xff Keyboard reset

If the command is preceded by writing 0xd4 to port 0x64, then it goes to the mouse instead of the keyboard. Common commands:

0xe6 Set mouse scaling to 1:1
0xe7 Set mouse scaling to 2:1
0xe8 Set mouse resolution
0xe9 Get mouse information
0xf2 Read mouse ID
0xf3 Set mouse sample rate
0xf4 Mouse enable
0xf5 Mouse disable
0xf6 Set defaults
0xff Mouse reset

11.1 Keyboard command details

Command e8: Nonstandard. Reported to give a 2-byte ID on an OmniKey keyboard.

Command ea: Nonstandard. The sequences ea 70 and ea 71 are used by some IBM keyboards to disable and enable extra keys.

Command eb: Nonstandard. Sequences involving eb are often used for manipulating extra LEDs.

Command ec: Nonstandard. On the IBM Rapid Access keyboard this command yields a 2-byte ID.

Command ed: Write LEDs

This command is followed by a byte indicating the desired LEDs setting. Bits 7-3: unused, 0. Bit 2: 1: CapsLock LED on. Bit 1: 1: NumLock LED on. Bit 0: 1: ScrollLock LED on. When OK, both bytes are ACKed. If the second byte is recognized as a command, that command is ACKed and done instead. Otherwise a NACK is returned (and a keyboard enable may be needed).

Command ee: Diagnostic echo

This command returns a single byte, again ee.

Command f0: Set/Get scancode set

Many, but not all, keyboards can be switched to three different scancode sets. This command, followed by a byte 01, 02, or 03 selects the corresponding scancode set. This command, followed by a zero byte, reads the current scancode set. The reply (translated) is 43, 41 or 3f, from untranslated 1, 2 or 3. Note that scancode set 1 should not be translated, while sets 2 and 3 should be translated.

Set 2 was introduced by the AT. Set 3 by the PS/2.

Command f2: Read keyboard ID

This command reads a 2-byte keyboard ID. XT keyboards do not answer at all (of course), AT keyboards reply with an ACK (fa) only, MF2 and other keyboards reply with a 2-byte ID. Wait at least 10ms after issuing this command.

For the mouse reply, see below.

Command f3: Set repeat rate and delay

A following byte gives the desired delay before a pressed key starts repeating, and the repeat rate.

Bit 7: unused, 0.

Bits 6-5: 0, 1, 2, 3: 250, 500, 750, 1000 ms delay. Default after reset is 500 ms.

Bits 4-0: inter-character delay. The number of characters per second is given by

0 1 2 3 4 5 6 7
0 30.0 26.7 24.0 21.8 20.0 18.5 17.1 16.0
8 15.0 13.3 12.0 10.9 10.0 9.2 8.6 8.0
16 7.5 6.7 6.0 5.5 5.0 4.6 4.3 4.0
24 3.7 3.3 3.0 2.7 2.5 2.3 2.1 2.0

(that is, the inter-character delay is (2 ^ B) * (D + 8) / 240 sec, where B gives Bits 4-3 and D gives Bits 2-0).

Default after reset is 10.9 characters per second.

Logitech extended commands Logitech uses escape sequences involving f3 for extended commands. A Logitech extended command looks like f3 7f f3 00 f3 xx (for varying 7-bit values of xx). For example:

xx = 01: SendStatus: send the E1 XX codes for SubDeviceType, BatteryStatus, (Channel if relevant) KbdStatus (=wireless status).

xx = 02: OpenLocking

xx = 03: CloseLocking

xx = 06 f3 aa: Read byte at address aa (in 0x01-0x1e).

xx = 07 F3 aa f3 dd: Write dd at address aa (in 0x01-0x1e).

xx = 10 or 11: Clear all device-related data in EEPROM and RAM. Now device is disconnected.

Command f4: Keyboard enable

If a transmit error occurs, the keyboard is automatically disabled. This command re-enables the keyboard and clears its internal 16-byte buffer.

Command f5: Set defaults and disable keyboard

Reset keyboard, clear output buffer, switch off LEDs, reset repeat rate and delay to defaults. Disable the keyboard scan.

Command f6: Set defaults

Reset keyboard, clear output buffer, switch off LEDs, reset repeat rate and delay to defaults.

Command f7: Set all keys to repeat

Keyboards that support scancode Set 3 keep for each key two bits: does it repeat? does it generate a break code? This command sets the "repeat" bit for all keys. It does not influence keyboard operation when the scancode set is not Set 3.

Command f8: Set all keys to give make/break codes

This command sets the "generate break code" bit for all keys. It does not influence keyboard operation when the scancode set is not Set 3.

Command f9: Set all keys to give make codes only

This command clears the "generate break code" bit for all keys. It does not influence keyboard operation when the scancode set is not Set 3.

Command fa: Set all keys to repeat and give make/break codes

This command sets the "repeat" and "generate break code" bits for all keys. It does not influence keyboard operation when the scancode set is not Set 3.

Command fb: Set some keys to repeat

This command sets the "repeat" bits for the indicated keys. It is followed by the untranslated Set 3 scancodes of the keys for which this bit must be set. The sequence is ended by a command code (ed, ee, f0, f2-ff). Afterwards, a "keyboard enable" f4 is required.

Command fc: Set some keys to give make/break codes

This command sets the "generate break code" bits for the indicated keys. It is followed by the untranslated Set 3 scancodes of the keys for which this bit must be set. The sequence is ended by a command code (ed, ee, f0, f2-ff). Afterwards, a "keyboard enable" f4 is required.

Command fd: Set some keys to give make codes only

This command clears the "generate break code" bits for the indicated keys. It is followed by the untranslated Set 3 scancodes of the keys for which this bit must be set. The sequence is ended by a recognized command code (such as ed, ee, f0, f2-ff). Afterwards, a "keyboard enable" f4 is required.

Command fe: Resend

Meant for use by the keyboard controller after a transmission error. Not for use by the CPU.

Command ff: Keyboard reset

Reset and self-test. The self-test (BAT) will return aa when OK, and fc otherwise. As part of the self-test, all LEDs are flashed.


Next Previous Contents


Imprint / Data Protection