Arduino PS2 Keyboard-Emulator an C64 DTV

Ich versuche gerade den DTV (C64 DTV – Wikipedia)zu modden. Ich habe ihn bereits mit dem PS2-Mod ausgestattet und kann eine PS2 Tastatur daran benutzen.
Um in den C64.Modus zu kommen, muss man die CTRL-Taste drücken. Dazu will ich einen Arduino benutzen, der sich wie eine PS2-Tastatur verhält und in den ersten paar Sekunden nur den Scan-Code für CTRL sendet. Hierzu greife ich auf die PS2-library zurück: Arduino Playground - Ps2mouse
Dazu hab ich mir ein bißchen code geholt (s.u.)

Das Problem:
Das Gute: er sendet tatsächlich den CTRL-Scan Code an das DTV und es startet im C64-Modus. Aber danach funktioniert nichts mehr wie es soll. Ich sende danach die Codes für die Zahlen 1 und 2. Dadurch ändert sich die Zeichenfarbe beim DTV. Ganz so, als ob immernoch die Commodore-Taste (CTRL) gedrückt wäre. Ist aber nicht, da ich ja den Breakcode sende.
Weiteres Problem: beim ersten Durchlauf (kann ich über die blinkende LED am Arduino feststellen) setzt er die Zeichenfarbe zuerst auf schwarz - Taste 1 und dann auf weiß - Taste 2. Im nächsten Durchgang tut er das aber nicht, sondern behält die Zeichenfarbe weiß bei.

Ich fürchte, irgendwas mit den Breakcodes stimmt nicht, aber die sind formal richtig. Was kann es noch sein.

#include "ps2dev.h" // to emulate a PS/2 device

PS2dev keyboard(3,2); // PS2dev object (2:data, 3:clock)
int enabled = 0; // pseudo variable for state of "keyboard"
int led = 13;

void ack() {
  //acknowledge commands
  while(keyboard.write(0xFA));
}

int keyboardcommand(int command) {
  unsigned char val;
  switch (command) {
  case 0xFF: //reset
    ack();
    //the while loop lets us wait for the host to be ready
    while(keyboard.write(0xAA)!=0);
    break;
  case 0xFE: //resend
    ack();
    break;
  case 0xF6: //set defaults
    //enter stream mode
    ack();
    break;
  case 0xF5: //disable data reporting
    //FM
    enabled = 0;
    ack();
    break;
  case 0xF4: //enable data reporting
    //FM
    enabled = 1;
    ack();
    break;
  case 0xF3: //set typematic rate
    ack();
    keyboard.read(&val); //do nothing with the rate
    ack();
    break;
  case 0xF2: //get device id
    ack();
    keyboard.write(0xAB);
    keyboard.write(0x83);
    break;
  case 0xF0: //set scan code set
    ack();
    keyboard.read(&val); //do nothing with the rate
    ack();
    break;
  case 0xEE: //echo
    //ack();
    keyboard.write(0xEE);
    break;
  case 0xED: //set/reset LEDs
    ack();
    keyboard.read(&val); //do nothing with the rate
    ack();
    break;
  }
}

void printA() {
  unsigned char c;
  //if host device wants to send a command:
  if( (digitalRead(3)==LOW) || (digitalRead(2) == LOW)) {
    while(keyboard.read(&c)) ;
    keyboardcommand(c);
  }
  else{ //send keypresses accordingly using scancodes
  keyboard.write(0x1C); // \
  keyboard.write(0xF0); //  |- send 'a'
  keyboard.write(0x1C); // /
  delay (1000); // wait 1 second  
  }
  
}

void setup() {
  pinMode(led, OUTPUT);
  // send the keyboard start up
  while(keyboard.write(0xAA)!=0);
  delay(10);
}

void loop() {
  unsigned char c;
  for (byte i=0; i<5; i++)
  {
  //if host device wants to send a command:
  if( (digitalRead(3)==LOW) || (digitalRead(2) == LOW)) {
    while(keyboard.read(&c)) ;
    keyboardcommand(c);
  }
  else{ //send keypresses accordingly using scancodes
  // secancodes: http://www.computer-engineering.org/ps2keyboard/scancodes2.html
  keyboard.write(0x14); // \
  keyboard.write(0xF0); //  |- send 'ctrl'
  keyboard.write(0x14); // /
  delay (500);
  }
  }
  
  // um sichtbar zu machen dass jetzt Teil 2 anfängt
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(1000);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(1000);               // wait for a second
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(1000);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(1000);     

           // wait for a second
  
  keyboard.write(0x16); // \
  keyboard.write(0xF0); //  |- send '1'
  keyboard.write(0x16); // /  
  delay (1000); // wait 1 second
  
 
  keyboard.write(0x1e); // \
  keyboard.write(0xF0); //  |- send '2'
  keyboard.write(0x1e); // /  
  delay (1000); // wait 1 second  
  
 // um sichtbar zu machen, dass es jetzt wieder von Vorne los geht
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(500);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(500);               // wait for a second
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(500);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(500); 
}