PaulStoffregen / PS2Keyboard

PS/2 Keyboard Library for Arduino
http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
147 stars 57 forks source link

Problem with ¬ and £ in UK Keyboard. #39

Open matalog opened 1 year ago

matalog commented 1 year ago

Description

If I use PS2Keyboard configured to UK to output bytes, as numbers instead of the acsii characters, the characters ¬ and £ , both accessed with shift key, cause some strange bytes to be returned, instead of the expected 172 and 163 respectively, it will return -62 -84 for ¬ and then -62 -93 for £. I cannot pinpoint what causes this.

EDIT: It has a problem with any of the codes within PS2Keyboard.h that are above 160.

EDIT: If the code processed is over 127, then 2 numbers are returned. I still haven't worked out why. Yes the example you gives does return the required character, but the set is not expandable beyond 128 as is, if the user wants to return a number from the routine. Can you think of why 2 numbers are being returned if the keycode is above 127?

Steps To Reproduce Problem

Use the following code and then SHIFT+3 or SHIFT + ` to reproduce this problem.

Please note that I have changed the pins used to suit my system.

Hardware & Software

Board Arduino Mega 2560 Shields / modules used N/A Arduino IDE version 1.8.13 Teensyduino version (if using Teensy) N/A Version info & package name (from Tools > Boards > Board Manager) 1.8.5 Operating system & version Windows 8.1 Any other software or hardware?

Arduino Sketch

// Change the code below by your sketch (please try to give the smallest code which demonstrates the problem)
#include <Arduino.h>

// libraries: give links/details so anyone can compile your code for the same result

`/*  PS2Keyboard library example

  PS2Keyboard now requries both pins specified for begin()

  keyboard.begin(data_pin, irq_pin);

  Valid irq pins:
     Arduino Uno:  2, 3
     Arduino Due:  All pins, except 13 (LED)
     Arduino Mega: 2, 3, 18, 19, 20, 21
     Teensy 2.0:   All pins, except 13 (LED)
     Teensy 2.0:   5, 6, 7, 8
     Teensy 1.0:   0, 1, 2, 3, 4, 6, 7, 16
     Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
     Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
     Sanguino:     2, 10, 11

  for more information you can read the original wiki in arduino.cc
  at http://www.arduino.cc/playground/Main/PS2Keyboard
  or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html

  Like the Original library and example this is under LGPL license.

  Modified by Cuninganreset@gmail.com on 2010-03-22
  Modified by Paul Stoffregen <paul@pjrc.com> June 2010
*/

#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  3;

PS2Keyboard keyboard;

void setup() {
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
  Serial.begin(9600);
  Serial.println("Keyboard Test:");
}

void loop() {
  if (keyboard.available()) {

    // read the next key
    char c = keyboard.read();
    int h = (int)c;

    // check for some of the special keys
    if (c == PS2_ENTER) {
      Serial.println();
    } else if (c == PS2_TAB) {
      Serial.print("[Tab]");
    } else if (c == PS2_ESC) {
      Serial.print("[ESC]");
    } else if (c == PS2_PAGEDOWN) {
      Serial.print("[PgDn]");
    } else if (c == PS2_PAGEUP) {
      Serial.print("[PgUp]");
    } else if (c == PS2_LEFTARROW) {
      Serial.print("[Left]");
    } else if (c == PS2_RIGHTARROW) {
      Serial.print("[Right]");
    } else if (c == PS2_UPARROW) {
      Serial.print("[Up]");
    } else if (c == PS2_DOWNARROW) {
      Serial.print("[Down]");
    } else if (c == PS2_DELETE) {
      Serial.print("[Del]");
    } else {

      // otherwise, just print all normal characters
      Serial.print(c);
      Serial.print(" ");
      Serial.print(h);
      Serial.print(" ");
    }
  }
}`

Errors or Incorrect Output

If you see any errors or incorrect output, please show it here. Please use copy & paste to give an exact copy of the message. Details matter, so please show (not merely describe) the actual message or error exactly as it appears.

PS2Keyboard.cpp has: Line 411 : 0, PS2_F10, PS2_F8, PS2_F6, PS2_F4, PS2_TAB, 172 /* ¬ */, 0, Line 414: 0, 'C', 'X', 'D', 'E', '$', 163 /* £ */, 0,

Both of these lines have a different method of numbering £ and ¬, I suspect there may have been trouble with them before.