1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
4 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
5 <TITLE>Keyboard scancodes: Keyboard commands</TITLE>
6 <LINK HREF="scancodes-12.html" REL=next>
7 <LINK HREF="scancodes-10.html" REL=previous>
8 <LINK HREF="scancodes.html#toc11" REL=contents>
11 <A HREF="scancodes-12.html">Next</A>
12 <A HREF="scancodes-10.html">Previous</A>
13 <A HREF="scancodes.html#toc11">Contents</A>
15 <H2><A NAME="s11">11. Keyboard commands</A></H2>
17 <P>One can not only talk to the keyboard controller (by writing to
18 port 0x64), but also to the keyboard (by writing to port 0x60).
19 <P>In order to avoid interference between scancode sequences or
20 mouse packets and the reponses given to commands, the keyboard
21 or mouse should always be disabled before giving a command that
22 requires a response, and probably enabled afterwards.
23 Some keyboards or mice do the disable automatically in this
24 situation, but still require an explicit enable afterwards.
25 <P>Each command (other than 0xfe) is ACKed by 0xfa.
26 Each unknown command is NACKed by 0xfe.
27 Some mice expect a corrected byte as reply to the 0xfe,
28 and will double-NACK with 0xfc when also that is wrong.
29 <P>Here a list with the common commands.
32 <CENTER><TABLE BORDER><TR><TD>
33 <A HREF="#kced">0xed</A> </TD><TD> Write LEDs </TD></TR><TR><TD>
34 <A HREF="#kcee">0xee</A> </TD><TD> Diagnostic echo </TD></TR><TR><TD>
35 <A HREF="#kcf0">0xf0</A> </TD><TD> Set/Get scancode set </TD></TR><TR><TD>
36 <A HREF="#kcf2">0xf2</A> </TD><TD> Read keyboard ID </TD></TR><TR><TD>
37 <A HREF="#kcf3">0xf3</A> </TD><TD> Set repeat rate and delay </TD></TR><TR><TD>
38 <A HREF="#kcf4">0xf4</A> </TD><TD> Keyboard enable </TD></TR><TR><TD>
39 <A HREF="#kcf5">0xf5</A> </TD><TD> Set defaults and disable keyboard </TD></TR><TR><TD>
40 <A HREF="#kcf6">0xf6</A> </TD><TD> Set defaults </TD></TR><TR><TD>
41 <A HREF="#kcf7">0xf7</A> </TD><TD> Set all keys to repeat </TD></TR><TR><TD>
42 <A HREF="#kcf8">0xf8</A> </TD><TD> Set all keys to give make/break codes </TD></TR><TR><TD>
43 <A HREF="#kcf9">0xf9</A> </TD><TD> Set all keys to give make codes only </TD></TR><TR><TD>
44 <A HREF="#kcfa">0xfa</A> </TD><TD> Set all keys to repeat and give make/break codes </TD></TR><TR><TD>
45 <A HREF="#kcfb">0xfb</A> </TD><TD> Set a single key to repeat </TD></TR><TR><TD>
46 <A HREF="#kcfc">0xfc</A> </TD><TD> Set a single key to give make/break codes </TD></TR><TR><TD>
47 <A HREF="#kcfd">0xfd</A> </TD><TD> Set a single key to give make codes only </TD></TR><TR><TD>
48 <A HREF="#kcfe">0xfe</A> </TD><TD> Resend </TD></TR><TR><TD>
49 <A HREF="#kcff">0xff</A> </TD><TD> Keyboard reset </TD></TR><TR><TD>
51 </TD></TR></TABLE></CENTER>
52 <P>If the command is preceded by writing 0xd4 to port 0x64, then
53 it goes to the mouse instead of the keyboard. Common commands:
56 <CENTER><TABLE BORDER><TR><TD>
57 <A HREF="scancodes-12.html#mce6">0xe6</A> </TD><TD> Set mouse scaling to 1:1 </TD></TR><TR><TD>
58 <A HREF="scancodes-12.html#mce7">0xe7</A> </TD><TD> Set mouse scaling to 2:1 </TD></TR><TR><TD>
59 <A HREF="scancodes-12.html#mce8">0xe8</A> </TD><TD> Set mouse resolution </TD></TR><TR><TD>
60 <A HREF="scancodes-12.html#mce9">0xe9</A> </TD><TD> Get mouse information </TD></TR><TR><TD>
61 <A HREF="scancodes-12.html#mcf2">0xf2</A> </TD><TD> Read mouse ID </TD></TR><TR><TD>
62 <A HREF="scancodes-12.html#mcf3">0xf3</A> </TD><TD> Set mouse sample rate </TD></TR><TR><TD>
63 <A HREF="scancodes-12.html#mcf4">0xf4</A> </TD><TD> Mouse enable </TD></TR><TR><TD>
64 <A HREF="scancodes-12.html#mcf5">0xf5</A> </TD><TD> Mouse disable </TD></TR><TR><TD>
65 <A HREF="scancodes-12.html#mcf6">0xf6</A> </TD><TD> Set defaults </TD></TR><TR><TD>
66 <A HREF="scancodes-12.html#mcff">0xff</A> </TD><TD> Mouse reset </TD></TR><TR><TD>
68 </TD></TR></TABLE></CENTER>
70 <H2><A NAME="ss11.1">11.1 Keyboard command details</A>
74 <P><I>Command <B>e8</B></I>: Nonstandard. Reported to give a
76 <A HREF="scancodes-5.html#omnikey">OmniKey</A> keyboard.
77 <P><I>Command <B>ea</B></I>: Nonstandard. The sequences
78 <B>ea</B> <B>70</B> and <B>ea</B> <B>71</B> are
79 used by some IBM keyboards to disable and enable extra keys.
80 <P><I>Command <B>eb</B></I>: Nonstandard. Sequences involving <B>eb</B>
82 <A HREF="scancodes-1.html#LEDmanip">manipulating extra LEDs</A>.
83 <P><I>Command <B>ec</B></I>: Nonstandard. On the
84 <A HREF="scancodes-5.html#ibmrapidaccess">IBM Rapid Access keyboard</A>
85 this command yields a 2-byte ID.
86 <P><I>Command <B>ed</B>:
87 <A NAME="kced"></A> Write LEDs</I>
90 This command is followed by a byte indicating the desired LEDs setting.
92 Bit 2: 1: CapsLock LED on.
93 Bit 1: 1: NumLock LED on.
94 Bit 0: 1: ScrollLock LED on.
95 When OK, both bytes are ACKed. If the second byte is recognized as a
96 command, that command is ACKed and done instead. Otherwise a NACK is
97 returned (and a keyboard enable may be needed).
99 <P><I>Command <B>ee</B>:
100 <A NAME="kcee"></A> Diagnostic echo</I>
103 This command returns a single byte, again <B>ee</B>.
105 <P><I>Command <B>f0</B>:
106 <A NAME="kcf0"></A> Set/Get scancode set</I>
109 Many, but not all, keyboards can be switched to three different
110 <A HREF="scancodes-9.html#scancodesets">scancode sets</A>.
111 This command, followed by a byte <B>01</B>, <B>02</B>, or <B>03</B>
112 selects the corresponding scancode set. This command, followed by
113 a zero byte, reads the current scancode set. The reply (translated)
114 is <B>43</B>, <B>41</B> or <B>3f</B>, from untranslated 1, 2 or 3.
115 Note that scancode set 1 should not be translated, while sets
116 2 and 3 should be translated.
117 <P>Set 2 was introduced by the AT. Set 3 by the PS/2.
119 <P><I>Command <B>f2</B>:
120 <A NAME="kcf2"></A> Read keyboard ID</I>
123 This command reads a 2-byte
124 <A HREF="scancodes-9.html#keyboardid">keyboard ID</A>.
125 XT keyboards do not answer at all (of course),
126 AT keyboards reply with an ACK (<B>fa</B>) only,
127 MF2 and other keyboards reply with a 2-byte ID.
128 Wait at least 10ms after issuing this command.
129 <P>For the mouse reply, see
130 <A HREF="scancodes-12.html#mcf2">below</A>.
132 <P><I>Command <B>f3</B>:
133 <A NAME="kcf3"></A> Set repeat rate and delay</I>
136 A following byte gives the desired delay before a pressed key
137 starts repeating, and the repeat rate.
139 <P>Bits 6-5: 0, 1, 2, 3: 250, 500, 750, 1000 ms delay.
140 Default after reset is 500 ms.
141 <P>Bits 4-0: inter-character delay. The number of characters per second
144 <CENTER><TABLE BORDER><TR><TD>
145 </TD><TD> 0 </TD><TD> 1 </TD><TD> 2 </TD><TD> 3 </TD><TD> 4 </TD><TD> 5 </TD><TD> 6 </TD><TD> 7 </TD></TR><TR><TD>
146 0 </TD><TD> 30.0 </TD><TD> 26.7 </TD><TD> 24.0 </TD><TD> 21.8 </TD><TD> 20.0 </TD><TD> 18.5 </TD><TD> 17.1 </TD><TD> 16.0 </TD></TR><TR><TD>
147 8 </TD><TD> 15.0 </TD><TD> 13.3 </TD><TD> 12.0 </TD><TD> 10.9 </TD><TD> 10.0 </TD><TD> 9.2 </TD><TD> 8.6 </TD><TD> 8.0 </TD></TR><TR><TD>
148 16</TD><TD> 7.5 </TD><TD> 6.7 </TD><TD> 6.0 </TD><TD> 5.5 </TD><TD> 5.0 </TD><TD> 4.6 </TD><TD> 4.3 </TD><TD> 4.0 </TD></TR><TR><TD>
149 24</TD><TD> 3.7 </TD><TD> 3.3 </TD><TD> 3.0 </TD><TD> 2.7 </TD><TD> 2.5 </TD><TD> 2.3 </TD><TD> 2.1 </TD><TD> 2.0 </TD></TR><TR><TD>
151 </TD></TR></TABLE></CENTER>
152 <P>(that is, the inter-character delay is (2 ^ B) * (D + 8) / 240 sec,
153 where B gives Bits 4-3 and D gives Bits 2-0).
154 <P>Default after reset is 10.9 characters per second.
155 <P><B>Logitech extended commands</B>
156 Logitech uses escape sequences involving <B>f3</B> for extended commands.
157 A Logitech extended command looks like
158 <B>f3</B> <B>7f</B> <B>f3</B> <B>00</B> <B>f3</B> <I>xx</I>
159 (for varying 7-bit values of <I>xx</I>). For example:
160 <P><I>xx</I> = <B>01</B>: SendStatus: send the E1 XX codes for SubDeviceType,
161 BatteryStatus, (Channel if relevant) KbdStatus (=wireless status).
162 <P><I>xx</I> = <B>02</B>: OpenLocking
163 <P><I>xx</I> = <B>03</B>: CloseLocking
164 <P><I>xx</I> = <B>06</B> <B>f3</B> <I>aa</I>:
165 Read byte at address <I>aa</I> (in 0x01-0x1e).
166 <P><I>xx</I> = <B>07</B> <B>F3</B> <I>aa</I> <B>f3</B> <I>dd</I>:
167 Write <I>dd</I> at address <I>aa</I> (in 0x01-0x1e).
168 <P><I>xx</I> = <B>10</B> or <B>11</B>: Clear all device-related data
169 in EEPROM and RAM. Now device is disconnected.
171 <P><I>Command <B>f4</B>:
172 <A NAME="kcf4"></A> Keyboard enable</I>
175 If a transmit error occurs, the keyboard is automatically disabled.
176 This command re-enables the keyboard and clears its internal 16-byte
179 <P><I>Command <B>f5</B>:
180 <A NAME="kcf5"></A> Set defaults and
184 Reset keyboard, clear output buffer, switch off LEDs, reset
185 repeat rate and delay to defaults. Disable the keyboard scan.
187 <P><I>Command <B>f6</B>:
188 <A NAME="kcf6"></A> Set defaults</I>
191 Reset keyboard, clear output buffer, switch off LEDs, reset
192 repeat rate and delay to defaults.
194 <P><I>Command <B>f7</B>:
195 <A NAME="kcf7"></A> Set all keys to repeat</I>
198 Keyboards that support scancode Set 3 keep for each key two bits:
199 does it repeat? does it generate a break code?
200 This command sets the "repeat" bit for all keys.
201 It does not influence keyboard operation when the scancode set is not Set 3.
203 <P><I>Command <B>f8</B>:
204 <A NAME="kcf8"></A> Set all keys to give make/break
208 This command sets the "generate break code" bit for all keys.
209 It does not influence keyboard operation when the scancode set is not Set 3.
211 <P><I>Command <B>f9</B>:
212 <A NAME="kcf9"></A> Set all keys to give
216 This command clears the "generate break code" bit for all keys.
217 It does not influence keyboard operation when the scancode set is not Set 3.
219 <P><I>Command <B>fa</B>:
220 <A NAME="kcfa"></A> Set all keys to repeat
221 and give make/break codes</I>
224 This command sets the "repeat" and "generate break code" bits for all keys.
225 It does not influence keyboard operation when the scancode set is not Set 3.
227 <P><I>Command <B>fb</B>:
228 <A NAME="kcfb"></A> Set some keys to repeat</I>
231 This command sets the "repeat" bits for the indicated keys.
232 It is followed by the untranslated Set 3 scancodes of the keys
233 for which this bit must be set. The sequence is ended by a command
234 code (<B>ed</B>, <B>ee</B>, <B>f0</B>, <B>f2</B>-<B>ff</B>).
235 Afterwards, a "keyboard enable" <B>f4</B> is required.
237 <P><I>Command <B>fc</B>:
238 <A NAME="kcfc"></A> Set some keys to give make/break
242 This command sets the "generate break code" bits for the indicated keys.
243 It is followed by the untranslated Set 3 scancodes of the keys
244 for which this bit must be set. The sequence is ended by a command
245 code (<B>ed</B>, <B>ee</B>, <B>f0</B>, <B>f2</B>-<B>ff</B>).
246 Afterwards, a "keyboard enable" <B>f4</B> is required.
248 <P><I>Command <B>fd</B>:
249 <A NAME="kcfd"></A> Set some keys to give make codes
253 This command clears the "generate break code" bits for the indicated keys.
254 It is followed by the untranslated Set 3 scancodes of the keys for which
255 this bit must be set. The sequence is ended by a recognized command code
256 (such as <B>ed</B>, <B>ee</B>, <B>f0</B>, <B>f2</B>-<B>ff</B>).
257 Afterwards, a "keyboard enable" <B>f4</B> is required.
259 <P><I>Command <B>fe</B>:
260 <A NAME="kcfe"></A> Resend</I>
263 Meant for use by the keyboard controller after a transmission error.
264 Not for use by the CPU.
266 <P><I>Command <B>ff</B>:
267 <A NAME="kcff"></A> Keyboard reset</I>
271 The self-test (BAT) will return <B>aa</B> when OK, and <B>fc</B> otherwise.
272 As part of the self-test, all LEDs are flashed.
276 <A HREF="scancodes-12.html">Next</A>
277 <A HREF="scancodes-10.html">Previous</A>
278 <A HREF="scancodes.html#toc11">Contents</A>