confused and could use some fresh/experienced eyes.

What I have:
Arduino Uno R3
IR receiver
IR remote controller

What I'm trying to do:
Use IR remote controller to simulate keyboard presses.

What's my code:

#include <IRremote.h>
#define KEY_LEFT_CTRL  0x01
#define KEY_LEFT_SHIFT  0x02
#define KEY_RIGHT_CTRL  0x10
#define KEY_RIGHT_SHIFT 0x20

uint8_t buf[8] = {
  0
};  /* Keyboard report buffer */

int state = 1;
int RECV_PIN = 2;  //IR receiver connected on pin 2
int commandExecuted = 0;

//Change these values to match data sent by your remote control
/*-----COMMANDS------*/
const long play = 0x800F0416;
const long pause = 0x800F0418;
const long volumeUp = 0x800F8410;
const long volumeDown = 0x800F0411;
const long forward = 0x800F8414;
const long backward = 0x800F0415;
const long mute = 0x800F040E;
/*-----END COMMANDS------*/

IRrecv irrecv(RECV_PIN);  //initialize IR library on RECV_PIN
decode_results results;   //received data will be stored here


void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();  // Start the receiver
  delay(200);
}

void loop() {
  if (irrecv.decode(&results)) {
    switch (results.value) { //fetch received data
      case play:
        buf[0] = KEY_LEFT_CTRL; //Ctrl
        buf[2] = 6; //c
        Serial.write(buf, 8);
        releaseit();
        commandExecuted = 1;
        break;
      case volumeUp:
        buf[0] = KEY_LEFT_CTRL; //Ctrl
        buf[2] = 25; //v
        Serial.write(buf, 8);
        releaseit();
        commandExecuted = 1;
        break;
    }
  }
  if ( commandExecuted == 1) {   //a command was executed
    commandExecuted = 0;        // reset the flag value
  }
}
void releaseit()
{
  buf[0] = 0;
  buf[2] = 0;
  Serial.write(buf, 8); // Release key
  delay(500);
  irrecv.resume(); // Receive the next value
}

I upload the sketch to the arduino, use AMTEL FLIP software to program the 16u2 with the keyboard.hex, unplug arduino, plug it back in, arduino shows as a keyboard so that is fine. But it isn't doing what I want so I know I screwed up the code. Any help will be greatly appreciated!

Please explain exactly what you mean by "it isn't doing what I want".

When I press the button on the IR remote, nothing happens. I think I'm will try and see if i can use the serial monitor when the firmware is programmed with the keyboard.hex

You might be better served with an Arduino Leonardo or Arduino Micro which can natively do USB.

Test each part of your project separately:

  • Write a simple sketch that simulates some keypresses when you connect a pin to ground.
  • Write a simple sketch that turns on the LED when it receives the IR signal of a specific button on the remote control.

That can help to narrow down where the problem is.

johnwasser:
You might be better served with an Arduino Leonardo or Arduino Micro which can natively do USB.

If I had the money I would, plus this is a great learning experience for me, it has been almost 2 years since I've done anything with Arduino and this is only the 2nd project I've worked on getting back into it. Thought this would be easier than using an old portable dvd monitor with the tvout library. Wrong. lol

pert:
Test each part of your project separately:

  • Write a simple sketch that simulates some keypresses when you connect a pin to ground.
  • Write a simple sketch that turns on the LED when it receives the IR signal of a specific button on the remote control.

That can help to narrow down where the problem is.

Great advice, I will do and adapt from that and report back, thank you!

Okay so I had to rethink how to accomplish sending key presses. Using the alternate firmware for the UNO just wasn't working for me. Instead I found a program SerialPort to Keyboard download | SourceForge.net and I am able to use serial.print to send ASCII. Works perfect as long as the application I am using is the current window selected on the PC. Here is the stupid simple code I used to accomplish this.

#include <IRremote.h>
int LEDPin = 13;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;


void setup()
{
  Serial.begin(115200);
  irrecv.enableIRIn(); // Start the receiver
}




void loop()
{
  if (irrecv.decode(&results))
  {
    if (results.value == (0x800F0416))
      Serial.print(" ");
    delay(100);
    irrecv.resume(); //receive the next value
    if (results.value == (0x800F840C))
      Serial.print("");
    delay(100);
    irrecv.resume(); //receive the next value
  }
}

My task for this code is to use my IR Remote to pause/play kodi. "sending the space key".
I want to take it a step further and setup a hotkey on my pc to open kodi.
I am unable to find a way to send "ctrl and alt" key presses via serial.print.
any ideas?

Here's a free open source Windows program that's great for this sort of thing:
http://www.eventghost.net/
It has a Serial plugin that allows you to do communication between the Arduino and EventGhost. You can start applications, switch windows, emulate any keystrokes including combinations, and there is even a Kodi plugin available. It's pretty easy to get started with via the visual programming interface but it's also all based on Python so you can do very complex things also when necessary.