PS2 Commands

Frozen Content

The following sections detail common commands that can be sent from a host processor to a connected PS/2 keyboard or mouse, and vice-versa.

Commands Sent from a Host Processor

Table 1 and Table 2 list some of the common commands that can be sent from a host processor to a connected PS/2 keyboard or PS/2 mouse respectively. The commands are listed in terms of their hexadecimal codes. Note that all of the commands themselves are a single byte in length, but many of the commands require an additional byte of data to be sent by the host when determining specific options.

Table 1. Commands sent from host to PS/2 keyboard.
Code
Description and Keyboard Action

EDh

This command is used to turn the keyboard's LED indicators ON or OFF. The command tells the keyboard that the host CPU wishes to change the status of one or more of the LEDs. The keyboard sends an acknowledgement (response code FAh) and then waits for another byte of data from the host, that specifies the state settings for the LEDs as follows:

Bit0 – State of Scroll Lock LED
Bit1 – State of Num Lock LED
Bit2 – State of Caps Lock LED
Bit3-7 – Not Used

For each indicator, if the corresponding bit is 1, the LED is turned ON. If the bit is 0, the LED is turned OFF.

EEh

This is the echo command. Upon receipt, the keyboard transmits the echo response code (EEh).

F0h

This command is used to select the scan code set to be used for the keyboard. Every key on the keyboard has a scan code associated with it and it is this code that is sent to the host CPU when the key is pressed. The keyboard sends an acknowledgement (response code FAh) and then waits for another byte of data from the host, that specifies the particular scan code set to be used, as follows:

01h – select scan code set 1
02h – select scan code set 2
03h – select scan code set 3.

If the byte 00h is sent, the keyboard responds by sending the code for the current scan set that is in use.

F2h

This command is used to read the keyboard ID. Upon receipt, the keyboard responds with the acknowledge response code (FAh), followed by two bytes that constitute the keyboard's ID – ABh and 83h.

F3h

This command is used to set the auto-repeat rate. This is the rate at which the scan code for a depressed key is sent when that key has been held depressed for a length of time exceeding a specified delay. Upon receipt of the command, the keyboard issues the acknowledge response code (FAh) and then waits for another byte of data from the host, that specifies the auto-repeat rate and also the delay before auto-repeat comes into effect, as follows:

Bit0-4 – specifies the repeat rate (0000 = 30 times per second; 1111 = 2 times per second)
Bit5-6 – specifies the delay time (00 = 250ms; 11 = 1s)
Bit7 – Not Used.

Upon reception of this second byte from the host, the keyboard responds by sending the acknowledgement code again.

F4h

This command is used to enable the keyboard. Upon receipt of the command, the keyboard's output buffer is flushed and keyboard scanning (of the PSDATA and PSCLK lines) is enabled. The keyboard responds by sending the acknowledgement code (FAh).

F5h

This command is used to disable the keyboard. Upon receipt of the command, the keyboard is reset. The keyboard issues the acknowledgement code (FAh) and then keyboard scanning (of the PSDATA and PSCLK lines) is disabled. The keyboard remains in this state, waiting for another command from the host CPU.

FEh

This is the resend command and is used when the host requires the keyboard to retransmit the last byte of data sent. Upon receipt, the keyboard responds with the acknowledge response code (FAh), then proceeds to transmit the previously sent byte of data.

FFh

This command is used to reset the keyboard. Upon receipt, the keyboard responds with the acknowledge response code (FAh). The keyboard is reset and subsequently performs its power-on Basic Assurance Test (BAT). Depending on the result of the test, the keyboard will either send the 'Passed' code (AAh) or the 'Failed' code (FCh).


Table 2. Commands sent from host to PS/2 mouse.
Code
Description and Mouse Action

E6h

This command is used to set the current scaling from 2:1 to 1:1. After receipt of the command, the mouse replies with the acknowledge code (FAh) and changes the scaling to be 1:1.

E7h

This command is used to set the current scaling from 1:1 to 2:1. After receipt of the command, the mouse replies with the acknowledge code (FAh) and changes the scaling to be 2:1.

E8h

This command is used to set the resolution for the mouse. The mouse sends an acknowledgement (response code FAh) and then waits for another byte of data from the host, that specifies the resolution to be used, as follows:

00h – 1 count per millimeter
01h – 2 counts per millimeter
02h – 4 counts per millimeter
03h – 8 counts per millimeter

After receipt of this second byte, the mouse sends the acknowledge code again and resets its movement counters

E9h

This command is used to request the current status of the mouse. Upon receipt of the command, the mouse sends the acknowledge response code (FAh), followed by a three byte status packet, structured as follows:

Byte1
Bit0 – State of right mouse button (1=pressed; 0=not pressed)
Bit1 – State of middle mouse button (1=pressed; 0=not pressed)
Bit2 – State of left mouse button (1=pressed; 0=not pressed)
Bit3 – Not Used (set to 0)
Bit4 – Current scaling in use (1= 2:1; 0= 1:1)
Bit5 – Data reporting state (1=enabled; 0=disabled)
Bit6 – Current mode (1= Remote mode; 0= Stream mode)
Bit7 – Not Used (set to 0)
Byte2 – Current resolution in use
Byte3 – Current sampling rate in use

After sending the status packet, the mouse resets its movement counters.

EAh

This command is used to set the mouse in Stream mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering Stream mode. In this mode, a packet of data is sent every time the mouse detects movement, or when one of its buttons has changed state. Data is sent to the host, providing that data reporting is enabled. The frequency of packet transmission is determined by the sampling rate – the default being 100 samples per second.

EBh

This command is used to read sampled data from the mouse whilst it is in Remote mode. The mouse responds by sending the acknowledge response code (FAh) and then sending its current packet of movement data. The movement counters are subsequently reset.

ECh

This command is used to reset Wrap mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering the mode that it was in prior to entering Wrap mode (either Stream or Remote).

EEh

This command is used to set the mouse in Wrap mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering Wrap mode. In this mode, the mouse echoes all commands directly back to the host, without additional or further response. Two exceptions to this are the commands to reset (FFh) and reset Wrap mode (ECh). In these cases, the mouse responds as per the entries for these commands in this table.

F0h

This command is used to set the mouse in Remote mode. The mouse responds by sending the acknowledge code (FAh), resetting its movement counters and entering Remote mode. In this mode, the inputs to the mouse (movement and buttons) are still sampled, but no packets of data are sent to the host.

F2h

This command is used to read the mouse ID. Upon receipt, the mouse responds with the acknowledge response code (FAh), followed by the code that represents its ID and distinguishes it as a standard PS/2 mouse – 00h. The movement counters are also reset at this time.

F3h

This command is used to set the sampling rate for the mouse (when monitoring its movement and button inputs). The mouse sends an acknowledgement (response code FAh) and then waits for another byte of data from the host, that specifies the sampling rate to be used, as follows:

0Ah – 10 samples per second
14h – 20 samples per second
28h – 40 samples per second
3Ch – 60 samples per second
50h – 80 samples per second
64h – 100 samples per second
C8h – 200 samples per second.

After receipt of this second byte, the mouse sends the acknowledge code again and resets its movement counters.

F4h

This command is used to enable data reporting when the mouse is in Stream mode. Upon receipt of the command, the mouse sends the acknowledge response code (FAh) and resets its movement counters. It continues to sample its inputs (movement and buttons) and packets of data are once again sent to the host.

F5h

This command is used to disable data reporting when the mouse is in Stream mode. Upon receipt of the command, the mouse sends the acknowledge response code (FAh) and resets its movement counters. It continues to sample its inputs (movement and buttons) but no packets of data are sent to the host. Stream mode with data reporting disabled is analogous to the mouse being in Remote mode.

F6h

This command is used to load the mouse with default values. Upon receipt of the command, the mouse sends the acknowledge response code (FAh) and then loads the following:

  • Sampling Rate – 100 samples per second
  • Resolution – 4 counts per millimeter
  • Scaling – 1:1
  • Data Reporting – Disabled.

    These default values are also loaded when a reset command is received from the host, or when the mouse is powered-up (as part of its Basic Assurance Test).
    After loading the values, the mouse resets its movement counters and enters Stream mode.

FEh

This is the resend command and is used when the host requires the mouse to retransmit the last packet of data sent. Upon receipt of the command, the mouse sends the acknowledge response code (FAh), then proceeds to transmit the previously sent packet of data (e.g. movement data, status information, BAT code, ID, etc).

FFh

This command is used to reset the mouse. Upon receipt of the command, the mouse sends the acknowledge response code (FAh). The mouse is reset and subsequently performs its power-on Basic Assurance Test (BAT). During this test, default values are loaded for the sampling rate, resolution and scaling, and data reporting is disabled. Depending on the result of the test, the mouse will either send the 'Passed' code (AAh) or the 'Failed' code (FCh).

After the result of the power-on test is sent, the mouse sends its ID (00h). The mouse will then enter Stream mode. No movement data packets will be sent however, until the host first sends the command to enable data reporting.

Commands Sent from a PS/2 Device

Table 3 lists the common commands that can be sent from a PS/2 keyboard to a host processor. The commands are listed in terms of their hexadecimal codes. Note that all of the commands are a single byte in length, with the exception of the keyboard ID.

Table 3. Commands sent from a PS/2 keyboard.
Code
Description

00h

Error or output buffer overflow (scan code sets 2 and 3 only)

83ABh

Keyboard ID

AAh

Power-on Basic Assurance Test Passed

FCh

Power-on Basic Assurance Test Failed

EEh

Echo

FAh

Acknowledge.

FEh

Resend. Upon receipt of this code, the PS2 Controller will retransmit the previous byte

FFh

Error or output buffer overflow (scan code set 1 only)


Table 4 lists the common commands that can be sent from a PS/2 mouse to a host processor. The commands are listed in terms of their hexadecimal codes. Note that all of the commands are a single byte in length.

Table 4. Commands sent from a PS/2 mouse.
Code
Description

00h

Mouse ID

AAh

Power-on Basic Assurance Test Passed

FCh

Power-on Basic Assurance Test Failed

FAh

Acknowledge

FEh

Resend. Upon receipt of this code, the PS2 Controller will retransmit the previous byte.

You are reporting an issue with the following selected text and/or image within the active document: