├── LICENSE ├── README.md ├── examples ├── International │ └── International.ino └── KeyToLCD │ └── KeyToLCD.ino ├── extra ├── UTF-8codes.txt ├── readme.txt └── websites.txt ├── keywords.txt ├── library.properties └── src ├── PS2KeyData.h ├── PS2KeyMap.cpp └── PS2KeyMap.h /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | (This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.) 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | {description} 474 | Copyright (C) {year} {fullname} 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | {signature of Ty Coon}, 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PS2KeyMap 2 | ### Arduino PS2 keyboard International Keyboard mapping from PS2KeyAdvanced and return as UTF-8 3 | 4 | ## This library requires PS2KeyAdvanced as well to work 5 | **V1.0.6** April 2020 Correct _KeyMaps definition error in V1.0.5 6 | 7 | V1.0.5 March 2020 Add Italian and Spanish keyboard layouts 8 | 9 | V1.0.4 January 2020 Work better with new library manager spec and better 10 | additional platform possibilities 11 | 12 | V1.0.3 July 2018 Improved keywords file 13 | 14 | First Public Release Version V1.0.2 15 | 16 | Smaller footprint than any others found and more functionality. 17 | 18 | ### Platforms 19 | 20 | Arduino AVR - tested on Uno and Mega 2560 21 | Arduino SAM - tested on DUE 22 | SAMD1 - tested by user on Seeeduino Xiao M0+ 23 | 24 | ### Test Environment 25 | 26 | All platforms versions of test R3 Hardware 27 | Arduino V1.6.7 28 | DUE Board Manager package V1.6.6 29 | 30 | ## Important Hardware Notes 31 | 32 | 1. Make sure you have data and clock wires connected correctly. Clock wire MUST be connected to an interrupt pin. 33 | 34 | - Do NOT use Pin 13 for either clock or data wires 35 | - PS2KeyRaw requires both pins specified for begin() as in keyboard.begin( data_pin, irq_pin ); 36 | - Valid irq pins: 37 | - Arduino Uno: 2, 3 38 | - Arduino Due: All pins, except 13 (LED) 39 | - Arduino Mega: 2, 3, 18, 19, 20, 21 40 | - Teensy 2.0: All pins, except 13 (LED) 41 | - Teensy 2.0: 5, 6, 7, 8 42 | - Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16 43 | - Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37 44 | - Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37 45 | - Sanguino: 2, 10, 11 46 | 47 | 2. When using DUE or other boards with 3V3 I/O you MUST use a level translator FET or IC like Texas Instruments TXS0102 or similar as most keyboards not only operate at 5V but the two wire communications are pulled up by a resistor to 5V at the keyboard end. 48 | 49 | ### Introduction 50 | 51 | After looking round for suitable libraries I found most were lacking in functionality and high in code and data footprint, so I created a series of PS2 Keyboard libraries. This is the third which extends the second one PS2KeyAdvanced to support different Country keyboard mapping. More countries and special mappings can be added. 52 | 53 | The size of the keyboard mappings is smaller than other libraries as some countries can be not used, and existing mappings are only the keys that are different from US layout, so only change data is stored (in Flash). 54 | 55 | The library takes the 16 bit integer from PS2KeyAdvanced and converts to UTF-8/ASCII honouring SHIFT, CAPS and as long as NOT a functional key like F1 to F24 or Page Up, will convert to UTF-8 equivalent, otherwise same code is returned. 56 | 57 | Current Country mappings included (other contributions welcomed) 58 | * US 59 | * UK/GB 60 | * DE - German 61 | * FR - French 62 | 63 | You can select which map to use from your programme. 64 | 65 | ### Installation 66 | 67 | Performed by standard zip file library inclusion into Arduino IDE 68 | 69 | ### Examples 70 | 71 | This library has TWO examples, from simplest to most complec - 72 | 73 | - Internationl that uses the serial port to output the converted codes received and allow changing of keyboard mapping on the fly. 74 | - KeyToLCD - Example that will allow you to display converted keyboard characters on LCD connected to Arduino and allow cursor movements to move the cursor on LCD, whilst also displaying strings for keys like ESC, TAB, F1 to F12 75 | 76 | Note on LCDs and some terminal emulators not all characters may be supported. 77 | 78 | ## Euro Currency Symbol 79 | 80 | As the Euro came about *AFTER* the standardisation of UTF-8, the Euro Symbol is a supported keycode but *NOT* a conversion to UTF-8. This is just not possible. 81 | 82 | ### Contributor and Author Details 83 | 84 | Author Paul Carpenter, PC Services 85 | 86 | Web Site http://www.pcserviceselectronics.co.uk 87 | -------------------------------------------------------------------------------- /examples/International/International.ino: -------------------------------------------------------------------------------- 1 | /* international keyboard mapping example to serial port 2 | 3 | Example keyboard on Arduino to Serial port using baud of 115,200 4 | 5 | PS2KeyMap extension library for PS2KeyAdvanced library, 6 | Key mapping to ASCII/UTF-8 mapping and International Keyboard 7 | Layout Example. 8 | 9 | IMPORTANT WARNING 10 | 11 | If using a DUE or similar board with 3V3 I/O you MUST put a level translator 12 | like a Texas Instruments TXS0102 or FET circuit as the signals are 13 | Bi-directional (signals transmitted from both ends on same wire). 14 | 15 | Failure to do so may damage your Arduino Due or similar board. 16 | 17 | Test History 18 | September 2014 Uno and Mega 2560 September 2014 using Arduino V1.6.0 19 | January 2016 Uno, Mega 2560 and Due using Arduino 1.6.7 and Due Board 20 | Manager V1.6.6 21 | March 2020 Extend for Italian and Spanish keyboards 22 | 23 | PS2KeyMap uses a default US-ASCII Map but different country 24 | mappings can be selected on the fly 25 | 26 | Map to the keyboard you want when running by typing 27 | 28 | U for US keyboard 29 | G for UK keyboard 30 | D for German keyboard 31 | F for French keyboard 32 | I for Italian keyboard 33 | E for Spanish keyboard 34 | 35 | Defaults to US on start up 36 | 37 | The circuit: 38 | * KBD Clock (PS2 pin 1) to an interrupt pin on Arduino ( this example pin 3 ) 39 | * KBD Data (PS2 pin 5) to a data pin ( this example pin 4 ) 40 | * +5V from Arduino to PS2 pin 1 41 | * GND from Arduino to PS2 pin 3 42 | 43 | The connector to mate with PS2 keyboard is a 6 pin Female Mini-Din connector 44 | PS2 Pins to signal 45 | 1 KBD Data 46 | 3 GND 47 | 4 +5V 48 | 5 KBD Clock 49 | 50 | Keyboard has 5V and GND connected see plenty of examples and 51 | photos around on Arduino site and other sites about the PS2 Connector. 52 | 53 | Interrupts 54 | 55 | Clock pin from PS2 keyboard MUST be connected to an interrupt 56 | pin, these vary with the different types of Arduino 57 | 58 | For PS2KeyAdvanced you pass this info into begin() 59 | 60 | keyboard.begin( DATAPIN, IRQPIN ); 61 | 62 | Valid irq pins: 63 | Arduino Uno: 2, 3 64 | Arduino Due: All pins, except 13 (LED) 65 | Arduino Mega: 2, 3, 18, 19, 20, 21 66 | Teensy 2.0: All pins, except 13 (LED) 67 | Teensy 2.0: 5, 6, 7, 8 68 | Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16 69 | Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37 70 | Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37 71 | Sanguino: 2, 10, 11 72 | 73 | Like the Original library and example this is under LGPL license. 74 | 75 | Written by Paul Carpenter, PC Services 76 | */ 77 | 78 | #include 79 | // Include all mappings 80 | #include 81 | 82 | /* Keyboard constants Change to suit your Arduino 83 | define pins used for data and clock from keyboard */ 84 | #define DATAPIN 4 85 | #define IRQPIN 3 86 | 87 | PS2KeyAdvanced keyboard; 88 | PS2KeyMap keymap; 89 | 90 | uint16_t code; 91 | uint8_t found; 92 | 93 | 94 | void setup() 95 | { 96 | Serial.begin( 115200 ); 97 | Serial.println( "PS2KeyMap plus PS2KeyAdvanced Libraries" ); 98 | Serial.println( "International Keyboard Test:" ); 99 | Serial.print( "Default is US layout, type a key to change layout\n" 100 | " U for US G for GB/UK\n" ); 101 | Serial.println( " D for DE F for FR\n" 102 | " I for IT E for ES\n" 103 | " All keys on keyboard echoed here" ); 104 | // Start keyboard setup while outputting 105 | keyboard.begin( DATAPIN, IRQPIN ); 106 | // Disable Break codes (key release) from PS2KeyAdvanced 107 | keyboard.setNoBreak( 1 ); 108 | // and set no repeat on CTRL, ALT, SHIFT, GUI while outputting 109 | keyboard.setNoRepeat( 1 ); 110 | } 111 | 112 | 113 | void loop() 114 | { 115 | if( keyboard.available() ) 116 | { 117 | code = keyboard.read(); 118 | Serial.print( "Value " ); 119 | Serial.print( code, HEX ); 120 | code = keymap.remapKey( code ); 121 | if( code > 0 ) 122 | { 123 | if( ( code & 0xFF ) ) 124 | { 125 | Serial.print( " mapped " ); 126 | Serial.print( code, HEX ); 127 | Serial.print( " - Status Bits " ); 128 | Serial.print( code >> 8, HEX ); 129 | Serial.print( " Code " ); 130 | Serial.print( code & 0xFF, HEX ); 131 | Serial.print( " ( " ); 132 | Serial.write( code & 0xFF ); 133 | Serial.print( " )\n" ); 134 | } 135 | // process special commands 136 | found = 0; 137 | switch( code ) 138 | { 139 | case 'D': 140 | case 'd': 141 | found = keymap.selectMap( (char *)"DE" ); 142 | break; 143 | case 'F': 144 | case 'f': 145 | found = keymap.selectMap( (char *)"FR" ); 146 | break; 147 | case 'E': 148 | case 'e': 149 | found = keymap.selectMap( (char *)"ES" ); 150 | break; 151 | case 'I': 152 | case 'i': 153 | found = keymap.selectMap( (char *)"IT" ); 154 | break; 155 | case 'G': 156 | case 'g': 157 | found = keymap.selectMap( (char *)"UK" ); 158 | break; 159 | case 'u': 160 | case 'U': 161 | found = keymap.selectMap( (char *)"US" ); 162 | break; 163 | } 164 | if( found ) 165 | { 166 | Serial.print( "Keyboard set to " ); 167 | Serial.println( keymap.getMap( ) ); 168 | } 169 | } 170 | else 171 | Serial.println( " Keyboard protocol or function" ); 172 | } 173 | delay( 100 ); 174 | } 175 | -------------------------------------------------------------------------------- /examples/KeyToLCD/KeyToLCD.ino: -------------------------------------------------------------------------------- 1 | /* international keyboard layout example to serial port 2 | 3 | Test for keyboard with additional keyboard mapping for UTF-8 and LiquidCrystal 4 | Only uses ONE key mapping not changeable at run time only at compile time 5 | 6 | Requires PS2KeyAdvanced and PS2KeyMap libraries to work 7 | 8 | IMPORTANT WARNING 9 | 10 | If using a DUE or similar board with 3V3 I/O you MUST put a level translator 11 | like a Texas Instruments TXS0102 or FET circuit as the signals are 12 | Bi-directional (signals transmitted from both ends on same wire). 13 | 14 | Failure to do so may damage your Arduino Due or similar board. 15 | 16 | Test History 17 | September 2014 Uno and Mega 2560 September 2014 using Arduino V1.6.0 18 | January 2016 Uno, Mega 2560 and Due using Arduino 1.6.7 and Due Board 19 | Manager V1.6.6 20 | March 2020 Simplify example 21 | 22 | This sketch displays text received from PS2 keyboard to LCD 23 | on same Arduino. Importantly it maps the keyboard to UTF-8 24 | codes and allows changes of which keyboard map. 25 | 26 | Allows the cursor movement keys as follows - 27 | 28 | Enter move to beginning of next line and wraps to top 29 | PGUP and PGDN go to top and bottom row in same column of LCD 30 | Arrow keys move one line or character and wrap round rows 31 | Backspace does backspace space backspace sequence 32 | Home goes to top left 33 | End goes to bottom right 34 | Keys TAB DEL ESC and F1 to F12 are displayed as strings 35 | 36 | All typing and some cursor movements wrap to appropriate 37 | line forwards and backwards 38 | 39 | Example works on any size text LCD, set for 16 x 2 40 | Change MAX_COLS and MAX_ROWS to match your LCD 41 | 42 | Also example of strings in flash memory 43 | 44 | Map to the keyboard you want in setup with 45 | 46 | keymap.setmap( "UK" ); 47 | 48 | or similar currently support for US (default), UK/GB, DE and FR. 49 | 50 | Displayable characters passed through (depends on LCD character set) 51 | 52 | The circuit: 53 | * LCD RS pin to digital pin 12 54 | * LCD Enable pin to digital pin 11 55 | * LCD D4 pin to digital pin 10 56 | * LCD D5 pin to digital pin 9 57 | * LCD D6 pin to digital pin 8 58 | * LCD D7 pin to digital pin 7 59 | * LCD R/W pin to ground 60 | * 10K variable resistor (trimmer or potentiometer): 61 | - ends to +5V and ground 62 | - wiper to LCD VO pin (pin 3) 63 | * KBD Clock (PS2 pin 1) to an interrupt pin on Arduino ( this example pin 3 ) 64 | * KBD Data (PS2 pin 5) to a data pin ( this example pin 4 ) 65 | * +5V from Arduino to PS2 pin 1 66 | * GND from Arduino to PS2 pin 3 67 | 68 | The connector to mate with PS2 keyboard is a 6 pin Female Mini-Din connector 69 | PS2 Pins to signal 70 | 1 KBD Data 71 | 3 GND 72 | 4 +5V 73 | 5 KBD Clock 74 | 75 | Keyboard has 5V and GND connected see plenty of examples and 76 | photos around on Arduino site and other sites about the PS2 Connector. 77 | 78 | Interrupts 79 | 80 | Clock pin from PS2 keyboard MUST be connected to an interrupt 81 | pin, these vary with the different types of Arduino 82 | 83 | For PS2KeyAdvanced you pass this info into begin() 84 | 85 | keyboard.begin( DATAPIN, IRQPIN ); 86 | 87 | Valid irq pins: 88 | Arduino Uno: 2, 3 89 | Arduino Due: All pins, except 13 (LED) 90 | Arduino Mega: 2, 3, 18, 19, 20, 21 91 | Teensy 2.0: All pins, except 13 (LED) 92 | Teensy 2.0: 5, 6, 7, 8 93 | Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16 94 | Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37 95 | Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37 96 | Sanguino: 2, 10, 11 97 | 98 | Like the Original library and example this is under LGPL license. 99 | 100 | Written by Paul Carpenter, PC Services 101 | */ 102 | 103 | // include the library code: 104 | #include 105 | #include 106 | #include 107 | 108 | /* Keyboard constants Change to suit your Arduino 109 | define pins used for data and clock from keyboard */ 110 | #define DATAPIN 4 111 | #define IRQPIN 3 112 | 113 | /* LCD pins definitions to match your LCD 4 bit mode */ 114 | #define RS 12 115 | #define ENA 11 116 | #define RW 10 117 | #define D7 9 118 | #define D6 8 119 | #define D5 7 120 | #define D4 6 121 | 122 | /* LCD Constants to match your display 16 x 2 */ 123 | /* Columns in display */ 124 | #define MAX_COL 16 125 | /* Rows in display */ 126 | #define MAX_ROW 2 127 | 128 | /* LCD Constants to match your display 20 x 4 */ 129 | /* Columns in display */ 130 | //#define MAX_COL 20 131 | /* Rows in display */ 132 | //#define MAX_ROW 4 133 | 134 | /* current cursor position */ 135 | signed char cols = 0; 136 | signed char rows = 0; 137 | 138 | /* messages constants */ 139 | /* Key codes and strings for keys producing a string */ 140 | /* three arrays in same order ( keycode, string to display, length of string ) */ 141 | uint8_t codes[] = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC, 142 | PS2_KEY_DELETE, PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3, 143 | PS2_KEY_F4, PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7, 144 | PS2_KEY_F8, PS2_KEY_F9, PS2_KEY_F10, PS2_KEY_F11, 145 | PS2_KEY_F12 }; 146 | const char *const keys[] = { " ", "[Tab]", "[ESC]", "[Del]", "[F1]", "[F2]", "[F3]", 147 | "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", 148 | "[F9]", "[F10]", "[F11]", "[F12]" }; 149 | int8_t sizes[] = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 }; 150 | 151 | 152 | // Class initialisation/instantiation 153 | // keyboard library 154 | PS2KeyAdvanced keyboard; 155 | // Initialise the keyboard remapping to UTF-8 156 | PS2KeyMap keymap; 157 | 158 | // initialize the LCD library with the numbers of the interface pins 159 | // For 4 bit interface first with RW pin grounded on LCD 160 | //LiquidCrystal lcd( RS, ENA, D4, D5, D6, D7 ); 161 | LiquidCrystal lcd( RS, RW, ENA, D4, D5, D6, D7 ); 162 | 163 | void setup() 164 | { 165 | // set up the LCD's number of columns and rows 166 | lcd.begin( MAX_COL, MAX_ROW ); 167 | lcd.clear(); // clear the screen 168 | lcd.cursor(); // Enable Cursor 169 | lcd.blink(); // Blinking cursor 170 | lcd.print( "PC Services" ); // Display signon text 171 | lcd.setCursor( 0,1 ); 172 | lcd.print( "Keyboard to LCD" ); 173 | keyboard.begin( DATAPIN, IRQPIN );// Setup keyboard pins 174 | keyboard.setNoBreak( 1 ); // No break codes for keys (when key released) 175 | keyboard.setNoRepeat( 1 ); // Don't repeat shift ctrl etc 176 | keymap.selectMap( (char *)"UK" ); // set which type of keyboard we have 177 | // Display type of keyboard mapped 178 | lcd.setCursor( 13,0 ); 179 | lcd.print( keymap.getMap( ) ); // display keyboard setting 180 | lcd.setCursor( 12,0 ); 181 | cols = 12; // update cursor position 182 | rows = 0; 183 | } 184 | 185 | void check_cursor() 186 | { 187 | if( cols >= MAX_COL ) 188 | { 189 | cols = 0; 190 | rows++; 191 | if( rows >= MAX_ROW ) 192 | rows = 0; 193 | lcd.setCursor( cols, rows ); 194 | } 195 | } 196 | 197 | void loop() 198 | { 199 | /* mode = 0 echo character 200 | mode = 1 print string 201 | mode = 2 cursor movement NO other echo 202 | mode = 4 ignore key no echo */ 203 | byte mode; 204 | byte idx; 205 | byte base; 206 | int c; 207 | 208 | if( keyboard.available() ) 209 | { 210 | // read the next key 211 | if( ( c = keyboard.read() ) ) 212 | { 213 | // check for some of the special keys 214 | mode = 2; 215 | base = c & 0xFF; 216 | switch( base ) /* Cursor movements */ 217 | { 218 | case PS2_KEY_ENTER: /* Cursor to beginning of next line or start */ 219 | case PS2_KEY_KP_ENTER: 220 | cols = 0; 221 | rows++; 222 | if( rows >= MAX_ROW ) 223 | rows = 0; 224 | break; 225 | case PS2_KEY_PGDN: /* Cursor to top row current column */ 226 | rows = MAX_ROW - 1; 227 | break; 228 | case PS2_KEY_PGUP: /* Cursor to bottom row current column */ 229 | rows = 0; 230 | break; 231 | case PS2_KEY_L_ARROW: /* Cursor left or end of previous line */ 232 | cols--; 233 | if( cols < 0 ) 234 | { 235 | cols = MAX_COL - 1; 236 | rows--; 237 | if( rows < 0 ) 238 | rows = MAX_ROW - 1; 239 | } 240 | break; 241 | case PS2_KEY_R_ARROW: /* Cursor right or start of next line */ 242 | cols++; 243 | if( cols >= MAX_COL ) 244 | { 245 | cols = 0; 246 | rows++; 247 | if( rows >= MAX_COL ) 248 | rows = 0; 249 | } 250 | break; 251 | case PS2_KEY_UP_ARROW: /* Cursor up one line no wrap */ 252 | rows--; 253 | if( rows < 0 ) 254 | rows = 0; 255 | break; 256 | case PS2_KEY_DN_ARROW: /* Cursor down one line no wrap */ 257 | rows++; 258 | if( rows >= MAX_ROW ) 259 | rows = MAX_ROW - 1; 260 | break; 261 | case PS2_KEY_BS: /* Move cursor back write space move cursor back */ 262 | cols--; 263 | if( cols < 0 ) 264 | { 265 | cols = MAX_COL - 1; 266 | rows--; 267 | if( rows < 0 ) 268 | rows = MAX_ROW - 1; 269 | } 270 | lcd.setCursor( cols, rows ); 271 | lcd.write( ' ' ); 272 | break; 273 | case PS2_KEY_HOME: /* Cursor to top left */ 274 | cols = 0; 275 | rows = 0; 276 | break; 277 | case PS2_KEY_END: /* Cursor to max position */ 278 | cols = MAX_COL - 1; 279 | rows = MAX_ROW - 1; 280 | break; 281 | default: /* Not cursor movement */ 282 | mode = 0; 283 | } 284 | /* if was cursor movement do last movement */ 285 | if( mode == 2 ) 286 | lcd.setCursor( cols, rows ); 287 | else 288 | { 289 | /* Check for strings or single character to display */ 290 | if( base != PS2_KEY_EUROPE2 && ( base < PS2_KEY_KP0 || base >= PS2_KEY_F1 ) ) 291 | { // Non printable sort which ones we can print 292 | for( idx = 0; idx < sizeof( codes ); idx++ ) 293 | if( base == codes[ idx ] ) 294 | { 295 | /* String outputs */ 296 | mode = 1; 297 | c = sizes[ idx ]; 298 | cols += c - 1; 299 | check_cursor( ); 300 | /* when cursor reset keep track */ 301 | if( cols == 0 ) 302 | cols = c; 303 | lcd.print( keys[ idx ] ); 304 | cols++; 305 | check_cursor( ); 306 | break; 307 | } 308 | /* if not found a string ignore key cant do anything */ 309 | } 310 | else 311 | { /* Supported key */ 312 | if( ( base = keymap.remapKey( c ) ) > 0 ) 313 | { 314 | check_cursor( ); 315 | cols++; 316 | lcd.write( base ); 317 | check_cursor( ); 318 | } 319 | } 320 | } 321 | } 322 | delay( 100 ); 323 | } 324 | } 325 | -------------------------------------------------------------------------------- /extra/UTF-8codes.txt: -------------------------------------------------------------------------------- 1 | Constants to use in decoding keyboard values from PS2KeyMap 2 | 3 | Copyright (c) 2007 Free Software Foundation. All right reserved. 4 | Written by Paul Carpenter, PC Services 5 | Created September 2014 6 | Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management 7 | 8 | Extra constants in case you cannot type UTF-8 codes for the codes BEYOND 9 | US-ASCII that are defined in UTF-8 10 | 11 | Standard codes actually in US-ASCII but useful 12 | 13 | PS2_BACKSPACE 14 | PS2_TAB 15 | PS2_ENTER 16 | PS2_ESC 17 | PS2_DELETE 18 | PS2_SPACE 19 | 20 | UTF-8 single byte LATIN encodings 21 | 128 to 159 (0x80 to 0x9F) are control characters application generated 22 | 160 to 255 (0xA0 to 0XFF) are used depending on keymap tables 23 | 24 | ==================================================================== 25 | IMPORTANT NOTE EURO currency Symbol is NOT supported in UTF-8 single 26 | byte codings, as EURO symbol came after UTF-8 single byte coding 27 | ==================================================================== 28 | 29 | The symbols are shown on right but MAY not be displayed if you are viewing 30 | or printing in a non-UTF-8 supporting environment. 31 | 32 | PS2_NO_BREAK_SPACE nbsp 33 | PS2_INVERTED_EXCLAMATION ¡ 34 | PS2_CENT_SIGN ¢ 35 | PS2_POUND_SIGN £ 36 | PS2_CURRENCY_SIGN ¤ 37 | PS2_YEN_SIGN ¥ 38 | PS2_BROKEN_BAR ¦ 39 | PS2_SECTION_SIGN § 40 | PS2_DIAERESIS ¨ 41 | PS2_COPYRIGHT_SIGN © 42 | PS2_FEMININE_ORDINAL ª 43 | PS2_LEFT_DOUBLE_ANGLE_QUOTE « 44 | PS2_NOT_SIGN ¬ 45 | PS2_HYPHEN 46 | PS2_REGISTERED_SIGN ® 47 | PS2_MACRON ¯ 48 | PS2_DEGREE_SIGN ° 49 | PS2_PLUS_MINUS_SIGN ± 50 | PS2_SUPERSCRIPT_TWO ² 51 | PS2_SUPERSCRIPT_THREE ³ 52 | PS2_ACUTE_ACCENT ´ 53 | PS2_MICRO_SIGN µ 54 | PS2_PILCROW_SIGN ¶ 55 | PS2_MIDDLE_DOT · 56 | PS2_CEDILLA ¸ 57 | PS2_SUPERSCRIPT_ONE ¹ 58 | PS2_MASCULINE_ORDINAL º 59 | PS2_RIGHT_DOUBLE_ANGLE_QUOTE » 60 | PS2_FRACTION_ONE_QUARTER ¼ 61 | PS2_FRACTION_ONE_HALF ½ 62 | PS2_FRACTION_THREE_QUARTERS ¾ 63 | PS2_INVERTED_QUESTION_MARK ¿ 64 | PS2_A_GRAVE À 65 | PS2_A_ACUTE Á 66 | PS2_A_CIRCUMFLEX Â 67 | PS2_A_TILDE Ã 68 | PS2_A_DIAERESIS Ä 69 | PS2_A_RING_ABOVE Å 70 | PS2_AE Æ 71 | PS2_C_CEDILLA Ç 72 | PS2_E_GRAVE È 73 | PS2_E_ACUTE É 74 | PS2_E_CIRCUMFLEX Ê 75 | PS2_E_DIAERESIS Ë 76 | PS2_I_GRAVE Ì 77 | PS2_I_ACUTE Í 78 | PS2_I_CIRCUMFLEX Î 79 | PS2_I_DIAERESIS Ï 80 | PS2_ETH Ð 81 | PS2_N_TILDE Ñ 82 | PS2_O_GRAVE Ò 83 | PS2_O_ACUTE Ó 84 | PS2_O_CIRCUMFLEX Ô 85 | PS2_O_TILDE Õ 86 | PS2_O_DIAERESIS Ö 87 | PS2_MULTIPLICATION × 88 | PS2_O_STROKE Ø 89 | PS2_U_GRAVE Ù 90 | PS2_U_ACUTE Ú 91 | PS2_U_CIRCUMFLEX Û 92 | PS2_U_DIAERESIS Ü 93 | PS2_Y_ACUTE Ý 94 | PS2_THORN Þ 95 | PS2_SHARP_S ß 96 | PS2_a_GRAVE à 97 | PS2_a_ACUTE á 98 | PS2_a_CIRCUMFLEX â 99 | PS2_a_TILDE ã 100 | PS2_a_DIAERESIS ä 101 | PS2_a_RING_ABOVE å 102 | PS2_ae æ 103 | PS2_c_CEDILLA ç 104 | PS2_e_GRAVE è 105 | PS2_e_ACUTE é 106 | PS2_e_CIRCUMFLEX ê 107 | PS2_e_DIAERESIS ë 108 | PS2_i_GRAVE ì 109 | PS2_i_ACUTE í 110 | PS2_i_CIRCUMFLEX î 111 | PS2_i_DIAERESIS ï 112 | PS2_eth ð 113 | PS2_n_TILDE ñ 114 | PS2_o_GRAVE ò 115 | PS2_o_ACUTE ó 116 | PS2_o_CIRCUMFLEX ô 117 | PS2_o_TILDE õ 118 | PS2_o_DIAERESIS ö 119 | PS2_DIVISION ÷ 120 | PS2_o_STROKE ø 121 | PS2_u_GRAVE ù 122 | PS2_u_ACUTE ú 123 | PS2_u_CIRCUMFLEX û 124 | PS2_u_DIAERESIS ü 125 | PS2_y_ACUTE ý 126 | PS2_thorn þ 127 | PS2_y_DIAERESIS ÿ 128 | -------------------------------------------------------------------------------- /extra/readme.txt: -------------------------------------------------------------------------------- 1 | PS2KeyMap - Extension to PS2KeyAdvanced library 2 | Copyright (c) 2007 Free Software Foundation. All right reserved. 3 | Written by Paul Carpenter, PC Services 4 | Created September 2014 5 | Updated January 2016 6 | 7 | This is for a LATIN style keyboard. 8 | 9 | Assumption ONLY ONE keyboard connected to system 10 | 11 | Converts key codes from PS2KeyAdvanced library reads, to UTF-8 codes (with 12 | CTRL,ALT....) taking into account the country keyboard mapping selected. 13 | 14 | Note as humans cannot type multiple keys at EXACT same time if waiting for 15 | the three keys together + + , you WILL receive, mixtures of 16 | these keys before the final combination is seen. 17 | 18 | You can add your own keyboard mappings as EXTRA mappings, follow the style in 19 | PS2KeyData.h to add a mapping table. The mapping tables only contain the 20 | differences from US layout. Use PS2KeyAdvanced example SimpleTest to note the 21 | codes received first from the keyboard for the keys you want to change before 22 | adding the table. 23 | 24 | See also file websites.txt for website information about PS2 interface, protocol 25 | scancodes and UTF-8 encoding. 26 | 27 | Files are 28 | 29 | extras folder 30 | readme.txt this file 31 | websites.txt Other websites about UTF-8 and PS2 keyboard 32 | UTF-8codes.txt Constants for codes beyond US-ASCII 33 | 34 | src folder 35 | PS2KeyMap.cpp the library code 36 | PS2KeyMap.h Library Header for sketches defines class and values 37 | returned for keys 38 | PS2KeyData.h Mapping tables (held in Flash) 39 | 40 | examples folder 41 | international reads every returned keycode back to serial 42 | Some keys will change the mapping to different country 43 | on the fly 44 | KeyToLCD reads keyboard and displays where possible on LCD with 45 | pre-selected in code ONE country mapping 46 | 47 | Reading a key code returns an UNSIGNED INT containing 48 | Make/Break status 49 | Caps status 50 | Shift, Ctrl, Alt, Alt Gr, GUI keys 51 | Flag for function key not a displayable/printable character 52 | 8 bit key code 53 | 54 | See PS2KeyAdvanced for non-UTF-8 mapping codes like F1 to F24, HOME, END as 55 | these will set the function bit. 56 | 57 | See extras/UTF-8codes.txt for the codes returned beyond standard US-ASCII in 58 | bottom 8 bits 59 | 60 | Top Byte is 8 bits denoting as follows and standard defines available see 61 | PS2KeyAdvanced for these details 62 | 63 | Error Codes 64 | Most functions return 0 or 0xFFFF as error, other codes to note and 65 | handle appropriately 66 | 67 | Paul Carpenter 68 | PC Services 69 | January 2016 70 | http://www.pcserviceselectronics.co.uk -------------------------------------------------------------------------------- /extra/websites.txt: -------------------------------------------------------------------------------- 1 | Some URLs of useful technical sites that give you the inner workings details 2 | of the PS2 Keyboard interface, not in any order, many have pictures on - 3 | 4 | PS2 Interface, Keyboard and scan codes 5 | 6 | https://en.wikipedia.org/wiki/PS/2_port 7 | http://www.computer-engineering.org/ps2keyboard/ 8 | http://computer-engineering.org/ps2protocol/ 9 | http://retired.beyondlogic.org/keyboard/keybrd.htm 10 | http://wiki.osdev.org/PS/2_Keyboard 11 | 12 | UTF-8 13 | http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=char 14 | 15 | Old Arduino site library page 16 | http://playground.arduino.cc/Main/PS2Keyboard -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Colouring Map For PS2KeyMap 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes/class (KEYWORD1) 7 | ####################################### 8 | PS2KeyMap KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | selectMap KEYWORD2 14 | getMap KEYWORD2 15 | remapKey KEYWORD2 16 | remapKeyByte KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | PS2_NO_BREAK_SPACE LITERAL1 22 | PS2_INVERTED_EXCLAMATION LITERAL1 23 | PS2_CENT_SIGN LITERAL1 24 | PS2_POUND_SIGN LITERAL1 25 | PS2_CURRENCY_SIGN LITERAL1 26 | PS2_YEN_SIGN LITERAL1 27 | PS2_BROKEN_BAR LITERAL1 28 | PS2_SECTION_SIGN LITERAL1 29 | PS2_DIAERESIS LITERAL1 30 | PS2_COPYRIGHT_SIGN LITERAL1 31 | PS2_FEMININE_ORDINAL LITERAL1 32 | PS2_LEFT_DOUBLE_ANGLE_QUOTE LITERAL1 33 | PS2_NOT_SIGN LITERAL1 34 | PS2_HYPHEN LITERAL1 35 | PS2_REGISTERED_SIGN LITERAL1 36 | PS2_MACRON LITERAL1 37 | PS2_DEGREE_SIGN LITERAL1 38 | PS2_PLUS_MINUS_SIGN LITERAL1 39 | PS2_SUPERSCRIPT_TWO LITERAL1 40 | PS2_SUPERSCRIPT_THREE LITERAL1 41 | PS2_ACUTE_ACCENT LITERAL1 42 | PS2_MICRO_SIGN LITERAL1 43 | PS2_PILCROW_SIGN LITERAL1 44 | PS2_MIDDLE_DOT LITERAL1 45 | PS2_CEDILLA LITERAL1 46 | PS2_SUPERSCRIPT_ONE LITERAL1 47 | PS2_MASCULINE_ORDINAL LITERAL1 48 | PS2_RIGHT_DOUBLE_ANGLE_QUOTE LITERAL1 49 | PS2_FRACTION_ONE_QUARTER LITERAL1 50 | PS2_FRACTION_ONE_HALF LITERAL1 51 | PS2_FRACTION_THREE_QUARTERS LITERAL1 52 | PS2_INVERTED_QUESTION_MARK LITERAL1 53 | PS2_A_GRAVE LITERAL1 54 | PS2_A_ACUTE LITERAL1 55 | PS2_A_CIRCUMFLEX LITERAL1 56 | PS2_A_TILDE LITERAL1 57 | PS2_A_DIAERESIS LITERAL1 58 | PS2_A_RING_ABOVE LITERAL1 59 | PS2_AE LITERAL1 60 | PS2_C_CEDILLA LITERAL1 61 | PS2_E_GRAVE LITERAL1 62 | PS2_E_ACUTE LITERAL1 63 | PS2_E_CIRCUMFLEX LITERAL1 64 | PS2_E_DIAERESIS LITERAL1 65 | PS2_I_GRAVE LITERAL1 66 | PS2_I_ACUTE LITERAL1 67 | PS2_I_CIRCUMFLEX LITERAL1 68 | PS2_I_DIAERESIS LITERAL1 69 | PS2_ETH LITERAL1 70 | PS2_N_TILDE LITERAL1 71 | PS2_O_GRAVE LITERAL1 72 | PS2_O_ACUTE LITERAL1 73 | PS2_O_CIRCUMFLEX LITERAL1 74 | PS2_O_TILDE LITERAL1 75 | PS2_O_DIAERESIS LITERAL1 76 | PS2_MULTIPLICATION LITERAL1 77 | PS2_O_STROKE LITERAL1 78 | PS2_U_GRAVE LITERAL1 79 | PS2_U_ACUTE LITERAL1 80 | PS2_U_CIRCUMFLEX LITERAL1 81 | PS2_U_DIAERESIS LITERAL1 82 | PS2_Y_ACUTE LITERAL1 83 | PS2_THORN LITERAL1 84 | PS2_SHARP_S LITERAL1 85 | PS2_a_GRAVE LITERAL1 86 | PS2_a_ACUTE LITERAL1 87 | PS2_a_CIRCUMFLEX LITERAL1 88 | PS2_a_TILDE LITERAL1 89 | PS2_a_DIAERESIS LITERAL1 90 | PS2_a_RING_ABOVE LITERAL1 91 | PS2_ae LITERAL1 92 | PS2_c_CEDILLA LITERAL1 93 | PS2_e_GRAVE LITERAL1 94 | PS2_e_ACUTE LITERAL1 95 | PS2_e_CIRCUMFLEX LITERAL1 96 | PS2_e_DIAERESIS LITERAL1 97 | PS2_i_GRAVE LITERAL1 98 | PS2_i_ACUTE LITERAL1 99 | PS2_i_CIRCUMFLEX LITERAL1 100 | PS2_i_DIAERESIS LITERAL1 101 | PS2_eth LITERAL1 102 | PS2_n_TILDE LITERAL1 103 | PS2_o_GRAVE LITERAL1 104 | PS2_o_ACUTE LITERAL1 105 | PS2_o_CIRCUMFLEX LITERAL1 106 | PS2_o_TILDE LITERAL1 107 | PS2_o_DIAERESIS LITERAL1 108 | PS2_DIVISION LITERAL1 109 | PS2_o_STROKE LITERAL1 110 | PS2_u_GRAVE LITERAL1 111 | PS2_u_ACUTE LITERAL1 112 | PS2_u_CIRCUMFLEX LITERAL1 113 | PS2_u_DIAERESIS LITERAL1 114 | PS2_y_ACUTE LITERAL1 115 | PS2_thorn LITERAL1 116 | PS2_y_DIAERESIS LITERAL1 117 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=PS2KeyMap 2 | version=1.0.6 3 | author=Paul Carpenter 4 | maintainer=Paul Carpenter 5 | sentence=PS2 keyboard codes from PS2KeyAdvanced to UTF-8 for any Latin language keyboard. 6 | paragraph=Takes integer values from PS2KeyAdvanced to convert using selectable country mapping and you can add your own country mapping. 7 | category=Other 8 | url=https://github.com/techpaul/PS2KeyMap.git 9 | architectures=avr,sam,samd1 10 | depends=PS2KeyAdvanced 11 | includes=PS2KeyAdvanced.h,PS2KeyMap.h 12 | 13 | -------------------------------------------------------------------------------- /src/PS2KeyData.h: -------------------------------------------------------------------------------- 1 | /* Version V1.0.6 2 | PS2KeyMap.h - PS2KeyAdvanced library 3 | Copyright (c) 2007 Free Software Foundation. All right reserved. 4 | Written by Paul Carpenter, PC Services 5 | Created September 2014 6 | Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management 7 | January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management 8 | March 2020 - Paul Carpenter - add Spanish and Italian Mappings 9 | April 2020 - Paul Carpenter - Correct _KeyMaps definition error in last version 10 | 11 | PRIVATE to library data and key mapping tables 12 | 13 | This library REQUIRES PS2KeyAdvanced and PS2KeyMap.h as the codes used to 14 | remap to ASCII/UTF-8 are specific to that library to match ALL keys on a keyboard 15 | 16 | To create your own map to ADD to this library see the readme.txt file in 17 | the library directory 18 | 19 | See PS2KeyAvanced.h for returned definitions of Keys and accessible 20 | definitions 21 | 22 | This library is free software; you can redistribute it and/or 23 | modify it under the terms of the GNU Lesser General Public 24 | License as published by the Free Software Foundation; either 25 | version 2.1 of the License, or (at your option) any later version. 26 | 27 | This library is distributed in the hope that it will be useful, 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 30 | Lesser General Public License for more details. 31 | 32 | You should have received a copy of the GNU Lesser General Public 33 | License along with this library; if not, write to the Free Software 34 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 35 | */ 36 | #ifndef PS2KeyData_h 37 | #define PS2KeyData_h 38 | 39 | /* Standard ASCII/UTF-8 control Characters */ 40 | #define PS2_BACKSPACE 0x08 41 | #define PS2_TAB 0x09 42 | #define PS2_ENTER 0x0D 43 | #define PS2_ESC 0x1B 44 | #define PS2_DELETE 0x7F 45 | #define PS2_SPACE 0x20 46 | 47 | 48 | /* Standard ASCII control characters array */ 49 | /* in order of PS2_KEY_* values order is important */ 50 | #if defined(PS2_REQUIRES_PROGMEM) 51 | const uint8_t PROGMEM _control_codes[] = { 52 | #else 53 | const uint8_t _control_codes[] = { 54 | #endif 55 | PS2_DELETE, PS2_ESC, PS2_BACKSPACE, 56 | PS2_TAB, PS2_ENTER, PS2_SPACE 57 | }; 58 | 59 | // convert codes based on SHIFT and not SHIFT only for base US-ASCII 60 | #if defined(PS2_REQUIRES_PROGMEM) 61 | const uint16_t PROGMEM _US_ASCII[][ 2 ] = { 62 | #else 63 | const uint16_t _US_ASCII[][ 2 ] = { 64 | #endif 65 | { PS2_SHIFT + PS2_KEY_1, '!' }, 66 | { PS2_SHIFT + PS2_KEY_2, '@' }, 67 | { PS2_SHIFT + PS2_KEY_3, '#' }, 68 | { PS2_SHIFT + PS2_KEY_4, '$' }, 69 | { PS2_SHIFT + PS2_KEY_5, '%' }, 70 | { PS2_SHIFT + PS2_KEY_6, '^' }, 71 | { PS2_SHIFT + PS2_KEY_7, '&' }, 72 | { PS2_SHIFT + PS2_KEY_8, '*' }, 73 | { PS2_SHIFT + PS2_KEY_9, '(' }, 74 | { PS2_SHIFT + PS2_KEY_0, ')' }, 75 | { PS2_KEY_KP_DOT, '.' }, 76 | { PS2_KEY_KP_ENTER, PS2_ENTER }, 77 | { PS2_KEY_KP_PLUS, '+' }, 78 | { PS2_KEY_KP_MINUS, '-' }, 79 | { PS2_KEY_KP_TIMES, '*' }, 80 | { PS2_KEY_KP_DIV, '/' }, 81 | { PS2_KEY_KP_COMMA, ',' }, 82 | { PS2_KEY_KP_EQUAL, '=' }, 83 | { PS2_KEY_APOS, '\'' }, 84 | { PS2_SHIFT + PS2_KEY_APOS, '"' }, 85 | { PS2_KEY_COMMA, ',' }, 86 | { PS2_SHIFT + PS2_KEY_COMMA, '<' }, 87 | { PS2_KEY_MINUS, '-' }, 88 | { PS2_SHIFT + PS2_KEY_MINUS, '_' }, 89 | { PS2_KEY_DOT, '.' }, 90 | { PS2_SHIFT + PS2_KEY_DOT, '>' }, 91 | { PS2_KEY_DIV, '/' }, 92 | { PS2_SHIFT + PS2_KEY_DIV, '?' }, 93 | { PS2_KEY_SINGLE, '`' }, 94 | { PS2_SHIFT + PS2_KEY_SINGLE, '~' }, 95 | { PS2_KEY_SEMI, ';' }, 96 | { PS2_SHIFT + PS2_KEY_SEMI, ':' }, 97 | { PS2_KEY_BACK, '\\' }, 98 | { PS2_SHIFT + PS2_KEY_BACK, '|' }, 99 | { PS2_KEY_OPEN_SQ, '[' }, 100 | { PS2_SHIFT + PS2_KEY_OPEN_SQ, '{' }, 101 | { PS2_KEY_CLOSE_SQ, ']' }, 102 | { PS2_SHIFT + PS2_KEY_CLOSE_SQ, '}' }, 103 | { PS2_KEY_EQUAL, '=' }, 104 | { PS2_SHIFT + PS2_KEY_EQUAL, '+' } 105 | }; 106 | 107 | #if defined(PS2_REQUIRES_PROGMEM) 108 | const uint16_t PROGMEM _UKmap[][ 2 ] = { 109 | #else 110 | const uint16_t _UKmap[][ 2 ] = { 111 | #endif 112 | { PS2_SHIFT + '@', '"' }, 113 | { PS2_SHIFT + '"', '@' }, 114 | { PS2_ALT_GR + '`', PS2_BROKEN_BAR }, 115 | { PS2_SHIFT + '`', PS2_NOT_SIGN }, 116 | { PS2_SHIFT + '#', PS2_POUND_SIGN }, 117 | { '\\', '#' }, 118 | { PS2_SHIFT + '|', '~' }, 119 | { PS2_KEY_EUROPE2, '\\' }, 120 | { PS2_SHIFT + PS2_KEY_EUROPE2, '|' }, 121 | }; 122 | #ifdef FRENCH 123 | #if defined(PS2_REQUIRES_PROGMEM) 124 | const uint16_t PROGMEM _FRmap[][ 2 ] = { 125 | #else 126 | const uint16_t _FRmap[][ 2 ] = { 127 | #endif 128 | { '`', PS2_SUPERSCRIPT_TWO }, 129 | { PS2_SHIFT + '~', PS2_SUPERSCRIPT_TWO }, 130 | { 'q', 'a' }, 131 | { 'Q', 'A' }, 132 | { '1', '&' }, 133 | { PS2_SHIFT + '!', '1' }, 134 | { PS2_ALT_GR + '1', 0 }, 135 | { PS2_ALT_GR + PS2_SHIFT + '!', 0 }, 136 | { 'z', 'w' }, 137 | { 'Z', 'W' }, 138 | { 'a', 'q' }, 139 | { 'A', 'Q' }, 140 | { 'w', 'z' }, 141 | { 'W', 'Z' }, 142 | { PS2_ALT_GR + '2', '~' }, 143 | { PS2_SHIFT + PS2_ALT_GR + '@', '~' }, 144 | { '2', PS2_e_ACUTE }, 145 | { PS2_SHIFT + '@', '2' }, 146 | { PS2_ALT_GR + '3', PS2_CENT_SIGN }, 147 | { PS2_SHIFT + PS2_ALT_GR + '#', PS2_CENT_SIGN }, 148 | { '3', '"' }, 149 | { PS2_SHIFT + '#', '3' }, 150 | { PS2_ALT_GR + '4', '{' }, 151 | { PS2_SHIFT + PS2_ALT_GR + '$', '{' }, 152 | { '4', '\'' }, 153 | { PS2_SHIFT + '$', '4' }, 154 | { PS2_ALT_GR + '5', '[' }, 155 | { PS2_SHIFT + PS2_ALT_GR + '%', '[' }, 156 | { '5', '(' }, 157 | { PS2_SHIFT + '%', '5' }, 158 | { PS2_ALT_GR + '6', '|' }, 159 | { PS2_SHIFT + PS2_ALT_GR + '^', '|' }, 160 | { '6', '-' }, 161 | { PS2_SHIFT + '^', '6' }, 162 | { 'm', ',' }, 163 | { 'M', '?' }, 164 | { PS2_ALT_GR + '7', '`' }, 165 | { PS2_SHIFT + PS2_ALT_GR + '&', '`' }, 166 | { '7', PS2_e_GRAVE }, 167 | { PS2_SHIFT + '&', '7' }, 168 | { PS2_ALT_GR + '8', '\\' }, 169 | { PS2_SHIFT + PS2_ALT_GR + '*', '\\' }, 170 | { '8', '_' }, 171 | { PS2_SHIFT + '*', '8' }, 172 | { ',', ';' }, 173 | { PS2_SHIFT + '<', '.' }, 174 | { PS2_ALT_GR + '9', '^' }, 175 | { PS2_SHIFT + PS2_ALT_GR + '(', '^' }, 176 | { '9', PS2_c_CEDILLA }, 177 | { PS2_SHIFT + '(', '9' }, 178 | { PS2_ALT_GR + '0', '@' }, 179 | { PS2_ALT_GR + ')', '@' }, 180 | { '0', PS2_a_GRAVE }, 181 | { PS2_SHIFT + ')', '0' }, 182 | { '.', ':' }, 183 | { PS2_SHIFT + '>', '/' }, 184 | { '/', '!' }, 185 | { PS2_SHIFT + '?', PS2_SECTION_SIGN }, 186 | { ';', 'm' }, 187 | { PS2_SHIFT + ':', 'M' }, 188 | { PS2_ALT_GR + '-', ']' }, 189 | { PS2_SHIFT + PS2_ALT_GR + '_', ']' }, 190 | { '-', ')' }, 191 | { PS2_SHIFT + '_', PS2_DEGREE_SIGN }, 192 | { '\'', PS2_u_GRAVE }, 193 | { PS2_SHIFT + '"', '%' }, 194 | { PS2_ALT_GR + '\'', 0 }, 195 | { PS2_SHIFT + PS2_ALT_GR + '"', 0 }, 196 | { '[', '^' }, 197 | { PS2_SHIFT + '{', PS2_DIAERESIS }, 198 | { PS2_ALT_GR + '=', '}' }, 199 | { PS2_SHIFT + PS2_ALT_GR + '+', '}' }, 200 | { PS2_ALT_GR + ']', PS2_CURRENCY_SIGN }, 201 | { PS2_SHIFT + PS2_ALT_GR + '}', 0 }, 202 | { ']', '$' }, 203 | { PS2_SHIFT + '}', PS2_POUND_SIGN }, 204 | { '\\', '*' }, 205 | { PS2_SHIFT + '|', PS2_MICRO_SIGN }, 206 | { PS2_SHIFT + PS2_ALT_GR +'|', 0 }, 207 | { PS2_ALT_GR +'\\', 0 }, 208 | { PS2_KEY_EUROPE2 + PS2_SHIFT + PS2_ALT_GR, '|' }, 209 | { PS2_KEY_EUROPE2 + PS2_ALT_GR, '|' }, 210 | { PS2_SHIFT + PS2_KEY_EUROPE2, '>' }, 211 | { PS2_KEY_EUROPE2, '<' } 212 | }; 213 | #endif 214 | #ifdef GERMAN 215 | #if defined(PS2_REQUIRES_PROGMEM) 216 | const uint16_t PROGMEM _DEmap[][ 2 ] = { 217 | #else 218 | const uint16_t _DEmap[][ 2 ] = { 219 | #endif 220 | { '`', '^' }, 221 | { PS2_SHIFT + '~', PS2_DEGREE_SIGN }, 222 | { PS2_ALT_GR + 'q', '@' }, 223 | { PS2_ALT_GR + 'Q', '@' }, 224 | { 'y', 'z' }, 225 | { 'Y', 'Z' }, 226 | { PS2_ALT_GR + '2', PS2_SUPERSCRIPT_TWO }, 227 | { PS2_SHIFT + PS2_ALT_GR + '@', PS2_SUPERSCRIPT_TWO }, 228 | { PS2_SHIFT + '@', '"' }, 229 | { PS2_ALT_GR + 'e', PS2_CURRENCY_SIGN }, 230 | { PS2_ALT_GR + 'E', PS2_CURRENCY_SIGN }, 231 | { PS2_ALT_GR + '3', PS2_SUPERSCRIPT_THREE }, 232 | { PS2_SHIFT + PS2_ALT_GR + '#', PS2_SUPERSCRIPT_THREE }, 233 | { PS2_SHIFT + '#', PS2_SECTION_SIGN }, 234 | { 'z', 'y' }, 235 | { 'Z', 'Y' }, 236 | { PS2_SHIFT + '^', '&' }, 237 | { PS2_ALT_GR + 'm', PS2_MICRO_SIGN }, 238 | { PS2_ALT_GR + 'M', PS2_MICRO_SIGN }, 239 | { PS2_SHIFT + '&', '/' }, 240 | { PS2_ALT_GR + '7', '{' }, 241 | { PS2_SHIFT + PS2_ALT_GR + '&', '{' }, 242 | { PS2_SHIFT + '*', '(' }, 243 | { PS2_ALT_GR + '8', '[' }, 244 | { PS2_SHIFT + PS2_ALT_GR + '*', '[' }, 245 | { PS2_SHIFT + '<', ';' }, 246 | { PS2_SHIFT + ')', '=' }, 247 | { PS2_ALT_GR + '0', '}' }, 248 | { PS2_SHIFT + PS2_ALT_GR + ')', '}' }, 249 | { PS2_SHIFT + '(', ')' }, 250 | { PS2_ALT_GR + '9', ']' }, 251 | { PS2_SHIFT + PS2_ALT_GR + '(', ']' }, 252 | { PS2_SHIFT + '>', ':' }, 253 | { ';', PS2_o_DIAERESIS }, 254 | { PS2_SHIFT + ':', PS2_O_DIAERESIS }, 255 | { PS2_ALT_GR + '-', '\\' }, 256 | { PS2_SHIFT + PS2_ALT_GR + '_', '\\' }, 257 | { '-', PS2_SHARP_S }, 258 | { PS2_SHIFT + '_', '?' }, 259 | { '\'', PS2_a_DIAERESIS }, 260 | { PS2_SHIFT + '"', PS2_A_DIAERESIS }, 261 | { '[', PS2_u_DIAERESIS }, 262 | { PS2_SHIFT + '{', PS2_U_DIAERESIS }, 263 | { '=', '\'' }, 264 | { PS2_SHIFT + '+', '`' }, 265 | { ']' + PS2_ALT_GR, '~' }, 266 | { PS2_SHIFT + '}' + PS2_ALT_GR, '~' }, 267 | { ']', '+' }, 268 | { PS2_SHIFT + '}', '*' }, 269 | { '\\', '#' }, 270 | { PS2_SHIFT + '|', '\'' }, 271 | { PS2_KEY_EUROPE2 + PS2_SHIFT + PS2_ALT_GR, '|' }, 272 | { PS2_KEY_EUROPE2 + PS2_ALT_GR, '|' }, 273 | { PS2_SHIFT + PS2_KEY_EUROPE2, '>' }, 274 | { PS2_KEY_EUROPE2, '<' } 275 | }; 276 | #endif 277 | #ifdef SPANISH 278 | #if defined(PS2_REQUIRES_PROGMEM) 279 | const uint16_t PROGMEM _ESmap[][ 2 ] = { 280 | #else 281 | const uint16_t _ESmap[][ 2 ] = { 282 | #endif 283 | { PS2_KEY_SINGLE, PS2_MASCULINE_ORDINAL }, 284 | { PS2_SHIFT + PS2_KEY_SINGLE, PS2_FEMININE_ORDINAL }, 285 | { PS2_KEY_SINGLE + PS2_ALT_GR, '\\' }, 286 | { '1' + PS2_ALT_GR, '|' }, 287 | { PS2_SHIFT + '@', '"' }, 288 | { '2' + PS2_ALT_GR, '@' }, 289 | { PS2_SHIFT + '#', PS2_MIDDLE_DOT }, 290 | { '3' + PS2_ALT_GR, '#' }, 291 | { '4' + PS2_ALT_GR, '~' }, 292 | { PS2_SHIFT + '^', '&' }, 293 | { '6' + PS2_ALT_GR, PS2_NOT_SIGN }, 294 | { PS2_SHIFT + '&', '/' }, 295 | { PS2_SHIFT + '*', '(' }, 296 | { PS2_SHIFT + '(', ')' }, 297 | { PS2_SHIFT + ')', '=' }, 298 | { '-', '\'' }, 299 | { PS2_SHIFT + '_', '?' }, 300 | { '=', PS2_INVERTED_EXCLAMATION }, 301 | { PS2_SHIFT + '+', PS2_INVERTED_QUESTION_MARK }, 302 | { '[', '`' }, 303 | { PS2_SHIFT + '{', '^' }, 304 | { '[' + PS2_ALT_GR, '[' }, 305 | { ']', '+' }, 306 | { PS2_SHIFT + '}', '*' }, 307 | { ']' + PS2_ALT_GR, ']' }, 308 | { ';', PS2_n_TILDE }, 309 | { PS2_SHIFT + ':', PS2_N_TILDE }, 310 | { '\'', PS2_ACUTE_ACCENT }, 311 | { PS2_SHIFT + '"', PS2_DIAERESIS }, 312 | { '\'' + PS2_ALT_GR, '{' }, 313 | { '\\', PS2_c_CEDILLA }, 314 | { PS2_SHIFT + '|', PS2_C_CEDILLA }, 315 | { '\\' + PS2_ALT_GR, '}' }, 316 | { PS2_SHIFT + PS2_KEY_EUROPE2, '>' }, 317 | { PS2_KEY_EUROPE2, '<' }, 318 | { PS2_SHIFT + '<', ';' }, 319 | { PS2_SHIFT + '>', ':' }, 320 | { PS2_KEY_DIV, '-' }, 321 | { PS2_SHIFT + PS2_KEY_DIV, '+' } 322 | }; 323 | #endif 324 | #ifdef ITALIAN 325 | #if defined(PS2_REQUIRES_PROGMEM) 326 | const uint16_t PROGMEM _ITmap[][ 2 ] = { 327 | #else 328 | const uint16_t _ITmap[][ 2 ] = { 329 | #endif 330 | { PS2_KEY_SINGLE, '\\' }, 331 | { PS2_SHIFT + PS2_KEY_SINGLE, '|' }, 332 | { '@', '"' }, 333 | { PS2_SHIFT + '#', PS2_POUND_SIGN }, 334 | { '3' + PS2_ALT_GR, '#' }, 335 | { PS2_SHIFT + '^', '&' }, 336 | { PS2_SHIFT + '&', '/' }, 337 | { '7' + PS2_ALT_GR, '{' }, 338 | { PS2_SHIFT + '*', '(' }, 339 | { '8' + PS2_ALT_GR, '[' }, 340 | { PS2_SHIFT + '(', ')' }, 341 | { '9' + PS2_ALT_GR, ']' }, 342 | { PS2_SHIFT + ')', '=' }, 343 | { '0' + PS2_ALT_GR, '}' }, 344 | { '-', '\'' }, 345 | { PS2_SHIFT + '_', '?' }, 346 | { '=', PS2_i_GRAVE }, 347 | { PS2_SHIFT + '+', '^' }, 348 | { 'q' + PS2_ALT_GR, '@' }, 349 | { '[', PS2_e_GRAVE }, 350 | { PS2_SHIFT + '{', PS2_e_ACUTE }, 351 | { ']', '+' }, 352 | { PS2_SHIFT + '}', '*' }, 353 | { ']' + PS2_ALT_GR, '~' }, 354 | { ';', PS2_o_GRAVE }, 355 | { PS2_SHIFT + ':', PS2_c_CEDILLA }, 356 | { '\'', PS2_a_GRAVE }, 357 | { PS2_SHIFT + '"', PS2_DEGREE_SIGN }, 358 | { '\\', PS2_u_GRAVE }, 359 | { PS2_SHIFT + '|', PS2_SECTION_SIGN }, 360 | { PS2_SHIFT + PS2_KEY_EUROPE2, '>' }, 361 | { PS2_KEY_EUROPE2, '<' }, 362 | { PS2_SHIFT + '<', ';' }, 363 | { PS2_SHIFT + '>', ':' }, 364 | { PS2_KEY_DIV, '-' }, 365 | { PS2_SHIFT + PS2_KEY_DIV, '+' } 366 | }; 367 | #endif 368 | #ifdef SPECIAL 369 | #if defined(PS2_REQUIRES_PROGMEM) 370 | const uint16_t PROGMEM _SpecialMap[][ 2 ] = { 371 | #else 372 | const uint16_t _SpecialMap[][ 2 ] = { 373 | #endif 374 | // Insert your Special mapping DIFFERENCES from US-ASCII here 375 | }; 376 | #endif 377 | 378 | // The following structures define the key maps available 379 | typedef struct { 380 | char name[ 3 ]; // 2 Character ISO country code 381 | uint8_t size; // Number of entries in map array 382 | uint16_t *map; // Map array pointer 383 | } PS2Advmap; 384 | 385 | // Actual map structure array ( 2 entries for GB and UK for same map 386 | // Because many people don't know ISO code for UK is GB ) 387 | const PS2Advmap _KeyMaps[ ] = { 388 | { "US", sizeof( _US_ASCII ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_US_ASCII }, 389 | #ifdef FRENCH 390 | { "FR", sizeof( _FRmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_FRmap }, 391 | #endif 392 | #ifdef GERMAN 393 | { "DE", sizeof( _DEmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_DEmap }, 394 | #endif 395 | #ifdef SPANISH 396 | { "ES", sizeof( _ESmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_ESmap }, 397 | #endif 398 | #ifdef ITALIAN 399 | { "IT", sizeof( _ITmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_ITmap }, 400 | #endif 401 | #ifdef SPECIAL 402 | { "--", sizeof( _SpecialMap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t* )_SpecialMap }, 403 | #endif 404 | { "UK", sizeof( _UKmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_UKmap }, 405 | { "GB", sizeof( _UKmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_UKmap } 406 | }; 407 | #endif 408 | -------------------------------------------------------------------------------- /src/PS2KeyMap.cpp: -------------------------------------------------------------------------------- 1 | /* Version V1.0.5 2 | PS2KeyMap.cpp - PS2KeyMap library 3 | Copyright (c) 2007 Free Software Foundation. All right reserved. 4 | Written by Paul Carpenter, PC Services 5 | Created September 2014 6 | Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management 7 | January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management 8 | March 2020 - Paul Carpenter - add Spanish and Italian Mappings 9 | 10 | IMPORTANT WARNING 11 | If using a DUE or similar board with 3V3 I/O you MUST put a level translator 12 | like a Texas Instruments TXS0102 or FET circuit as the signals are 13 | Bi-directional (signals transmitted from both ends on same wire). 14 | 15 | Failure to do so may damage your Arduino Due or similar board. 16 | 17 | Test History 18 | September 2014 Uno and Mega 2560 September 2014 using Arduino V1.6.0 19 | January 2016 Uno, Mega 2560 and Due using Arduino 1.6.7 and Due Board 20 | Manager V1.6.6 21 | 22 | This is for a LATIN style keyboard. Currently Supports 23 | US - Default 24 | UK - By selecting with string "UK" or "GB" 25 | DE - German if define GERMAN exists 26 | FR - French if define FRENCH exists 27 | ES - Spanish if define SPANISH exists 28 | IT - Italian if define ITALIAN exists 29 | -- Special if you have created your own mapping see PS2KeyMap.h 30 | 31 | US and UK mappings are base layouts always compiled. All mappings are done 32 | based on US mapping with CHANGE information to reduce storage space. 33 | 34 | To add other mappings 35 | 36 | Works with PS2KeyAdvanced library ONLY as this is an extension of that 37 | library. 38 | 39 | REQUIRES PS2KeyAdvanced library BEFORE THIS ONE 40 | 41 | To reduce flash memory footprint comment out any of the following in 42 | PSKeyMap.h and recompile 43 | 44 | // Uncomment any of following defines to include those mappings 45 | // or comment to exclude 46 | //#define GERMAN 47 | //#define FRENCH 48 | //#define SPANISH 49 | //#define ITALIAN 50 | //#define SPECIAL 51 | 52 | Library converts key codes from PS2KeyAdvanced to enable full ASCCII/UTF-8 53 | codes depending on language of keyboard and all the modifier keys or any 54 | combination of them e.g. 55 | SHIFT 56 | CTRL 57 | ALT 58 | ALT GR (Right ALT) 59 | GUI (Windows key) 60 | 61 | Remap functions convert to USASCII and US keyboard first, then if an 62 | additional map is selected, scans that table for the few keys that are 63 | different. Making additional keyboard mappings easier, as well as 64 | enabling special key combinations to produce special codes. Also you 65 | can ignore key combinations. 66 | 67 | For example you could specify that CTRL + ENTER key produces the linefeed 68 | code, by adding one entry in a mapping table. 69 | 70 | Allows tables for any keyboard layout and special cases to be added 71 | Returns either uint8_t or uint16_t depending on which function is used 72 | 73 | When returning a uint8_t (byte) the code ranges are 74 | 0 invalid/error 75 | 1-1F ASCII Control Codes (BS, TAB, ESC, ENTER, SPACE) 76 | 20-7F ASCII Printable characters and DEL 77 | 80-9F UTF-8 Control codes (none in base library) 78 | A0-FF UTF-8 1 byte printable characters (See PS2KeyMap.h) 79 | 80 | When return an uint16_t containing 81 | Make/Break status 82 | Caps status 83 | Shift, CTRL, ALT, ALT GR, GUI keys 84 | Flag for function key not a displayable/printable character 85 | 8 bit key code 86 | 87 | Top Byte is 8 bits denoting as follows with defines for bit code 88 | (see PS2KeyAdvanced.h for definitions) 89 | 90 | Define name bit description 91 | PS2_BREAK 15 1 = Break key code 92 | (MSB) 0 = Make Key code 93 | PS2_SHIFT 14 1 = Shift key pressed as well (either side) 94 | 0 = NO shift key 95 | PS2_CTRL 13 1 = Ctrl key pressed as well (either side) 96 | 0 = NO Ctrl key 97 | PS2_CAPS 12 1 = Caps Lock ON 98 | 0 = Caps lock OFF 99 | PS2_ALT 11 1 = Left Alt key pressed as well 100 | 0 = NO Left Alt key 101 | PS2_ALT_GR 10 1 = Right Alt (Alt GR) key pressed as well 102 | 0 = NO Right Alt key 103 | PS2_GUI 9 1 = GUI key pressed as well (either) 104 | 0 = NO GUI key 105 | PS2_FUNCTION 8 1 = FUNCTION key non-printable character (plus space, tab, enter) 106 | 0 = standard character key 107 | 108 | Code Ranges (bottom byte of uint16_t) 109 | When bit 8 = 0 110 | 0 invalid/error 111 | 1-1F ASCII Control Codes (BS, TAB, ESC, ENTER, SPACE) 112 | 20-7F ASCII Printable characters and DEL 113 | 80-9F UTF-8 Control codes (none in base library) 114 | A0-FF UTF-8 1 byte printable characters (See PS2KeyMap.h) 115 | 116 | When bit 8 = 1 Function keys see PS2KeyAdvanced for coding details) 117 | 0 invalid/error 118 | 1-19 Functions PGUP PGDN etc.. 119 | 1A-60 NOT RETURNED 120 | 61-9F Function keys and other special keys (plus F2 and F1) 121 | 61-78 F1 to F24 122 | 79-8A Multimedia 123 | 8B-8D ACPI power 124 | 90-9F Special multilingual 125 | A0-FF Keyboard communications commands (note F2 and F1 are special 126 | codes for special multi-lingual keyboards) 127 | 128 | Error Codes 129 | Most functions return 0 or 0xFFFF as error, other codes to note and 130 | handle appropriately for bottom byte - 131 | 0xAA keyboard has reset and passed power up tests 132 | will happen if keyboard plugged in after code start 133 | 0xFC Keyboard General error or power up fail 134 | 135 | Functions contained are 136 | selectMap() Pass in 2 digit ISO country code to select map if loaded 137 | returns 0 for done or 1 for not found. 138 | 139 | remapKey() Pass in unsigned int returned from PS2KeyAdvanced 140 | Returns 0 for error 141 | unsigned int as described above 142 | remapKeyByte() Returns uint8_t version of remapKey ONLY for standard ASCII/UTF-8 codes 143 | Invalid codes returned as 0 144 | 145 | To create your own map to ADD to this library see the readme.txt file in 146 | the library directory 147 | 148 | See PS2KeyAvanced.h for returned definitions of Keys and accessible 149 | definitions 150 | 151 | This library is free software; you can redistribute it and/or 152 | modify it under the terms of the GNU Lesser General Public 153 | License as published by the Free Software Foundation; either 154 | version 2.1 of the License, or (at your option) any later version. 155 | 156 | This library is distributed in the hope that it will be useful, 157 | but WITHOUT ANY WARRANTY; without even the implied warranty of 158 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 159 | Lesser General Public License for more details. 160 | 161 | You should have received a copy of the GNU Lesser General Public 162 | License along with this library; if not, write to the Free Software 163 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 164 | */ 165 | 166 | /* To Add a key mapping for one of the below add the line to YOUR CODE 167 | BEFORE including PS2KeyMap.h see examples for this library 168 | 169 | #define FRENCH 170 | #define GERMAN 171 | 172 | Add following line when you add you own map see #ifdef SPECIAL sections 173 | Selected by country code of "--" when created and enabled 174 | 175 | #define SPECIAL 176 | */ 177 | 178 | /*------------------ Code starts here -------------------------*/ 179 | #include 180 | // Internal headers for library defines/codes/etc 181 | #include 182 | #include "PS2KeyMap.h" 183 | #include "PS2KeyData.h" 184 | 185 | uint8_t _selected_map; 186 | 187 | // Private country code strings 188 | const char *_USStr[] = { "US" }; 189 | 190 | 191 | /* Common function to scan a Look up table table and 192 | return a value or 0 for not found 193 | 194 | Checks using default mask of keycode plus ALT_GR and SHIFT 195 | To add in match other modifiers set mask to combination of 196 | PS2_CTRL match either Control key as well 197 | PS2_ALT match left ALT as well 198 | PS2_GUI match either GUI key as well 199 | 200 | Assumes map table has 2 dimensions of type prog_uint16_t (in Flash memory) 201 | i.e. an array like test[ ][ 2 ] 202 | First entry (test[][ 0 ]) is item to match 203 | Second entry (test[][ 1 ]) is item to return 204 | 205 | Parameters are 206 | data unsigned int 16 from PS2KeyAdvanced library 207 | index index of mapping table to use 208 | */ 209 | uint16_t scan_map( uint16_t data, uint8_t index ) 210 | { 211 | uint16_t idx, result, size; 212 | uint16_t *maparray; 213 | 214 | // Convert entries count to number of ints 215 | size = ( _KeyMaps[ index ].size ) << 1; 216 | maparray = ( uint16_t *)_KeyMaps[ index ].map; 217 | // Leave only required bits for checking against 218 | result = data & ( PS2_ALT_GR + PS2_SHIFT + 0xFF ); 219 | 220 | // scan Lookup Table (array) jumping 2 integers at a time 221 | for( idx = 0; idx < size; idx += 2 ) 222 | #if defined(PS2_REQUIRES_PROGMEM) 223 | if( result == pgm_read_word( maparray + idx ) ) 224 | { // second integer is the replacement value 225 | result = pgm_read_word( maparray + idx + 1 ); 226 | #else 227 | if( result == *( maparray + idx ) ) 228 | { // second integer is the replacement value 229 | result = *( maparray + idx + 1 ); 230 | #endif 231 | data &= ~0xFF; // clear old bits retaining CTRL etc 232 | data |= result; // Make new code 233 | break; 234 | } 235 | return data; 236 | } 237 | 238 | 239 | /* 240 | Pass in 2 character string for the ISO 2 letter country code in use 241 | For UK "UK" or "GB" are valid 242 | "US" is built-in default 243 | 244 | Returns 1 for done 245 | or 0 for not found. 246 | */ 247 | uint8_t PS2KeyMap::selectMap( char *ISO = (char *)_USStr ) 248 | { 249 | uint8_t outer, idx, end; 250 | 251 | end = sizeof( _KeyMaps ) / sizeof( PS2Advmap ); 252 | for( outer = 0; outer < end; outer++ ) 253 | { 254 | for( idx = 0; idx < 3; idx++ ) 255 | if( _KeyMaps[ outer ].name[ idx ] != ISO[ idx ] ) 256 | break; // No match 257 | if( idx == 3 ) // done whole match 258 | break; 259 | } 260 | if( outer < end ) // found entry 261 | { 262 | _selected_map = outer; // Copy over to selected 263 | return 1; 264 | } 265 | return 0; 266 | } 267 | 268 | 269 | /* 270 | Return selected map as a string pointer (2 chars and terminator) 271 | */ 272 | const char *PS2KeyMap::getMap( void ) 273 | { 274 | return ( _KeyMaps[ _selected_map ].name ); 275 | } 276 | 277 | 278 | /* Pass in unsigned int returned from PS2KeyAdvanced 279 | Returns 0 for error 280 | uint16_t for valid code 281 | Converts code to US-ASCII first (honouring SHIFT ONLY) 282 | then if additional map defined scan and remap those keys 283 | */ 284 | uint16_t PS2KeyMap::remapKey( uint16_t code ) 285 | { 286 | uint8_t temp; 287 | 288 | // for bottom byte checks 289 | temp = code & 0xFF; 290 | 291 | // Sort standard ASCII control codes 292 | if( temp >= PS2_KEY_DELETE && temp <= PS2_KEY_SPACE ) 293 | { 294 | code &= ~( PS2_FUNCTION + 0xFF ); // convert to ASCII code not function 295 | #if defined(PS2_REQUIRES_PROGMEM) 296 | temp = pgm_read_byte( &_control_codes[ temp - PS2_KEY_DELETE ] ); 297 | #else 298 | temp = _control_codes[ temp - PS2_KEY_DELETE ]; 299 | #endif 300 | code |= temp; 301 | } 302 | else 303 | // Remainder convert printable to US-ASCII 304 | if( !( code & PS2_FUNCTION ) ) 305 | { // Some codes are straight return values We deal with ones that need work 306 | // When A-Z not shifted create lower case a - z 307 | if( temp >= PS2_KEY_A && temp <= PS2_KEY_Z ) 308 | { 309 | // Deal with Caps Lock by inverting PS2_SHIFT and remove caps lock 310 | if( ( code & PS2_CAPS ) ) 311 | code ^= ( PS2_SHIFT + PS2_CAPS ); 312 | if( !( code & PS2_SHIFT ) ) 313 | code |= 0x20; 314 | // When shifted pass through code as received as the codes are A - Z 315 | else 316 | code &= ~PS2_SHIFT; 317 | } 318 | else 319 | // Convert KeyPad 0-9 to number codes 320 | if( temp >= PS2_KEY_KP0 && temp <= PS2_KEY_KP9 ) 321 | { 322 | code |= 0x10; 323 | code &= ~( PS2_SHIFT + PS2_ALT + PS2_ALT_GR + PS2_CTRL + PS2_GUI + PS2_CAPS ); 324 | } 325 | else 326 | { 327 | // Some keys ignore shift, the extra keys on numeric keypad 328 | if( ( temp >= PS2_KEY_KP_DOT && temp <= PS2_KEY_KP_DIV ) 329 | || temp == PS2_KEY_KP_EQUAL || temp == PS2_KEY_KP_COMMA ) 330 | code &= ~PS2_SHIFT; 331 | // Do default US-ASCII mapping of remainders excluding (CTRL, ALT, GUI) 332 | code = (code & PS2_ALT_GR ) + scan_map( code & ~PS2_ALT_GR, 0 ); 333 | } 334 | //Now do remap if necessary for all modifiers 335 | if( code > 0 && _selected_map > 0 ) 336 | code = scan_map( code, _selected_map ); 337 | else // For USASCII ignore extra key in case 338 | if( ( temp == PS2_KEY_EUROPE2 ) ) 339 | code = 0; 340 | code &= ~( PS2_SHIFT + PS2_ALT_GR ); // Now clear shift status 341 | } 342 | else 343 | code = 0; 344 | return code; 345 | } 346 | 347 | 348 | /* 349 | Returns uint8_t version of remapKey ONLY for standard ASCII/UTF-8 codes 350 | Invalid codes returned as 0 351 | Also any key with BREAK condition are returned as 0 352 | */ 353 | uint8_t PS2KeyMap::remapKeyByte( uint16_t code ) 354 | { 355 | uint16_t data; 356 | 357 | // Invalid codes returned as 0 358 | if( code & ( PS2_FUNCTION + PS2_BREAK ) ) 359 | return 0; 360 | data = remapKey( code ); 361 | return ( uint8_t )( data & 0xFF ); 362 | } 363 | 364 | 365 | /* Class constructor 366 | At construction ensure default map selected 367 | */ 368 | PS2KeyMap::PS2KeyMap() 369 | { 370 | _selected_map = 0; 371 | } 372 | -------------------------------------------------------------------------------- /src/PS2KeyMap.h: -------------------------------------------------------------------------------- 1 | /* Version V1.0.5 2 | PS2KeyMap.h - PS2KeyAdvanced library 3 | Copyright (c) 2007 Free Software Foundation. All right reserved. 4 | Written by Paul Carpenter, PC Services 5 | Created September 2014 6 | Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management 7 | January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management 8 | March 2020 - Paul Carpenter - add Spanish and Italian Mappings 9 | 10 | IMPORTANT WARNING 11 | If using a DUE or similar board with 3V3 I/O you MUST put a level translator 12 | like a Texas Instruments TXS0102 or FET circuit as the signals are 13 | Bi-directional (signals transmitted from both ends on same wire). 14 | 15 | Failure to do so may damage your Arduino Due or similar board. 16 | 17 | Test History 18 | September 2014 Uno and Mega 2560 September 2014 using Arduino V1.6.0 19 | January 2016 Uno, Mega 2560 and Due using Arduino 1.6.7 and Due Board 20 | Manager V1.6.6 21 | 22 | Takes output key codes from PS2KeyAdvanced and translates them to ASCII/UTF-8 23 | if valid as these characters, or returns PS2KeyAdvanced codings for function keys 24 | as these do NOT have any standard ASCII/UTF-8 encodings. 25 | 26 | Use defines from here and PS2KeyAdvanced.h to make reference to key codes 27 | 28 | This library REQUIRES PS2KeyAdvanced as the codes used to remap to ASCII/UTF-8 29 | are specific to that library to match ALL keys on a keyboard 30 | 31 | To reduce flash memory footprint comment out any of the following in 32 | PSKeyMap.h and recompile 33 | 34 | // Uncomment any of following defines to include those mappings 35 | // or comment to exclude 36 | //#define GERMAN 37 | //#define FRENCH 38 | //#define SPANISH 39 | //#define ITALIAN 40 | //#define SPECIAL 41 | 42 | The functions in this library takes the unsigned int values produced from 43 | PS2KeyAdvanced and translate them as follows into an unsigned int value 44 | 45 | 0 invalid/error 46 | 1-1F ASCII Control Codes (BS, TAB, ESC, ENTER, SPACE) 47 | 20-7F ASCII Printable characters and DEL 48 | 80-9F UTF-8 Control codes (none in base library) 49 | A0-FF UTF-8 1 byte printable characters (See PS2KeyMap.h) 50 | 51 | All other codes for F1 to F24 (yes there are 24 function key codes) arrow keys page up 52 | page down etc are returned as the same codes as PS2KeyAdvanced uses. 53 | 54 | When return an uint16_t containing 55 | Make/Break status 56 | Caps status 57 | Shift, CTRL, ALT, ALT GR, GUI keys 58 | Flag for function key not a displayable/printable character 59 | 8 bit key code 60 | 61 | Top Byte is 8 bits denoting as follows with defines for bit code 62 | (see PS2KeyAdvanced.h for definitions) 63 | 64 | Define name bit description 65 | PS2_BREAK 15 1 = Break key code 66 | (MSB) 0 = Make Key code 67 | PS2_SHIFT 14 1 = Shift key pressed as well (either side) 68 | 0 = NO shift key 69 | PS2_CTRL 13 1 = Ctrl key pressed as well (either side) 70 | 0 = NO Ctrl key 71 | PS2_CAPS 12 1 = Caps Lock ON 72 | 0 = Caps lock OFF 73 | PS2_ALT 11 1 = Left Alt key pressed as well 74 | 0 = NO Left Alt key 75 | PS2_ALT_GR 10 1 = Right Alt (Alt GR) key pressed as well 76 | 0 = NO Right Alt key 77 | PS2_GUI 9 1 = GUI key pressed as well (either) 78 | 0 = NO GUI key 79 | PS2_FUNCTION 8 1 = FUNCTION key non-printable character (plus space, tab, enter) 80 | 0 = standard character key 81 | 82 | Code Ranges (bottom byte of uint16_t) 83 | When bit 8 = 0 84 | 0 invalid/error 85 | 1-1F ASCII Control Codes (BS, TAB, ESC, ENTER, SPACE) 86 | 20-7F ASCII Printable characters and DEL 87 | 80-9F UTF-8 Control codes (none in base library) 88 | A0-FF UTF-8 1 byte printable characters (See PS2KeyMap.h) 89 | 90 | When bit 8 = 1 Function keys see PS2KeyAdvanced for coding details) 91 | 0 invalid/error 92 | 1-19 Functions PGUP PGDN etc.. 93 | 1A-60 NOT RETURNED 94 | 61-9F Function keys and other special keys (plus F2 and F1) 95 | 61-78 F1 to F24 96 | 79-8A Multimedia 97 | 8B-8D ACPI power 98 | 90-9F Special multilingual 99 | A0-FF Keyboard communications commands (note F2 and F1 are special 100 | codes for special multi-lingual keyboards) 101 | 102 | Error Codes 103 | Most functions return 0 or 0xFFFF as error, other codes to note and 104 | handle appropriately for bottom byte - 105 | 0xAA keyboard has reset and passed power up tests 106 | will happen if keyboard plugged in after code start 107 | 0xFC Keyboard General error or power up fail 108 | 109 | This library is free software; you can redistribute it and/or 110 | modify it under the terms of the GNU Lesser General Public 111 | License as published by the Free Software Foundation; either 112 | version 2.1 of the License, or (at your option) any later version. 113 | 114 | This library is distributed in the hope that it will be useful, 115 | but WITHOUT ANY WARRANTY; without even the implied warranty of 116 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 117 | Lesser General Public License for more details. 118 | 119 | You should have received a copy of the GNU Lesser General Public 120 | License along with this library; if not, write to the Free Software 121 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 122 | */ 123 | 124 | #ifndef PS2KeyMap_h 125 | #define PS2KeyMap_h 126 | 127 | #ifndef PS2KeyAdvanced_h 128 | #error PS2KeyAdvanced library missing 129 | #endif 130 | 131 | // Uncomment any of following defines to include those mappings 132 | // or comment to exclude 133 | #define GERMAN 134 | #define FRENCH 135 | #define SPANISH 136 | #define ITALIAN 137 | //#define SPECIAL 138 | 139 | /* UTF-8 single byte LATIN encodings 140 | 128 to 159 (0x80 to 0x9F) are control characters application generated 141 | 160 to 255 (0xA0 to 0XFF) are used depending on keymap tables 142 | These defines are used to insert them into correct tables */ 143 | 144 | /**************************************************************** 145 | IMPORTANT NOTE EURO currency Symbol is NOT supported in UTF-8 single 146 | byte codings, as EURO symbol came after UTF-8 single byte codings 147 | ****************************************************************/ 148 | #define PS2_NO_BREAK_SPACE 160 // nbsp 149 | #define PS2_INVERTED_EXCLAMATION 161 // ¡ 150 | #define PS2_CENT_SIGN 162 // ¢ 151 | #define PS2_POUND_SIGN 163 // £ 152 | #define PS2_CURRENCY_SIGN 164 // ¤ 153 | #define PS2_YEN_SIGN 165 // ¥ 154 | #define PS2_BROKEN_BAR 166 // ¦ 155 | #define PS2_SECTION_SIGN 167 // § 156 | #define PS2_DIAERESIS 168 // ¨ 157 | #define PS2_COPYRIGHT_SIGN 169 // © 158 | #define PS2_FEMININE_ORDINAL 170 // ª 159 | #define PS2_LEFT_DOUBLE_ANGLE_QUOTE 171 // « 160 | #define PS2_NOT_SIGN 172 // ¬ 161 | #define PS2_HYPHEN 173 162 | #define PS2_REGISTERED_SIGN 174 // ® 163 | #define PS2_MACRON 175 // ¯ 164 | #define PS2_DEGREE_SIGN 176 // ° 165 | #define PS2_PLUS_MINUS_SIGN 177 // ± 166 | #define PS2_SUPERSCRIPT_TWO 178 // ² 167 | #define PS2_SUPERSCRIPT_THREE 179 // ³ 168 | #define PS2_ACUTE_ACCENT 180 // ´ 169 | #define PS2_MICRO_SIGN 181 // µ 170 | #define PS2_PILCROW_SIGN 182 // ¶ 171 | #define PS2_MIDDLE_DOT 183 // · 172 | #define PS2_CEDILLA 184 // ¸ 173 | #define PS2_SUPERSCRIPT_ONE 185 // ¹ 174 | #define PS2_MASCULINE_ORDINAL 186 // º 175 | #define PS2_RIGHT_DOUBLE_ANGLE_QUOTE 187 // » 176 | #define PS2_FRACTION_ONE_QUARTER 188 // ¼ 177 | #define PS2_FRACTION_ONE_HALF 189 // ½ 178 | #define PS2_FRACTION_THREE_QUARTERS 190 // ¾ 179 | #define PS2_INVERTED_QUESTION_MARK 191 // ¿ 180 | #define PS2_A_GRAVE 192 // À 181 | #define PS2_A_ACUTE 193 // Á 182 | #define PS2_A_CIRCUMFLEX 194 // Â 183 | #define PS2_A_TILDE 195 // Ã 184 | #define PS2_A_DIAERESIS 196 // Ä 185 | #define PS2_A_RING_ABOVE 197 // Å 186 | #define PS2_AE 198 // Æ 187 | #define PS2_C_CEDILLA 199 // Ç 188 | #define PS2_E_GRAVE 200 // È 189 | #define PS2_E_ACUTE 201 // É 190 | #define PS2_E_CIRCUMFLEX 202 // Ê 191 | #define PS2_E_DIAERESIS 203 // Ë 192 | #define PS2_I_GRAVE 204 // Ì 193 | #define PS2_I_ACUTE 205 // Í 194 | #define PS2_I_CIRCUMFLEX 206 // Î 195 | #define PS2_I_DIAERESIS 207 // Ï 196 | #define PS2_ETH 208 // Ð 197 | #define PS2_N_TILDE 209 // Ñ 198 | #define PS2_O_GRAVE 210 // Ò 199 | #define PS2_O_ACUTE 211 // Ó 200 | #define PS2_O_CIRCUMFLEX 212 // Ô 201 | #define PS2_O_TILDE 213 // Õ 202 | #define PS2_O_DIAERESIS 214 // Ö 203 | #define PS2_MULTIPLICATION 215 // × 204 | #define PS2_O_STROKE 216 // Ø 205 | #define PS2_U_GRAVE 217 // Ù 206 | #define PS2_U_ACUTE 218 // Ú 207 | #define PS2_U_CIRCUMFLEX 219 // Û 208 | #define PS2_U_DIAERESIS 220 // Ü 209 | #define PS2_Y_ACUTE 221 // Ý 210 | #define PS2_THORN 222 // Þ 211 | #define PS2_SHARP_S 223 // ß 212 | #define PS2_a_GRAVE 224 // à 213 | #define PS2_a_ACUTE 225 // á 214 | #define PS2_a_CIRCUMFLEX 226 // â 215 | #define PS2_a_TILDE 227 // ã 216 | #define PS2_a_DIAERESIS 228 // ä 217 | #define PS2_a_RING_ABOVE 229 // å 218 | #define PS2_ae 230 // æ 219 | #define PS2_c_CEDILLA 231 // ç 220 | #define PS2_e_GRAVE 232 // è 221 | #define PS2_e_ACUTE 233 // é 222 | #define PS2_e_CIRCUMFLEX 234 // ê 223 | #define PS2_e_DIAERESIS 235 // ë 224 | #define PS2_i_GRAVE 236 // ì 225 | #define PS2_i_ACUTE 237 // í 226 | #define PS2_i_CIRCUMFLEX 238 // î 227 | #define PS2_i_DIAERESIS 239 // ï 228 | #define PS2_eth 240 // ð 229 | #define PS2_n_TILDE 241 // ñ 230 | #define PS2_o_GRAVE 242 // ò 231 | #define PS2_o_ACUTE 243 // ó 232 | #define PS2_o_CIRCUMFLEX 244 // ô 233 | #define PS2_o_TILDE 245 // õ 234 | #define PS2_o_DIAERESIS 246 // ö 235 | #define PS2_DIVISION 247 // ÷ 236 | #define PS2_o_STROKE 248 // ø 237 | #define PS2_u_GRAVE 249 // ù 238 | #define PS2_u_ACUTE 250 // ú 239 | #define PS2_u_CIRCUMFLEX 251 // û 240 | #define PS2_u_DIAERESIS 252 // ü 241 | #define PS2_y_ACUTE 253 // ý 242 | #define PS2_thorn 254 // þ 243 | #define PS2_y_DIAERESIS 255 // ÿ 244 | 245 | 246 | /* Public class definition */ 247 | class PS2KeyMap { 248 | public: 249 | /** 250 | * This constructor just sets the default key mapping to US. */ 251 | PS2KeyMap(); 252 | 253 | /** 254 | Pass in 2 character string for the ISO 2 letter country code in use 255 | For UK "UK" or "GB" are valid 256 | "US" is built-in default 257 | Returns 1 for done or 0 for not found. 258 | */ 259 | uint8_t selectMap( char * ); 260 | 261 | /** 262 | Return selected map as a string pointer (2 chars and terminator) */ 263 | const char *getMap( void ); 264 | 265 | /** 266 | Pass in unsigned int returned from PS2KeyAdvanced 267 | Returns 0 for error 268 | uint16_t for valid code 269 | */ 270 | uint16_t remapKey( uint16_t ); 271 | 272 | /** 273 | Returns uint8_t version of remapKey ONLY for standard ASCII/UTF-8 codes 274 | Invalid codes returned as 0 275 | */ 276 | uint8_t remapKeyByte( uint16_t ); 277 | }; 278 | #endif 279 | --------------------------------------------------------------------------------