PS/2 Scancodes and the ps2dev library confusion

Hi Everyone,

I am currently trying to emulate a PS/2 keyboard using the ps2dev library from the bottom of the page here Arduino Playground - Ps2mouse

My plan was to use the play/pause etc buttons on an IR remote to make these commands on a PC to control iTunes and VLC.

The problem I am having is understanding these scan codes for the PS/2.
The code I found on the forums(can't find a link right now, will edit if I do) looks like this

void loop() {
  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
  // secancodes: http://www.computer-engineering.org/ps2keyboard/scancodes2.html
  keyboard.write(0x1C); // \
  keyboard.write(0xF0); //  |- send 'a'
  keyboard.write(0x1C); // /
  delay (1000); // wait 1 second
  }
}

I modified it to look like this so I could then select the key to press a play/pause command

//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
    if(keyPressed == 1){
      keyboard.write(0x34); // \
      keyboard.write(0xE0); //  |- send 'play/pause'
      keyboard.write(0x34); // /
      Serial.println(keyPressed);
      keyPressed =0;
    }
  delay (1000); // wait 1 second
  }

The first set of code does a constant pressing of 'a'.
The second set does a constant pressing of 'g' when I press the button on my remote, but doesn't stop. This part kind of makes sense as the code for it is 0x34, but the make/ break code setup confuses me a bit along with getting it to only press once.

Could someone give me a hand with putting the play/pause scancode in code for the Arduino that I could use?

Thanks a lot in advance!

After doing some googling and some more research I think there may simply be a problem with the Arduino not sending the break commands.

keyboard.write(0x34); // \
keyboard.write(0xE0); //  |- send 'g'
keyboard.write(0x34); // /

That code should make a 'g' and then break it, but instead it seems to just make it therefore make it look like I was holding the key down.

as for the play/pause key the code should look like this

keyboard.write(0xE0);
keyboard.write(0x34); // \
keyboard.write(0xE0); //  |- send 'play/pause'
keyboard.write(0xF0);
keyboard.write(0x34); // /

but I can't get that to work either.

Any thoughts?

Does anyone have any ideas?

I have tried nearly every combination of these characters I can think of and can't get the scan codes to 'break'. The computer sees it as a constant keypress like I'm holding down the key.

Anything at this point would be helpful.

Hi step, got same problem a couple months ago. What I did was something like this :

void make_break_kb(byte data)
{
// makes and breaks the key
    keyboard.write(data);
    delay(100);
    keyboard.write(0xF0);
    delay(100);
    keyboard.write(data);
    delay(100);
}

As You can see above, I put delays between sending data, since PS2 aint that very fast protocol. Hope this will help You.

Sarachiel:
Hi step, got same problem a couple months ago. What I did was something like this :

void make_break_kb(byte data)

{
// makes and breaks the key
    keyboard.write(data);
    delay(100);
    keyboard.write(0xF0);
    delay(100);
    keyboard.write(data);
    delay(100);
}




As You can see above, I put delays between sending data, since PS2 aint that very fast protocol. Hope this will help You.

I never did get this to work, and therefore abandoned the project, but I may give this a shot in the future if I do decide to try again. Thanks! :slight_smile: